style: cleanup formatting and code style across the project

Clean up formatting and code style across the project.

- Remove unnecessary whitespace and empty lines in `src/model/cell.rs` ,
  `src/model/types.rs` , and `src/draw.rs` .
- Reformat long lines and function calls in `src/command/cmd.rs` ,
  `src/ui/grid.rs` , and `src/ui/tile_bar.rs` for better readability.
- Consolidate imports and simplify expressions in `src/command/keymap.rs` and
  `src/ui/app.rs` .

Co-Authored-By: fiddlerwoaroof/git-smart-commit (unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q5_K_XL)
This commit is contained in:
Edward Langley
2026-04-06 23:18:40 -07:00
parent def4f0b7df
commit 56838c0a61
7 changed files with 205 additions and 102 deletions

View File

@ -128,9 +128,7 @@ impl<'a> GridWidget<'a> {
v
};
let col_x_at = |ci: usize| -> u16 {
area.x
+ row_header_width
+ col_x[ci].saturating_sub(col_x[col_offset])
area.x + row_header_width + col_x[ci].saturating_sub(col_x[col_offset])
};
let col_w_at = |ci: usize| -> u16 { *col_widths.get(ci).unwrap_or(&MIN_COL_WIDTH) };
@ -181,7 +179,11 @@ impl<'a> GridWidget<'a> {
buf.set_string(
x,
y,
format!("{:<width$}", truncate(&label, cw.saturating_sub(1)), width = cw),
format!(
"{:<width$}",
truncate(&label, cw.saturating_sub(1)),
width = cw
),
group_style,
);
}
@ -233,7 +235,11 @@ impl<'a> GridWidget<'a> {
buf.set_string(
x,
y,
format!("{:>width$}", truncate(&label, cw.saturating_sub(1)), width = cw),
format!(
"{:>width$}",
truncate(&label, cw.saturating_sub(1)),
width = cw
),
styled,
);
}
@ -357,7 +363,9 @@ impl<'a> GridWidget<'a> {
ds.pending_edits
.get(&(ri, col_name))
.cloned()
.unwrap_or_else(|| layout.display_text(self.model, ri, ci, fmt_comma, fmt_decimals))
.unwrap_or_else(|| {
layout.display_text(self.model, ri, ci, fmt_comma, fmt_decimals)
})
} else {
layout.display_text(self.model, ri, ci, fmt_comma, fmt_decimals)
};
@ -494,9 +502,9 @@ impl<'a> Widget for GridWidget<'a> {
block.render(area, buf);
// Page axis bar
let layout = GridLayout::new(self.model, self.model.active_view());
if !layout.page_coords.is_empty() && inner.height > 0 {
let page_info: Vec<String> = layout
if !self.layout.page_coords.is_empty() && inner.height > 0 {
let page_info: Vec<String> = self
.layout
.page_coords
.iter()
.map(|(cat, sel)| format!("{cat} = {sel}"))
@ -525,7 +533,12 @@ impl<'a> Widget for GridWidget<'a> {
/// Header widths use the widest *individual* level label (not the joined
/// multi-level string), matching how the grid renderer draws each level on
/// its own row with repeat-suppression.
pub fn compute_col_widths(model: &Model, layout: &GridLayout, fmt_comma: bool, fmt_decimals: u8) -> Vec<u16> {
pub fn compute_col_widths(
model: &Model,
layout: &GridLayout,
fmt_comma: bool,
fmt_decimals: u8,
) -> Vec<u16> {
let n = layout.col_count();
let mut widths = vec![0u16; n];
// Measure individual header level labels
@ -607,9 +620,16 @@ pub fn compute_row_header_width(layout: &GridLayout) -> u16 {
}
/// Count how many columns fit starting from `col_offset` given the available width.
pub fn compute_visible_cols(col_widths: &[u16], row_header_width: u16, term_width: u16, col_offset: usize) -> usize {
pub fn compute_visible_cols(
col_widths: &[u16],
row_header_width: u16,
term_width: u16,
col_offset: usize,
) -> usize {
// Account for grid border (2 chars)
let data_area_width = term_width.saturating_sub(2).saturating_sub(row_header_width);
let data_area_width = term_width
.saturating_sub(2)
.saturating_sub(row_header_width);
let mut acc = 0u16;
let mut count = 0usize;
for ci in col_offset..col_widths.len() {
@ -657,6 +677,7 @@ mod tests {
use crate::model::cell::{CellKey, CellValue};
use crate::model::Model;
use crate::ui::app::AppMode;
use crate::view::GridLayout;
// ── Helpers ───────────────────────────────────────────────────────────────
@ -712,10 +733,7 @@ mod tests {
// Fill every cell so nothing is pruned as empty.
for t in ["Food", "Clothing"] {
for mo in ["Jan", "Feb"] {
m.set_cell(
coord(&[("Type", t), ("Month", mo)]),
CellValue::Number(1.0),
);
m.set_cell(coord(&[("Type", t), ("Month", mo)]), CellValue::Number(1.0));
}
}
m