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

@ -123,12 +123,7 @@ impl CmdRegistry {
/// Register a command with both a text parser and an interactive constructor.
/// The name is derived from a prototype command instance.
pub fn register(
&mut self,
prototype: &dyn Cmd,
parse: ParseFn,
interactive: InteractiveFn,
) {
pub fn register(&mut self, prototype: &dyn Cmd, parse: ParseFn, interactive: InteractiveFn) {
self.entries.push(CmdEntry {
name: prototype.name(),
parse: Box::new(parse),
@ -317,7 +312,14 @@ impl Cmd for MoveSelection {
let col_max = self.cursor.col_count.saturating_sub(1);
let nr = (self.cursor.row as i32 + self.dr).clamp(0, row_max as i32) as usize;
let nc = (self.cursor.col as i32 + self.dc).clamp(0, col_max as i32) as usize;
viewport_effects(nr, nc, self.cursor.row_offset, self.cursor.col_offset, self.cursor.visible_rows, self.cursor.visible_cols)
viewport_effects(
nr,
nc,
self.cursor.row_offset,
self.cursor.col_offset,
self.cursor.visible_rows,
self.cursor.visible_cols,
)
}
}
@ -336,16 +338,27 @@ impl Cmd for JumpToEdge {
}
fn execute(&self, _ctx: &CmdContext) -> Vec<Box<dyn Effect>> {
let (nr, nc) = if self.is_row {
let r = if self.end { self.cursor.row_count.saturating_sub(1) } else { 0 };
let r = if self.end {
self.cursor.row_count.saturating_sub(1)
} else {
0
};
(r, self.cursor.col)
} else {
let c = if self.end { self.cursor.col_count.saturating_sub(1) } else { 0 };
let c = if self.end {
self.cursor.col_count.saturating_sub(1)
} else {
0
};
(self.cursor.row, c)
};
viewport_effects(
nr, nc,
self.cursor.row_offset, self.cursor.col_offset,
self.cursor.visible_rows, self.cursor.visible_cols,
nr,
nc,
self.cursor.row_offset,
self.cursor.col_offset,
self.cursor.visible_rows,
self.cursor.visible_cols,
)
}
}
@ -711,10 +724,7 @@ impl Cmd for AddRecordRow {
let coords: Vec<(String, String)> = page_cats
.iter()
.map(|cat| {
let sel = view
.page_selection(cat)
.unwrap_or("")
.to_string();
let sel = view.page_selection(cat).unwrap_or("").to_string();
(cat.clone(), sel)
})
.filter(|(_, v)| !v.is_empty())
@ -772,7 +782,14 @@ impl Cmd for EnterAdvance {
} else {
(r, c) // already at bottom-right; stay
};
viewport_effects(nr, nc, self.cursor.row_offset, self.cursor.col_offset, self.cursor.visible_rows, self.cursor.visible_cols)
viewport_effects(
nr,
nc,
self.cursor.row_offset,
self.cursor.col_offset,
self.cursor.visible_rows,
self.cursor.visible_cols,
)
}
}
@ -1916,7 +1933,10 @@ fn commit_cell_value(key: &CellKey, value: &str, effects: &mut Vec<Box<dyn Effec
effects.push(Box::new(effect::SetCell(key.clone(), CellValue::Number(n))));
effects.push(effect::mark_dirty());
} else {
effects.push(Box::new(effect::SetCell(key.clone(), CellValue::Text(value.to_string()))));
effects.push(Box::new(effect::SetCell(
key.clone(),
CellValue::Text(value.to_string()),
)));
effects.push(effect::mark_dirty());
}
}
@ -2420,7 +2440,9 @@ pub fn default_registry() -> CmdRegistry {
r.register_pure(&AddItemInGroupCmd(vec![]), AddItemInGroupCmd::parse);
r.register_pure(&SetCellCmd(vec![]), SetCellCmd::parse);
r.register(
&ClearCellCommand { key: CellKey::new(vec![]) },
&ClearCellCommand {
key: CellKey::new(vec![]),
},
|args| {
if args.is_empty() {
return Err("clear-cell requires at least one Cat/Item coordinate".into());
@ -2451,7 +2473,11 @@ pub fn default_registry() -> CmdRegistry {
// ── Navigation ───────────────────────────────────────────────────────
r.register(
&MoveSelection { dr: 0, dc: 0, cursor: CursorState::default() },
&MoveSelection {
dr: 0,
dc: 0,
cursor: CursorState::default(),
},
|args| {
require_args("move-selection", args, 2)?;
let dr = args[0].parse::<i32>().map_err(|e| e.to_string())?;
@ -2486,18 +2512,40 @@ pub fn default_registry() -> CmdRegistry {
macro_rules! reg_jump {
($r:expr, $is_row:expr, $end:expr, $name:expr) => {
$r.register(
&JumpToEdge { cursor: CursorState::default(), is_row: $is_row, end: $end, cmd_name: $name },
|_| Ok(Box::new(JumpToEdge { cursor: CursorState::default(), is_row: $is_row, end: $end, cmd_name: $name })),
|_, ctx| Ok(Box::new(JumpToEdge { cursor: CursorState::from_ctx(ctx), is_row: $is_row, end: $end, cmd_name: $name })),
&JumpToEdge {
cursor: CursorState::default(),
is_row: $is_row,
end: $end,
cmd_name: $name,
},
|_| {
Ok(Box::new(JumpToEdge {
cursor: CursorState::default(),
is_row: $is_row,
end: $end,
cmd_name: $name,
}))
},
|_, ctx| {
Ok(Box::new(JumpToEdge {
cursor: CursorState::from_ctx(ctx),
is_row: $is_row,
end: $end,
cmd_name: $name,
}))
},
);
};
}
reg_jump!(r, true, false, "jump-first-row");
reg_jump!(r, true, true, "jump-last-row");
reg_jump!(r, true, false, "jump-first-row");
reg_jump!(r, true, true, "jump-last-row");
reg_jump!(r, false, false, "jump-first-col");
reg_jump!(r, false, true, "jump-last-col");
reg_jump!(r, false, true, "jump-last-col");
r.register(
&ScrollRows { delta: 0, cursor: CursorState::default() },
&ScrollRows {
delta: 0,
cursor: CursorState::default(),
},
|args| {
require_args("scroll-rows", args, 1)?;
let n = args[0].parse::<i32>().map_err(|e| e.to_string())?;
@ -2525,7 +2573,10 @@ pub fn default_registry() -> CmdRegistry {
},
);
r.register(
&PageScroll { direction: 0, cursor: CursorState::default() },
&PageScroll {
direction: 0,
cursor: CursorState::default(),
},
|args| {
require_args("page-scroll", args, 1)?;
let dir = args[0].parse::<i32>().map_err(|e| e.to_string())?;
@ -2544,7 +2595,9 @@ pub fn default_registry() -> CmdRegistry {
},
);
r.register(
&EnterAdvance { cursor: CursorState::default() },
&EnterAdvance {
cursor: CursorState::default(),
},
|_| {
Ok(Box::new(EnterAdvance {
cursor: CursorState {
@ -2568,7 +2621,9 @@ pub fn default_registry() -> CmdRegistry {
// ── Cell operations ──────────────────────────────────────────────────
r.register(
&YankCell { key: CellKey::new(vec![]) },
&YankCell {
key: CellKey::new(vec![]),
},
|args| {
if args.is_empty() {
return Err("yank requires at least one Cat/Item coordinate".into());
@ -2612,20 +2667,16 @@ pub fn default_registry() -> CmdRegistry {
r.register_nullary(|| Box::new(SaveCmd));
r.register_nullary(|| Box::new(EnterSearchMode));
r.register(
&EnterEditMode { initial_value: String::new() },
&EnterEditMode {
initial_value: String::new(),
},
|args| {
let val = args.first().cloned().unwrap_or_default();
Ok(Box::new(EnterEditMode { initial_value: val }))
},
|_args, ctx| {
let current = ctx
.cell_key
.as_ref()
.and_then(|k| ctx.model.get_cell(k).cloned())
.map(|v| v.to_string())
.unwrap_or_default();
Ok(Box::new(EnterEditMode {
initial_value: current,
initial_value: ctx.display_value.clone(),
}))
},
);
@ -2693,7 +2744,11 @@ pub fn default_registry() -> CmdRegistry {
// ── Panel operations ─────────────────────────────────────────────────
r.register(
&TogglePanelAndFocus { panel: Panel::Formula, open: true, focused: true },
&TogglePanelAndFocus {
panel: Panel::Formula,
open: true,
focused: true,
},
|args| {
// Parse: toggle-panel-and-focus <panel> [open] [focused]
require_args("toggle-panel-and-focus", args, 1)?;
@ -2716,8 +2771,14 @@ pub fn default_registry() -> CmdRegistry {
Panel::View => ctx.view_panel_open,
};
let currently_focused = match panel {
Panel::Formula => matches!(ctx.mode, AppMode::FormulaPanel | AppMode::FormulaEdit { .. }),
Panel::Category => matches!(ctx.mode, AppMode::CategoryPanel | AppMode::CategoryAdd { .. } | AppMode::ItemAdd { .. }),
Panel::Formula => matches!(
ctx.mode,
AppMode::FormulaPanel | AppMode::FormulaEdit { .. }
),
Panel::Category => matches!(
ctx.mode,
AppMode::CategoryPanel | AppMode::CategoryAdd { .. } | AppMode::ItemAdd { .. }
),
Panel::View => matches!(ctx.mode, AppMode::ViewPanel),
};
let (open, focused) = if currently_open && currently_focused {
@ -2733,7 +2794,10 @@ pub fn default_registry() -> CmdRegistry {
},
);
r.register(
&TogglePanelVisibility { panel: Panel::Formula, currently_open: false },
&TogglePanelVisibility {
panel: Panel::Formula,
currently_open: false,
},
|args| {
require_args("toggle-panel-visibility", args, 1)?;
let panel = parse_panel(&args[0])?;
@ -2757,7 +2821,11 @@ pub fn default_registry() -> CmdRegistry {
},
);
r.register(
&CyclePanelFocus { formula_open: false, category_open: false, view_open: false },
&CyclePanelFocus {
formula_open: false,
category_open: false,
view_open: false,
},
|_| {
Ok(Box::new(CyclePanelFocus {
formula_open: false,
@ -2774,7 +2842,12 @@ pub fn default_registry() -> CmdRegistry {
},
);
r.register(
&MovePanelCursor { panel: Panel::Formula, delta: 0, current: 0, max: 0 },
&MovePanelCursor {
panel: Panel::Formula,
delta: 0,
current: 0,
max: 0,
},
|args| {
require_args("move-panel-cursor", args, 2)?;
let panel = parse_panel(&args[0])?;
@ -2803,9 +2876,7 @@ pub fn default_registry() -> CmdRegistry {
}))
},
);
r.register_nullary(|| {
Box::new(DeleteFormulaAtCursor)
});
r.register_nullary(|| Box::new(DeleteFormulaAtCursor));
r.register_nullary(|| Box::new(AddRecordRow));
r.register_nullary(|| Box::new(OpenRecordRow));
r.register_nullary(|| Box::new(TogglePruneEmpty));
@ -2833,12 +2904,8 @@ pub fn default_registry() -> CmdRegistry {
});
// ── Grid operations ──────────────────────────────────────────────────
r.register_nullary(|| {
Box::new(ToggleGroupUnderCursor)
});
r.register_nullary(|| {
Box::new(ToggleColGroupUnderCursor)
});
r.register_nullary(|| Box::new(ToggleGroupUnderCursor));
r.register_nullary(|| Box::new(ToggleColGroupUnderCursor));
r.register_nullary(|| Box::new(HideSelectedRowItem));
// ── Text buffer ──────────────────────────────────────────────────────