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
+65 -12
View File
@@ -1,19 +1,72 @@
pub enum CurrentScreen {
Main,
Editing,
Exiting,
use std::collections::HashMap;
pub struct TabsState<'a> {
pub titles: Vec<&'a str>,
pub index: usize,
}
pub enum CurrentlyEditing {
Key,
Value,
impl<'a> TabsState<'a> {
pub const fn new(titles: Vec<&'a str>) -> Self {
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 key_input: String, // the currently being edited json key.
pub value_input: String, // the currently being edited json value.
pub pairs: HashMap<String, String>, // The representation of our key and value pairs with serde Serialize support
pub current_screen: CurrentScreen, // the current screen the user is looking at, and will later determine what is rendered.
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 title: &'a str,
pub should_quit: bool,
pub tabs: TabsState<'a>,
pub servers: Vec<Server<'a>>,
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 ratatui::Terminal;
use std::io::{stdout, Write};
use std::io;
use std::error::Error;
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();
//todo: setup moonraker interface
//todo: setup custom klipper ui
};
#[derive(Debug, Parser)]
struct Cli {
/// 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(())
}