getting there
This commit is contained in:
+31
-3
@@ -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
@@ -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
@@ -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(())
|
||||
|
||||
Reference in New Issue
Block a user