refactor: remove Axis::Unassigned; axis_of returns Option<Axis>
Axis::Unassigned served two purposes that Option already covers:
1. "this category has no assignment yet" → None
2. "this category doesn't exist" → None
By removing the variant and changing axis_of to return Option<Axis>,
callers are forced by the compiler to handle the absent-category case
explicitly (via match or unwrap_or), rather than silently treating it
like a real axis value.
SetAxis { axis: String } also upgraded to SetAxis { axis: Axis }.
Previously, constructing SetAxis with an invalid string (e.g. "diagonal")
would compile and then silently fail at dispatch. Now the type only admits
valid axis values; the dispatch string-parser is gone.
Axis gains #[serde(rename_all = "lowercase")] so existing JSON command
files (smoke.jsonl, etc.) using "row"/"column"/"page" continue to work.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@ -813,21 +813,21 @@ impl App {
|
||||
}
|
||||
KeyCode::Char('r') => {
|
||||
if let Some(name) = cat_names.get(cat_idx) {
|
||||
command::dispatch(&mut self.model, &Command::SetAxis { category: name.clone(), axis: "row".to_string() });
|
||||
command::dispatch(&mut self.model, &Command::SetAxis { category: name.clone(), axis: Axis::Row });
|
||||
self.dirty = true;
|
||||
}
|
||||
self.mode = AppMode::Normal;
|
||||
}
|
||||
KeyCode::Char('c') => {
|
||||
if let Some(name) = cat_names.get(cat_idx) {
|
||||
command::dispatch(&mut self.model, &Command::SetAxis { category: name.clone(), axis: "column".to_string() });
|
||||
command::dispatch(&mut self.model, &Command::SetAxis { category: name.clone(), axis: Axis::Column });
|
||||
self.dirty = true;
|
||||
}
|
||||
self.mode = AppMode::Normal;
|
||||
}
|
||||
KeyCode::Char('p') => {
|
||||
if let Some(name) = cat_names.get(cat_idx) {
|
||||
command::dispatch(&mut self.model, &Command::SetAxis { category: name.clone(), axis: "page".to_string() });
|
||||
command::dispatch(&mut self.model, &Command::SetAxis { category: name.clone(), axis: Axis::Page });
|
||||
self.dirty = true;
|
||||
}
|
||||
self.mode = AppMode::Normal;
|
||||
|
||||
@ -67,16 +67,16 @@ impl<'a> Widget for CategoryPanel<'a> {
|
||||
|
||||
let axis = view.axis_of(cat_name);
|
||||
let axis_str = match axis {
|
||||
Axis::Row => "Row ↕",
|
||||
Axis::Column => "Col ↔",
|
||||
Axis::Page => "Page ☰",
|
||||
Axis::Unassigned => "none",
|
||||
Some(Axis::Row) => "Row ↕",
|
||||
Some(Axis::Column) => "Col ↔",
|
||||
Some(Axis::Page) => "Page ☰",
|
||||
None => "none",
|
||||
};
|
||||
let axis_color = match axis {
|
||||
Axis::Row => Color::Green,
|
||||
Axis::Column => Color::Blue,
|
||||
Axis::Page => Color::Magenta,
|
||||
Axis::Unassigned => Color::DarkGray,
|
||||
Some(Axis::Row) => Color::Green,
|
||||
Some(Axis::Column) => Color::Blue,
|
||||
Some(Axis::Page) => Color::Magenta,
|
||||
None => Color::DarkGray,
|
||||
};
|
||||
|
||||
let item_count = self.model.category(cat_name).map(|c| c.items.len()).unwrap_or(0);
|
||||
|
||||
@ -41,10 +41,10 @@ impl<'a> Widget for TileBar<'a> {
|
||||
for (i, cat_name) in cat_names.iter().enumerate() {
|
||||
let axis = view.axis_of(cat_name);
|
||||
let axis_symbol = match axis {
|
||||
Axis::Row => "↕",
|
||||
Axis::Column => "↔",
|
||||
Axis::Page => "☰",
|
||||
Axis::Unassigned => "─",
|
||||
Some(Axis::Row) => "↕",
|
||||
Some(Axis::Column) => "↔",
|
||||
Some(Axis::Page) => "☰",
|
||||
None => "─",
|
||||
};
|
||||
|
||||
let label = format!(" [{cat_name} {axis_symbol}] ");
|
||||
@ -54,10 +54,10 @@ impl<'a> Widget for TileBar<'a> {
|
||||
Style::default().fg(Color::Black).bg(Color::Cyan).add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
match axis {
|
||||
Axis::Row => Style::default().fg(Color::Green),
|
||||
Axis::Column => Style::default().fg(Color::Blue),
|
||||
Axis::Page => Style::default().fg(Color::Magenta),
|
||||
Axis::Unassigned => Style::default().fg(Color::DarkGray),
|
||||
Some(Axis::Row) => Style::default().fg(Color::Green),
|
||||
Some(Axis::Column) => Style::default().fg(Color::Blue),
|
||||
Some(Axis::Page) => Style::default().fg(Color::Magenta),
|
||||
None => Style::default().fg(Color::DarkGray),
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user