Adds commands module

This commit is contained in:
Gregor Reitzenstein 2020-11-03 13:41:54 +01:00
parent 02c310aa67
commit 0a68ea405c
3 changed files with 16 additions and 6 deletions

View File

@ -58,14 +58,21 @@ impl<'a, S: Unpin> Sute<'a, S> {
} }
} }
fn run_cmd(&mut self, cmd: String) { fn run_cmd(&mut self, cmdline: String) {
if cmd == "quit" { let mut words = cmdline.split_ascii_whitespace();
self.state.running = false; match words.next() {
} else { Some("quit") => self.state.running = false,
info!(self.log, "Issues unknown cmd: {}", cmd); Some("connect") => {
self.connect(cmdline)
},
cmd => info!(self.log, "Issues unknown cmd: {:?}", cmd),
} }
} }
fn connect(&mut self, params: String) {
info!(self.log, "Called connect with {}", params);
}
fn handle_resize(&mut self, new_size: (u16,u16)) { fn handle_resize(&mut self, new_size: (u16,u16)) {
self.state.size = new_size; self.state.size = new_size;
} }

View File

@ -26,6 +26,7 @@ mod input;
mod util; mod util;
mod ui; mod ui;
mod schema; mod schema;
mod commands;
use banner::BANNER; use banner::BANNER;
@ -71,6 +72,7 @@ fn main() -> Result<(), io::Error> {
let app = app::Sute::new(resize, log.clone(), drain, api); let app = app::Sute::new(resize, log.clone(), drain, api);
let mut state = app.get_state();
let mut stream = app.to_stream(); let mut stream = app.to_stream();
let ui_future = async move { let ui_future = async move {
@ -86,6 +88,7 @@ fn main() -> Result<(), io::Error> {
terminal.resize(tui::layout::Rect::new(0, 0, x,y)).unwrap(); terminal.resize(tui::layout::Rect::new(0, 0, x,y)).unwrap();
} }
terminal.draw(|f| ui::draw_ui(f, &mut state));
loop { loop {
if let Some(mut state) = stream.next().await { if let Some(mut state) = stream.next().await {
if !state.running { if !state.running {

View File

@ -26,7 +26,7 @@ pub fn draw_ui<B: Backend>(f: &mut Frame<B>, app: &mut SuteState) {
fn draw_header<B: Backend>(f: &mut Frame<B>, app: &mut SuteState, layout_chunk: Rect) { fn draw_header<B: Backend>(f: &mut Frame<B>, app: &mut SuteState, layout_chunk: Rect) {
f.render_widget(Block::default() f.render_widget(Block::default()
.title("Header") .title("Status")
.borders(Borders::ALL), layout_chunk); .borders(Borders::ALL), layout_chunk);
} }