From 21d93f7073077dee994b22ad57ebcdbf9d496f24 Mon Sep 17 00:00:00 2001 From: Isaac Mills Date: Fri, 18 Jul 2025 16:42:04 -0600 Subject: [PATCH] Initial cockpit commit --- .gitmodules | 4 ++ src/components/head.html | 1 + src/components/tab/content.html | 3 +- src/page_five.html | 3 ++ src/page_four.html | 3 -- .../{page_four.html => page_five.html} | 6 +-- src/partials/thecockpit.html | 18 +++++++ src/style.css | 10 ++++ src/thecockpit.html | 3 ++ src/thecockpit.js | 5 ++ thecockpit/Cargo.toml | 15 +++++- thecockpit/ratzilla | 1 + thecockpit/src/app.rs | 50 +++++++++++++++++++ thecockpit/src/lib.rs | 16 ++---- thecockpit/src/main.rs | 25 ++++++++++ thecockpit/src/web/mod.rs | 36 +++++++++++++ thecockpit/src/{ => web}/utils.rs | 0 17 files changed, 177 insertions(+), 22 deletions(-) create mode 100644 .gitmodules create mode 100644 src/page_five.html delete mode 100644 src/page_four.html rename src/partials/{page_four.html => page_five.html} (88%) create mode 100644 src/partials/thecockpit.html create mode 100644 src/thecockpit.html create mode 100644 src/thecockpit.js create mode 160000 thecockpit/ratzilla create mode 100644 thecockpit/src/app.rs create mode 100644 thecockpit/src/main.rs create mode 100644 thecockpit/src/web/mod.rs rename thecockpit/src/{ => web}/utils.rs (100%) diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..5308c86 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "thecockpit/ratzilla"] + path = thecockpit/ratzilla + url = https://github.com/StratusFearMe21/ratzilla + branch = resize_canvas diff --git a/src/components/head.html b/src/components/head.html index 3c3df46..8c1b64d 100644 --- a/src/components/head.html +++ b/src/components/head.html @@ -13,6 +13,7 @@ + diff --git a/src/components/tab/content.html b/src/components/tab/content.html index 7b02aa0..57a3bd4 100644 --- a/src/components/tab/content.html +++ b/src/components/tab/content.html @@ -7,7 +7,8 @@ Our Projects Who we are Our Interests - Page Four + The Cockpit + Page Five
diff --git a/src/page_five.html b/src/page_five.html new file mode 100644 index 0000000..9e2e5d7 --- /dev/null +++ b/src/page_five.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/page_four.html b/src/page_four.html deleted file mode 100644 index 1830e92..0000000 --- a/src/page_four.html +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/src/partials/page_four.html b/src/partials/page_five.html similarity index 88% rename from src/partials/page_four.html rename to src/partials/page_five.html index 279530a..16f346a 100644 --- a/src/partials/page_four.html +++ b/src/partials/page_five.html @@ -1,5 +1,5 @@ - - + + Who is this guy? @@ -20,7 +20,7 @@ ```=html

diff --git a/src/partials/thecockpit.html b/src/partials/thecockpit.html new file mode 100644 index 0000000..c4d62c3 --- /dev/null +++ b/src/partials/thecockpit.html @@ -0,0 +1,18 @@ + + + + ## Fact: + + In Myrtle Beach South Carolina, Richard and Isaac counted 100 Chrysler Pacificas in the span of a week. + + +
+
+ \ No newline at end of file diff --git a/src/style.css b/src/style.css index 1f73bb4..51c40a9 100644 --- a/src/style.css +++ b/src/style.css @@ -26,6 +26,16 @@ html { justify-content: space-between; + + section { + padding: 32px; + text-align: center; + + p { + text-align: center; + } + } + h1 { font-size: 48pt; } diff --git a/src/thecockpit.html b/src/thecockpit.html new file mode 100644 index 0000000..2206886 --- /dev/null +++ b/src/thecockpit.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/thecockpit.js b/src/thecockpit.js new file mode 100644 index 0000000..848b234 --- /dev/null +++ b/src/thecockpit.js @@ -0,0 +1,5 @@ +import { default as init, run } from 'thecockpit' +window.run_cockpit = async () => { + await init(); + run("cockpit-canvas"); +}; diff --git a/thecockpit/Cargo.toml b/thecockpit/Cargo.toml index fd11a89..063e04f 100644 --- a/thecockpit/Cargo.toml +++ b/thecockpit/Cargo.toml @@ -9,8 +9,17 @@ crate-type = ["cdylib", "rlib"] [features] default = ["console_error_panic_hook"] +console_error_panic_hook = ["dep:console_error_panic_hook"] -[dependencies] +[[bin]] +name = "thecockpit" +path = "src/main.rs" +required-features = ["ratatui/default"] + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +ratatui = { version = "0.29.0", default-features = false } + +[target.'cfg(target_arch = "wasm32")'.dependencies] wasm-bindgen = "0.2.84" # The `console_error_panic_hook` crate provides better debugging of panics by @@ -18,10 +27,12 @@ wasm-bindgen = "0.2.84" # all the `std::fmt` and `std::panicking` infrastructure, so isn't great for # code size when deploying. console_error_panic_hook = { version = "0.1.7", optional = true } +ratzilla = { path = "./ratzilla" } -[dev-dependencies] +[target.'cfg(target_arch = "wasm32")'.dev-dependencies] wasm-bindgen-test = "0.3.34" [profile.release] # Tell `rustc` to optimize for small code size. opt-level = "s" + diff --git a/thecockpit/ratzilla b/thecockpit/ratzilla new file mode 160000 index 0000000..3bcbd53 --- /dev/null +++ b/thecockpit/ratzilla @@ -0,0 +1 @@ +Subproject commit 3bcbd53bb0a57080740e3a71ef44b7ceb9b74403 diff --git a/thecockpit/src/app.rs b/thecockpit/src/app.rs new file mode 100644 index 0000000..896bfa4 --- /dev/null +++ b/thecockpit/src/app.rs @@ -0,0 +1,50 @@ +#[cfg(target_arch = "wasm32")] +use ratzilla::ratatui; + +use ratatui::{ + style::{Color, Stylize}, + widgets::{Block, Borders, Paragraph}, + Frame, +}; + +#[derive(Default)] +pub struct App {} + +const SPLASH: &str = r#" +!~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +!~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +!!~~~~~~!J5PPPPPPPPPPP?^^^^7PPPPPPPPPPPPPPPPY~^^^^ +!!!!!!~~~!JB&@@@@@@@@@5^^^^Y@@@@@@@@@@@@@@@@#~^^^^ +!!!!!5?!~~~!JG&@@@@@@@5^^^^Y@@@@@@@@@@@@@@@@#~^^^^ +!!!!7#&GJ!~~~!?G&@@@@@5^^^^Y@@@@@@@@@@@@@@@@#~^^^^ +7!!!7#@@&BJ!~~~!?G&@@@5^^^^Y@@@@@@@@@@@@@@@@#~^^^^ +7!!!7#@@@@@BY!~~~~?P&@5~^^^Y@@@@@@@@@@@@@@@@#~^^^^ +777!7#@@@@@@@BY!~~~~7PY~~~^Y@@@@@@@@@@@@@@@@#~^^^^ +7777?#@@@@@@@@@#Y7~~~~!~~~~Y@@@@@@@@@@@@@@@@#~^^^^ +7777?#@@@@@@@@@@@#57~~~~~~~Y@@@@@@@@@@@@@@@@#~^^^^ +?777?#@@@@@@@@@@@@@#57~~~~~?#@@@@@@@@@@@@@@@#~^^^^ +?777?#@@@@@@@@@@@@@@@#J~~~~~!Y#@@@@@@@@@@@@@#~^^^^ +???7?#@@@@@@@@@@@@@@@@P!!~~~~~!YB@@@@@@@@@@@#~^^^^ +?????#@@@@@@@@@@@@@@@@P!!!!!!~~~!YB@@@@@@@@@#~^^^^ +????J&@@@@@@@@@@@@@@@@P!!!!YG?!~~~!JB&@@@@@@#~^^^^ +????J&@@@@@@@@@@@@@@@@P!!!!5@&G?!~~~!JG&@@@@#~^^^^ +J???J&@@@@@@@@@@@@@@@@P!!!!5@@@&GJ!~~~!?G&@@#!^^^^ +J???J&@@@@@@@@@@@@@@@@P7!!!5@@@@@&BJ!~~~!?G&#!^^^~ +JJJ?J&@@@@@@@@@@@@@@@@P777!5@@@@@@@@BY!~~~~?5!~~^~ +JJJJJ&@@@@@@@@@@@@@@@@P77775@@@@@@@@@@BY!~~~~~~~~~ +JJJJJGBBGGGGGGGGGGGGGGY7777JGGGGGGGPPPPPY!~~~~~~~~ +YJJJJJJJJJ????????????77777777777!!!!!!!!!!!~~~~~~ +YJJJJJJJJJJJ???????????77777777777!!!!!!!!!!!~~~~~ +"#; + +impl App { + pub fn draw(&mut self, frame: &mut Frame) { + frame.render_widget( + Paragraph::new(SPLASH) + .alignment(ratatui::layout::Alignment::Center) + .fg(Color::Rgb(226, 190, 89)) + .block(Block::new().borders(Borders::all()).title("Coming soon")), + frame.area(), + ); + } +} diff --git a/thecockpit/src/lib.rs b/thecockpit/src/lib.rs index b7a1960..34bf12f 100644 --- a/thecockpit/src/lib.rs +++ b/thecockpit/src/lib.rs @@ -1,13 +1,3 @@ -mod utils; - -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -extern "C" { - fn alert(s: &str); -} - -#[wasm_bindgen] -pub fn greet() { - alert("Hello, thecockpit!"); -} +pub mod app; +#[cfg(target_arch = "wasm32")] +mod web; diff --git a/thecockpit/src/main.rs b/thecockpit/src/main.rs new file mode 100644 index 0000000..6ad32b7 --- /dev/null +++ b/thecockpit/src/main.rs @@ -0,0 +1,25 @@ +use std::time::Duration; + +use ratatui::crossterm::event; +use thecockpit::app::App; + +fn main() { + let mut terminal = ratatui::init(); + let mut app = App::default(); + + loop { + terminal.draw(|frame| app.draw(frame)); + + if event::poll(Duration::from_secs(0)).unwrap() { + match event::read().unwrap() { + event::Event::Key(event::KeyEvent { + code: event::KeyCode::Char('q'), + .. + }) => break, + _ => {} + } + } + } + + ratatui::restore(); +} diff --git a/thecockpit/src/web/mod.rs b/thecockpit/src/web/mod.rs new file mode 100644 index 0000000..1f0456c --- /dev/null +++ b/thecockpit/src/web/mod.rs @@ -0,0 +1,36 @@ +use std::{cell::RefCell, rc::Rc}; + +use ratzilla::{ + backend::canvas::CanvasBackendOptions, + ratatui::{ + widgets::{Block, Borders}, + Terminal, + }, + web_sys, CanvasBackend, WebRenderer, +}; +use wasm_bindgen::prelude::*; + +mod utils; + +use crate::app::App; + +#[wasm_bindgen] +extern "C" { + fn alert(s: &str); +} + +#[wasm_bindgen] +pub fn run(grid_id: &str) { + console_error_panic_hook::set_once(); + + let backend = + CanvasBackend::new_with_options(CanvasBackendOptions::new().grid_id(grid_id)).unwrap(); + let terminal = Terminal::new(backend).unwrap(); + + let app = Rc::new(RefCell::new(App::default())); + + terminal.draw_web({ + let app = Rc::clone(&app); + move |frame| app.borrow_mut().draw(frame) + }) +} diff --git a/thecockpit/src/utils.rs b/thecockpit/src/web/utils.rs similarity index 100% rename from thecockpit/src/utils.rs rename to thecockpit/src/web/utils.rs