diff --git a/src/bin/tui_ex.rs b/src/bin/tui_ex.rs index 8f0d5ffbc..40bc0e584 100644 --- a/src/bin/tui_ex.rs +++ b/src/bin/tui_ex.rs @@ -1,6 +1,7 @@ - -use drk::tui::{App, HBox, VBox, Widget}; -use drk::Result; +use drk::{ + tui::{App, HBox, VBox, Widget}, + Result, +}; async fn start() -> Result<()> { let wv1 = vec![Widget::new("V1".into())?]; diff --git a/src/tui/app.rs b/src/tui/app.rs index cfedb6853..7c4181e27 100644 --- a/src/tui/app.rs +++ b/src/tui/app.rs @@ -8,8 +8,8 @@ use termion::{ raw::{IntoRawMode, RawTerminal}, }; -use crate::Result; use super::Layout; +use crate::Result; #[allow(dead_code)] pub struct App { @@ -25,11 +25,7 @@ impl App { let stdout = std::io::stdout(); let stdout = stdout.into_raw_mode()?; - Ok(Self { - stdin, - stdout, - layouts: vec![], - }) + Ok(Self { stdin, stdout, layouts: vec![] }) } fn clear(&mut self) -> Result<()> { @@ -93,7 +89,7 @@ impl App { if terminal_width > box_x { terminal_width -= box_x; } else { - break; + break } } @@ -102,7 +98,7 @@ impl App { if terminal_height > box_y { terminal_height -= box_y; } else { - break; + break } } } diff --git a/src/tui/mod.rs b/src/tui/mod.rs index 780f74464..7c7dd295e 100644 --- a/src/tui/mod.rs +++ b/src/tui/mod.rs @@ -1,6 +1,5 @@ -pub mod widget; pub mod app; +pub mod widget; -pub use widget::{HBox, VBox, Widget, Layout}; pub use app::App; - +pub use widget::{HBox, Layout, VBox, Widget}; diff --git a/src/tui/widget.rs b/src/tui/widget.rs index e22e7ede8..7fba53153 100644 --- a/src/tui/widget.rs +++ b/src/tui/widget.rs @@ -15,13 +15,7 @@ pub struct Widget { impl Widget { pub fn new(title: String) -> Result { - Ok(Widget { - width: 0, - height: 0, - x: 0, - y: 0, - title, - }) + Ok(Widget { width: 0, height: 0, x: 0, y: 0, title }) } pub fn print( @@ -31,12 +25,7 @@ impl Widget { y: usize, text: &str, ) -> Result<()> { - write!( - stdout, - "{}{}", - cursor::Goto(1 + x as u16, 1 + y as u16), - text - )?; + write!(stdout, "{}{}", cursor::Goto(1 + x as u16, 1 + y as u16), text)?; Ok(()) } @@ -82,12 +71,7 @@ impl Widget { pub fn draw(&self, stdout: &mut RawTerminal) -> Result<()> { self.print_border(stdout)?; - self.print( - stdout, - self.x + 3, - self.y, - &format!(" {} ", &self.title.clone()), - )?; + self.print(stdout, self.x + 3, self.y, &format!(" {} ", &self.title.clone()))?; Ok(()) } } @@ -159,13 +143,12 @@ impl Layout for HBox { layout_width: usize, layout_height: usize, ) -> Result<(usize, usize)> { - let len = self.widgets.len(); let widget_height = layout_height / self.height; for (i, widget) in self.widgets.iter_mut().enumerate() { - widget.width = layout_width / len - 1; + widget.width = layout_width / len - 1; widget.height = widget_height - 1; widget.x = (widget.width + 1) * i + x; widget.y = y;