ghassmo 4 lat temu
rodzic
commit
61ff3ebb3f
4 zmienionych plików z 14 dodań i 35 usunięć
  1. 4 3
      src/bin/tui_ex.rs
  2. 4 8
      src/tui/app.rs
  3. 2 3
      src/tui/mod.rs
  4. 4 21
      src/tui/widget.rs

+ 4 - 3
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())?];

+ 4 - 8
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
                 }
             }
         }

+ 2 - 3
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};

+ 4 - 21
src/tui/widget.rs

@@ -15,13 +15,7 @@ pub struct Widget {
 
 impl Widget {
     pub fn new(title: String) -> Result<Widget> {
-        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<Stdout>) -> 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;