another commit

This commit is contained in:
2026-03-21 14:15:17 +00:00
committed by James Norcutt
parent 1d1a4af630
commit 6314b16e57
4 changed files with 192 additions and 22 deletions
Generated
+97 -1
View File
@@ -17,6 +17,56 @@ version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
[[package]]
name = "anstream"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
[[package]]
name = "anstyle-parse"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
dependencies = [
"anstyle",
"once_cell_polyfill",
"windows-sys",
]
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.102" version = "1.0.102"
@@ -113,6 +163,39 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]]
name = "clap"
version = "4.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b193af5b67834b676abd72466a96c1024e6a6ad978a1f484bd90b85c94041351"
dependencies = [
"clap_builder",
]
[[package]]
name = "clap_builder"
version = "4.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_lex"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9"
[[package]]
name = "colorchoice"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
[[package]] [[package]]
name = "compact_str" name = "compact_str"
version = "0.9.0" version = "0.9.0"
@@ -477,6 +560,12 @@ dependencies = [
"syn 2.0.117", "syn 2.0.117",
] ]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
[[package]] [[package]]
name = "itertools" name = "itertools"
version = "0.14.0" version = "0.14.0"
@@ -517,9 +606,10 @@ dependencies = [
name = "klipper-tui" name = "klipper-tui"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"clap",
"crossterm", "crossterm",
"ratatui", "ratatui",
"ratatui-crossterm", "serde_json",
] ]
[[package]] [[package]]
@@ -704,6 +794,12 @@ version = "1.21.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
[[package]]
name = "once_cell_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]] [[package]]
name = "ordered-float" name = "ordered-float"
version = "4.6.0" version = "4.6.0"
+2 -1
View File
@@ -6,4 +6,5 @@ edition = "2024"
[dependencies] [dependencies]
ratatui = "0.30.0" ratatui = "0.30.0"
crossterm = "0.29.0" crossterm = "0.29.0"
ratatui-crossterm = "0.1.0" clap = "4.6.0"
serde_json = "1.0.149"
+65 -12
View File
@@ -1,19 +1,72 @@
pub enum CurrentScreen { use std::collections::HashMap;
Main,
Editing, pub struct TabsState<'a> {
Exiting, pub titles: Vec<&'a str>,
pub index: usize,
} }
pub enum CurrentlyEditing { impl<'a> TabsState<'a> {
Key, pub const fn new(titles: Vec<&'a str>) -> Self {
Value, Self { titles, index: 0 }
}
pub fn next(&mut self) {
self.index = (self.index + 1) % self.titles.len();
}
pub fn previous(&mut self) {
if self.index > 0 {
self.index -= 1;
} else {
self.index = self.titles.len() - 1;
}
}
} }
pub struct App { pub struct App {
pub key_input: String, // the currently being edited json key. pub title: &'a str,
pub value_input: String, // the currently being edited json value. pub should_quit: bool,
pub pairs: HashMap<String, String>, // The representation of our key and value pairs with serde Serialize support pub tabs: TabsState<'a>,
pub current_screen: CurrentScreen, // the current screen the user is looking at, and will later determine what is rendered. pub servers: Vec<Server<'a>>,
pub currently_editing: Option<CurrentlyEditing>, // the optional state containing which of the key or value pair the user is editing. It is an option, because when the user is not directly editing a key-value pair, this will be set to `None`. pub enhanced_graphics: bool,
} }
impl App {
pub fn new(title: &'a str, servers: Vec<Server<'a>>, enhanced_graphics: bool) -> Self {
App {
title,
should_quit: false,
tabs: TabsState::new(vec!["Dashboard","Machine info","Config"]),
servers,
enhanced_graphics,
}
}
pub fn on_up(&mut self) {
}
pub fn on_down(&mut self) {
}
pub fn on_right(&mut self) {
}
pub fn on_left(&mut self) {
}
pub fn on_key(&mut self, c: char) {
match c {
'q' => {
self.should_quit = true;
}
_ => {}
}
}
pub fn on_tick(&mut self) {
}
}
+28 -8
View File
@@ -1,10 +1,30 @@
use ratatui::backend::CrosstermBackend; use std::io;
use ratatui::Terminal; use std::error::Error;
use std::io::{stdout, Write}; use std::time::Duration;
use clap::Parser;
mod app;
mod ui;
mod crossterm;
use crate::{
app::App,
ui::ui,
fn main() { };
let backend = CrosstermBackend::new(stdout());
let mut terminal = Terminal::new(backend).unwrap(); #[derive(Debug, Parser)]
//todo: setup moonraker interface struct Cli {
//todo: setup custom klipper ui /// time in ms between two ticks.
#[arg(short, long, default_value_t = 200)]
tick_rate: u64,
/// whether unicode symbols are used to improve the overall look of the app
#[arg(short, long, default_value_t = true)]
unicode: bool,
}
fn main() -> Result<(), Box<dyn Error>> {
let cli = Cli::Parse();
let tick_rate = Duration::from_millis(cli.tick_rate);
crate::crossterm::run(tick_rate, cli.unicode)?;
Ok(())
} }