Compare commits

..

3 Commits

Author SHA1 Message Date
James Norcutt 9afe1118db added json support 2026-03-28 07:30:25 +00:00
narf_poit 4b09a0fefb done this weekend 2026-03-22 19:18:27 +00:00
narf_poit 16ba6d8ad5 ui coming along 2026-03-22 12:55:37 +00:00
6 changed files with 65 additions and 10 deletions
Generated
+2
View File
@@ -619,9 +619,11 @@ dependencies = [
name = "klipper-tui"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"crossterm",
"ratatui",
"serde",
"serde_json",
]
+2
View File
@@ -8,3 +8,5 @@ ratatui = "0.30.0"
crossterm = "0.29.0"
clap = { version = "4.6.0", features = ["derive"] }
serde_json = "1.0.149"
anyhow = "1.0.102"
serde = { version = "1.0.228", features = ["derive"] }
+7 -1
View File
@@ -55,6 +55,7 @@ pub struct App<'a> {
pub should_quit: bool,
pub tabs: TabsState<'a>,
pub servers: Vec<Server<'a>>,
pub tabkeystext: Vec<&'a str>,
pub enhanced_graphics: bool,
}
@@ -65,6 +66,7 @@ impl<'a> App<'a> {
should_quit: false,
tabs: TabsState::new(vec!["Dashboard","Machine info","Config"]),
servers,
tabkeystext: vec!["(H)otend (B)ed P(r)eset (P)rint (C)ancel (Q)uit","(Q)uit","(Q)uit"],
enhanced_graphics,
}
}
@@ -78,11 +80,15 @@ impl<'a> App<'a> {
}
pub fn on_right(&mut self) {
self.tabs.next();
}
pub fn on_left(&mut self) {
self.tabs.previous();
}
pub fn on_tab(&mut self) {
self.tabs.next();
}
pub fn on_key(&mut self, c: char) {
+1
View File
@@ -64,6 +64,7 @@ where
KeyCode::Char('j') | KeyCode::Down => app.on_down(),
KeyCode::Char('k') | KeyCode::Up => app.on_up(),
KeyCode::Char('l') | KeyCode::Right => app.on_right(),
KeyCode::Tab => app.on_tab(),
KeyCode::Char(c) => app.on_key(c),
_ => {}
}
-1
View File
@@ -7,7 +7,6 @@ mod ui;
mod crossterm;
use crate::{
app::App,
ui::ui,
};
+53 -8
View File
@@ -1,18 +1,63 @@
use crossterm::style;
use ratatui::{
layout::{Constraint, Direction, Layout, Rect},
style::{Color, Style},
text::{Line, Span, Text},
widgets::{Block, Borders, Clear, List, ListItem, Paragraph, Wrap},
style::{Color, Style, Modifier},
text::{self, Line, Span, Text},
widgets::{
Block, Borders, Clear, List, ListItem,Tabs, Paragraph, Wrap,
canvas::{self, Canvas, Circle, Map, MapResolution, Rectangle},
},
symbols,
Frame,
};
use crate::app::App;
// ANCHOR: method_sig
pub fn ui(frame: &mut Frame, app: &App) {
}
pub fn render(frame: &mut Frame, app: &mut App) {
let chunks = Layout::vertical([Constraint::Length(3), Constraint::Min(1), Constraint::Length(3)]).split(frame.area());
let tabs = app.tabs
.titles
.iter()
.map(|t| text::Line::from(Span::styled(*t, Style::default().fg(Color::Green))))
.collect::<Tabs>()
.block(Block::bordered().title(app.title))
.highlight_style(Style::default().fg(Color::Yellow))
.select(app.tabs.index);
frame.render_widget(tabs, chunks[0]);
match app.tabs.index {
0 => draw_dashboard_tab(frame, app, chunks[1]),
1 => draw_machine_tab(frame, app, chunks[1]),
2 => draw_conf_tab(frame, app, chunks[1]),
_ => {}
};
draw_statusbar(frame, app, chunks[2]);
}
pub fn draw_dashboard_tab(frame: &mut Frame, app: &mut App, area: Rect) {
let chunks = Layout::vertical([Constraint::Percentage(50), Constraint::Percentage(50)]).split(area);
{
let chunks = Layout::horizontal([Constraint::Percentage(30), Constraint::Percentage(40), Constraint::Percentage(30)]).split(chunks[0]);
}
}
pub fn draw_machine_tab(frame: &mut Frame, app: &mut App, area: Rect) {
}
pub fn draw_conf_tab(frame: &mut Frame, app: &mut App, area: Rect) {
}
pub fn draw_statusbar(frame: &mut Frame, app: &mut App, area: Rect) {
let chunks = Layout::horizontal([Constraint::Length(25), Constraint::Min(0)]).split(area);
let status = Block::bordered().title(Span::styled("Status", Style::default().fg(Color::Cyan).add_modifier(Modifier::BOLD),));
let statustext = Paragraph::new("Todo...").block(status);
frame.render_widget(statustext, chunks[0]);
let keysblock = Block::bordered();
let keystext = Paragraph::new(app.tabkeystext[app.tabs.index]).block(keysblock);
frame.render_widget(keystext, chunks[1]);
}