getting there

This commit is contained in:
2026-03-21 17:25:09 +00:00
committed by James Norcutt
parent 6314b16e57
commit 8e32cc7277
5 changed files with 53 additions and 8 deletions
Generated
+13
View File
@@ -170,6 +170,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b193af5b67834b676abd72466a96c1024e6a6ad978a1f484bd90b85c94041351"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
@@ -184,6 +185,18 @@ dependencies = [
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1110bd8a634a1ab8cb04345d8d878267d57c3cf1b38d91b71af6686408bbca6a"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.117",
]
[[package]]
name = "clap_lex"
version = "1.1.0"
+1 -1
View File
@@ -6,5 +6,5 @@ edition = "2024"
[dependencies]
ratatui = "0.30.0"
crossterm = "0.29.0"
clap = "4.6.0"
clap = { version = "4.6.0", features = ["derive"] }
serde_json = "1.0.149"
+31 -3
View File
@@ -1,4 +1,3 @@
use std::collections::HashMap;
pub struct TabsState<'a> {
pub titles: Vec<&'a str>,
@@ -21,8 +20,37 @@ impl<'a> TabsState<'a> {
}
}
}
pub struct Servers<'a> {
pub servers: Vec<Server<'a>>,
pub index: usize,
}
pub struct App {
impl<'a> Servers<'a> {
pub const fn new( servers: Vec<Server<'a>>) -> Self {
Self { servers, index: 0 }
}
pub fn next(&mut self) {
self.index = (self.index + 1) % self.servers.len();
}
pub fn previous(&mut self) {
if self.index > 0 {
self.index -= 1;
} else {
self.index = self.servers.len() - 1;
}
}
}
pub struct Server<'a> {
pub name: &'a str,
pub location: &'a str,
pub ip: &'a str,
pub connected: bool,
}
pub struct App<'a> {
pub title: &'a str,
pub should_quit: bool,
pub tabs: TabsState<'a>,
@@ -30,7 +58,7 @@ pub struct App {
pub enhanced_graphics: bool,
}
impl App {
impl<'a> App<'a> {
pub fn new(title: &'a str, servers: Vec<Server<'a>>, enhanced_graphics: bool) -> Self {
App {
title,
+6 -2
View File
@@ -10,7 +10,7 @@ use crossterm::terminal::{
use ratatui::backend::{Backend, CrosstermBackend};
use ratatui::Terminal;
use crate::app::App;
use crate::app::{App, Server};
use crate::ui;
pub fn run(tick_rate: Duration, enhanced_graphics: bool) -> Result<(), Box<dyn Error>> {
@@ -22,7 +22,7 @@ pub fn run(tick_rate: Duration, enhanced_graphics: bool) -> Result<(), Box<dyn E
let mut terminal = Terminal::new(backend)?;
// create app and run it
let app = App::new("Klipper-Tui", enhanced_graphics);
let app = App::new("Klipper-Tui", get_servers(), enhanced_graphics);
let app_result = run_app(&mut terminal, app, tick_rate);
// restore terminal
@@ -74,3 +74,7 @@ where
}
}
}
pub fn get_servers<'a>() -> Vec<Server<'a>> {
//todo: add printer ip addrs
}
+2 -2
View File
@@ -11,7 +11,7 @@ use crate::{
};
#[derive(Debug, Parser)]
#[derive(Parser)]
struct Cli {
/// time in ms between two ticks.
#[arg(short, long, default_value_t = 200)]
@@ -23,7 +23,7 @@ struct Cli {
}
fn main() -> Result<(), Box<dyn Error>> {
let cli = Cli::Parse();
let cli = Cli::parse();
let tick_rate = Duration::from_millis(cli.tick_rate);
crate::crossterm::run(tick_rate, cli.unicode)?;
Ok(())