refactor: modularize architecture

refactors the application structure to move away from a monolithic
`main.rs`.

- **Domain Models**: Extracted `State`, `Message`, `FileAction`, and
`ViewAction` into `state.rs` and `message.rs`. Enforced encapsulation on
`State` using private fields and public accessors.
- **Controller Layer**: Created `handler.rs` to handle business logic
and I/O operations, transforming the main `update` loop into a pure
event router.
- **Component System**: Split the UI into composable, stateless
functions in `components/` (tabs, editor, status_bar, action_bar),
removing the 100+ line view function.
- **File Logic**: Encapsulated file operations and safe path handling
within `file.rs`, removing fragile `expect` calls from the UI layer.
- **Utilities**: Centralized static configuration, keybindings, and I/O
helpers into `constants.rs`, `key_bindings.rs`, and `io.rs`.

This change decouples the view from the model and makes the core
application logic testable
This commit is contained in:
Stevan Freeborn
2026-01-24 20:51:26 -06:00
parent cb5f1cf717
commit f5d98197ac
13 changed files with 695 additions and 507 deletions
+71
View File
@@ -0,0 +1,71 @@
use std::fmt::Display;
use iced::widget::text_editor;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FileAction {
New,
Save,
SaveAs,
Open,
Close(Option<usize>),
}
impl FileAction {
pub const ALL: &'static [FileAction] = &[
FileAction::New,
FileAction::Save,
FileAction::SaveAs,
FileAction::Open,
FileAction::Close(None),
];
}
impl Display for FileAction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
FileAction::New => write!(f, "New file"),
FileAction::Save => write!(f, "Save"),
FileAction::SaveAs => write!(f, "Save as... "),
FileAction::Open => write!(f, "Open"),
FileAction::Close(_) => write!(f, "Close"),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ViewAction {
Increase,
Decrease,
Reset,
TogglePreview,
}
impl ViewAction {
pub const ALL: &'static [ViewAction] = &[
ViewAction::Increase,
ViewAction::Decrease,
ViewAction::Reset,
ViewAction::TogglePreview,
];
}
impl Display for ViewAction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ViewAction::Decrease => write!(f, "Decrease font"),
ViewAction::Increase => write!(f, "Increase font"),
ViewAction::Reset => write!(f, "Reset font"),
ViewAction::TogglePreview => write!(f, "Toggle preview"),
}
}
}
#[derive(Debug, Clone)]
pub enum Message {
Edit(text_editor::Action),
FileActionSelected(FileAction),
ViewActionSelected(ViewAction),
SwitchTab(usize),
LinkClicked(String),
}