mirror of
https://github.com/zaphar/sheetsui.git
synced 2025-07-23 05:19:48 -04:00
chore: cargo fmt
This commit is contained in:
parent
01c2180c20
commit
4ff5d0adbe
@ -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(())
|
||||
}
|
||||
|
@ -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]
|
||||
|
@ -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)]
|
||||
|
@ -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";
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user