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
.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

View File

@ -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]

View File

@ -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)]

View File

@ -78,7 +78,11 @@ fn try_consume_write<'cmd, 'i: 'cmd>(
return Err("Invalid command: Did you mean to type `write <arg>`?");
}
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<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 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 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>`?");
}
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 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);
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<Constraint> = 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);