chore: cargo fmt

This commit is contained in:
Jeremy Wall 2024-11-23 21:53:13 -05:00
parent 01c2180c20
commit 4ff5d0adbe
5 changed files with 46 additions and 18 deletions

View File

@ -177,11 +177,13 @@ impl Book {
Ok((self Ok((self
.get_sheet()? .get_sheet()?
.get_column_width(idx as i32) .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<()> { 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))?; .map_err(|e| anyhow!("Error setting column width: {:?}", e))?;
Ok(()) Ok(())
} }
@ -243,7 +245,7 @@ impl Book {
.worksheet(self.current_sheet) .worksheet(self.current_sheet)
.map_err(|s| anyhow!("Invalid Worksheet: {}", s))?) .map_err(|s| anyhow!("Invalid Worksheet: {}", s))?)
} }
pub(crate) fn get_sheet_mut(&mut self) -> Result<&mut Worksheet> { pub(crate) fn get_sheet_mut(&mut self) -> Result<&mut Worksheet> {
Ok(self Ok(self
.model .model

View File

@ -69,12 +69,17 @@ fn test_book_insert_rows() {
let mut book = Book::default(); let mut book = Book::default();
book.update_entry(&Address { row: 2, col: 2 }, "1") book.update_entry(&Address { row: 2, col: 2 }, "1")
.expect("failed to edit cell"); .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")); assert_eq!((2, 2), book.get_size().expect("Failed to get size"));
book.insert_rows(1, 5).expect("Failed to insert rows"); book.insert_rows(1, 5).expect("Failed to insert rows");
assert_eq!((7, 2), book.get_size().expect("Failed to get size")); assert_eq!((7, 2), book.get_size().expect("Failed to get size"));
assert_eq!(Address {row: 7, col: 2, }, book.location); 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!(
"1",
book.get_current_cell_rendered()
.expect("Failed to get rendered content")
);
} }
#[test] #[test]
@ -82,12 +87,17 @@ fn test_book_insert_columns() {
let mut book = Book::default(); let mut book = Book::default();
book.update_entry(&Address { row: 2, col: 2 }, "1") book.update_entry(&Address { row: 2, col: 2 }, "1")
.expect("failed to edit cell"); .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")); assert_eq!((2, 2), book.get_size().expect("Failed to get size"));
book.insert_columns(1, 5).expect("Failed to insert rows"); book.insert_columns(1, 5).expect("Failed to insert rows");
assert_eq!((2, 7), book.get_size().expect("Failed to get size")); assert_eq!((2, 7), book.get_size().expect("Failed to get size"));
assert_eq!(Address {row: 2, col: 7, }, book.location); 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!(
"1",
book.get_current_cell_rendered()
.expect("Failed to get rendered content")
);
} }
#[test] #[test]

View File

@ -5,8 +5,8 @@ use crossterm::event;
use ratatui; use ratatui;
use ui::Workspace; use ui::Workspace;
mod ui;
mod book; mod book;
mod ui;
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(version, about, long_about = None)] #[command(version, about, long_about = None)]

View File

@ -78,7 +78,11 @@ fn try_consume_write<'cmd, 'i: 'cmd>(
return Err("Invalid command: Did you mean to type `write <arg>`?"); return Err("Invalid command: Did you mean to type `write <arg>`?");
} }
let arg = input.span(0..).trim(); 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>( 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<Option<Cmd<'cmd>>, &'static str> { fn try_consume_edit<'cmd, 'i: 'cmd>(
mut input: StrCursor<'i>,
) -> Result<Option<Cmd<'cmd>>, &'static str> {
const SHORT: &'static str = "e"; const SHORT: &'static str = "e";
const LONG: &'static str = "edit"; const LONG: &'static str = "edit";
@ -159,7 +165,9 @@ fn try_consume_edit<'cmd, 'i: 'cmd>(mut input: StrCursor<'i>) -> Result<Option<C
}))); })));
} }
fn try_consume_help<'cmd, 'i: 'cmd>(mut input: StrCursor<'i>) -> Result<Option<Cmd<'cmd>>, &'static str> { fn try_consume_help<'cmd, 'i: 'cmd>(
mut input: StrCursor<'i>,
) -> Result<Option<Cmd<'cmd>>, &'static str> {
const SHORT: &'static str = "?"; const SHORT: &'static str = "?";
const LONG: &'static str = "help"; const LONG: &'static str = "help";
@ -175,10 +183,16 @@ fn try_consume_help<'cmd, 'i: 'cmd>(mut input: StrCursor<'i>) -> Result<Option<C
return Err("Invalid command: Did you mean to type `help <arg>`?"); return Err("Invalid command: Did you mean to type `help <arg>`?");
} }
let arg = input.span(0..).trim(); 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<Option<Cmd<'cmd>>, &'static str> { fn try_consume_quit<'cmd, 'i: 'cmd>(
mut input: StrCursor<'i>,
) -> Result<Option<Cmd<'cmd>>, &'static str> {
const SHORT: &'static str = "q"; const SHORT: &'static str = "q";
const LONG: &'static str = "quit"; const LONG: &'static str = "quit";

View File

@ -41,7 +41,7 @@ impl<'widget, 'ws: 'widget> Widget for &'widget mut Workspace<'ws> {
} }
outer_block.render(area, buf); outer_block.render(area, buf);
if self.state.modality() == &Modality::Dialog { if self.state.modality() == &Modality::Dialog {
let lines = Text::from_iter(self.state.popup.iter().cloned()); let lines = Text::from_iter(self.state.popup.iter().cloned());
let popup = Popup::new(lines); 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()))]; let mut cells = vec![Cell::new(Text::from(ri.to_string()))];
cells.extend((1..=col_count).into_iter().map(|ci| { cells.extend((1..=col_count).into_iter().map(|ci| {
// TODO(zaphar): Is this safe? // 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)); let cell = Cell::new(Text::raw(content));
match (value.location.row == ri, value.location.col == ci) { match (value.location.row == ri, value.location.col == ci) {
(true, true) => cell.fg(Color::White).underlined(), (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<Constraint> = Vec::new(); let mut constraints: Vec<Constraint> = Vec::new();
constraints.push(Constraint::Max(5)); constraints.push(Constraint::Max(5));
for col_idx in 0..col_count { 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)); constraints.push(Constraint::Length(size as u16));
} }
let mut header = Vec::with_capacity(col_count as usize); let mut header = Vec::with_capacity(col_count as usize);