From 4ff5d0adbe35c9eabc8f79cac36e136c27f519ce Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Sat, 23 Nov 2024 21:53:13 -0500 Subject: [PATCH] chore: cargo fmt --- src/book/mod.rs | 8 +++++--- src/book/test.rs | 22 ++++++++++++++++------ src/main.rs | 2 +- src/ui/cmd.rs | 24 +++++++++++++++++++----- src/ui/render.rs | 8 +++++--- 5 files changed, 46 insertions(+), 18 deletions(-) diff --git a/src/book/mod.rs b/src/book/mod.rs index 37d9f70..f532252 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -177,11 +177,13 @@ impl Book { Ok((self .get_sheet()? .get_column_width(idx as i32) - .map_err(|e| anyhow!("Error getting column width: {:?}", e))? / COL_PIXELS) as usize) + .map_err(|e| anyhow!("Error getting column width: {:?}", e))? + / COL_PIXELS) as usize) } pub fn set_col_size(&mut self, idx: usize, cols: usize) -> Result<()> { - self.get_sheet_mut()?.set_column_width(idx as i32, cols as f64 * COL_PIXELS) + self.get_sheet_mut()? + .set_column_width(idx as i32, cols as f64 * COL_PIXELS) .map_err(|e| anyhow!("Error setting column width: {:?}", e))?; Ok(()) } @@ -243,7 +245,7 @@ impl Book { .worksheet(self.current_sheet) .map_err(|s| anyhow!("Invalid Worksheet: {}", s))?) } - + pub(crate) fn get_sheet_mut(&mut self) -> Result<&mut Worksheet> { Ok(self .model diff --git a/src/book/test.rs b/src/book/test.rs index 2f93449..510e1b6 100644 --- a/src/book/test.rs +++ b/src/book/test.rs @@ -69,12 +69,17 @@ fn test_book_insert_rows() { let mut book = Book::default(); book.update_entry(&Address { row: 2, col: 2 }, "1") .expect("failed to edit cell"); - book.move_to(&Address { row: 2, col: 2 }).expect("Failed to move to location"); + book.move_to(&Address { row: 2, col: 2 }) + .expect("Failed to move to location"); assert_eq!((2, 2), book.get_size().expect("Failed to get size")); book.insert_rows(1, 5).expect("Failed to insert rows"); assert_eq!((7, 2), book.get_size().expect("Failed to get size")); - assert_eq!(Address {row: 7, col: 2, }, book.location); - assert_eq!("1", book.get_current_cell_rendered().expect("Failed to get rendered content")); + assert_eq!(Address { row: 7, col: 2 }, book.location); + assert_eq!( + "1", + book.get_current_cell_rendered() + .expect("Failed to get rendered content") + ); } #[test] @@ -82,12 +87,17 @@ fn test_book_insert_columns() { let mut book = Book::default(); book.update_entry(&Address { row: 2, col: 2 }, "1") .expect("failed to edit cell"); - book.move_to(&Address { row: 2, col: 2 }).expect("Failed to move to location"); + book.move_to(&Address { row: 2, col: 2 }) + .expect("Failed to move to location"); assert_eq!((2, 2), book.get_size().expect("Failed to get size")); book.insert_columns(1, 5).expect("Failed to insert rows"); assert_eq!((2, 7), book.get_size().expect("Failed to get size")); - assert_eq!(Address {row: 2, col: 7, }, book.location); - assert_eq!("1", book.get_current_cell_rendered().expect("Failed to get rendered content")); + assert_eq!(Address { row: 2, col: 7 }, book.location); + assert_eq!( + "1", + book.get_current_cell_rendered() + .expect("Failed to get rendered content") + ); } #[test] diff --git a/src/main.rs b/src/main.rs index 1794bc7..200e3c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,8 +5,8 @@ use crossterm::event; use ratatui; use ui::Workspace; -mod ui; mod book; +mod ui; #[derive(Parser, Debug)] #[command(version, about, long_about = None)] diff --git a/src/ui/cmd.rs b/src/ui/cmd.rs index 1689815..1700ebc 100644 --- a/src/ui/cmd.rs +++ b/src/ui/cmd.rs @@ -78,7 +78,11 @@ fn try_consume_write<'cmd, 'i: 'cmd>( return Err("Invalid command: Did you mean to type `write `?"); } let arg = input.span(0..).trim(); - return Ok(Some(Cmd::Write(if arg.is_empty() { None } else { Some(arg) }))); + return Ok(Some(Cmd::Write(if arg.is_empty() { + None + } else { + Some(arg) + }))); } fn try_consume_insert_row<'cmd, 'i: 'cmd>( @@ -137,7 +141,9 @@ fn try_consume_insert_column<'cmd, 'i: 'cmd>( }))); } -fn try_consume_edit<'cmd, 'i: 'cmd>(mut input: StrCursor<'i>) -> Result>, &'static str> { +fn try_consume_edit<'cmd, 'i: 'cmd>( + mut input: StrCursor<'i>, +) -> Result>, &'static str> { const SHORT: &'static str = "e"; const LONG: &'static str = "edit"; @@ -159,7 +165,9 @@ fn try_consume_edit<'cmd, 'i: 'cmd>(mut input: StrCursor<'i>) -> Result(mut input: StrCursor<'i>) -> Result>, &'static str> { +fn try_consume_help<'cmd, 'i: 'cmd>( + mut input: StrCursor<'i>, +) -> Result>, &'static str> { const SHORT: &'static str = "?"; const LONG: &'static str = "help"; @@ -175,10 +183,16 @@ fn try_consume_help<'cmd, 'i: 'cmd>(mut input: StrCursor<'i>) -> Result`?"); } let arg = input.span(0..).trim(); - return Ok(Some(Cmd::Help(if arg.is_empty() { None } else { Some(arg) }))); + return Ok(Some(Cmd::Help(if arg.is_empty() { + None + } else { + Some(arg) + }))); } -fn try_consume_quit<'cmd, 'i: 'cmd>(mut input: StrCursor<'i>) -> Result>, &'static str> { +fn try_consume_quit<'cmd, 'i: 'cmd>( + mut input: StrCursor<'i>, +) -> Result>, &'static str> { const SHORT: &'static str = "q"; const LONG: &'static str = "quit"; diff --git a/src/ui/render.rs b/src/ui/render.rs index 658563b..34cbdd2 100644 --- a/src/ui/render.rs +++ b/src/ui/render.rs @@ -41,7 +41,7 @@ impl<'widget, 'ws: 'widget> Widget for &'widget mut Workspace<'ws> { } outer_block.render(area, buf); - + if self.state.modality() == &Modality::Dialog { let lines = Text::from_iter(self.state.popup.iter().cloned()); let popup = Popup::new(lines); @@ -66,7 +66,9 @@ impl<'t, 'book: 't> TryFrom<&'book Book> for Table<'t> { let mut cells = vec![Cell::new(Text::from(ri.to_string()))]; cells.extend((1..=col_count).into_iter().map(|ci| { // TODO(zaphar): Is this safe? - let content = value.get_cell_addr_rendered(&Address{ row: ri, col: ci }).unwrap(); + let content = value + .get_cell_addr_rendered(&Address { row: ri, col: ci }) + .unwrap(); let cell = Cell::new(Text::raw(content)); match (value.location.row == ri, value.location.col == ci) { (true, true) => cell.fg(Color::White).underlined(), @@ -90,7 +92,7 @@ impl<'t, 'book: 't> TryFrom<&'book Book> for Table<'t> { let mut constraints: Vec = Vec::new(); constraints.push(Constraint::Max(5)); for col_idx in 0..col_count { - let size = value.get_col_size(col_idx+1)?; + let size = value.get_col_size(col_idx + 1)?; constraints.push(Constraint::Length(size as u16)); } let mut header = Vec::with_capacity(col_count as usize);