[tui] Cleanup and renames.

This commit is contained in:
Shaun Reed 2026-01-19 09:23:12 -05:00
parent ce6c12f068
commit 507a4d8651
7 changed files with 28 additions and 23 deletions

1
Cargo.lock generated
View File

@ -256,6 +256,7 @@ dependencies = [
"log", "log",
"ratatui", "ratatui",
"structopt", "structopt",
"strum",
"syntect", "syntect",
"tui-tree-widget", "tui-tree-widget",
"uuid", "uuid",

View File

@ -15,7 +15,8 @@ ratatui = "0.30.0"
anyhow = "1.0.100" anyhow = "1.0.100"
tui-tree-widget = "0.24.0" tui-tree-widget = "0.24.0"
uuid = { version = "1.19.0", features = ["v4"] } uuid = { version = "1.19.0", features = ["v4"] }
edtui = "0.11.0" edtui = "0.11.1"
strum = "0.27.2"
[build-dependencies] [build-dependencies]
# The link_qt_object_files feature is required for statically linking Qt 6. # The link_qt_object_files feature is required for statically linking Qt 6.

View File

@ -1,4 +1,4 @@
pub mod app; mod app;
mod component; mod component;
mod editor; mod editor;
mod explorer; mod explorer;
@ -38,7 +38,7 @@ impl Tui {
)?; )?;
enable_raw_mode()?; enable_raw_mode()?;
let app_result = app::App::new(&self.root_path) let app_result = app::App::new(self.root_path)
.run(self.terminal) .run(self.terminal)
.context("Failed to start the TUI editor."); .context("Failed to start the TUI editor.");
Self::stop()?; Self::stop()?;

View File

@ -1,4 +1,4 @@
use crate::tui::component::{Action, ClideComponent}; use crate::tui::component::{Action, Component};
use crate::tui::editor::Editor; use crate::tui::editor::Editor;
use crate::tui::explorer::Explorer; use crate::tui::explorer::Explorer;
use ratatui::buffer::Buffer; use ratatui::buffer::Buffer;
@ -16,7 +16,7 @@ pub struct App<'a> {
} }
impl<'a> App<'a> { impl<'a> App<'a> {
pub(crate) fn new(root_path: &'a std::path::Path) -> Self { pub(crate) fn new(root_path: std::path::PathBuf) -> Self {
Self { Self {
explorer: Explorer::new(root_path), explorer: Explorer::new(root_path),
editor: Editor::new(), editor: Editor::new(),
@ -130,7 +130,7 @@ impl<'a> Widget for &mut App<'a> {
} }
} }
impl<'a> ClideComponent for App<'a> { impl<'a> Component for App<'a> {
fn handle_key_events(&mut self, key: KeyEvent) -> Action { fn handle_key_events(&mut self, key: KeyEvent) -> Action {
match key { match key {
KeyEvent { KeyEvent {

View File

@ -1,3 +1,5 @@
#![allow(dead_code, unused_variables)]
use ratatui::crossterm::event::{Event, KeyEvent, MouseEvent}; use ratatui::crossterm::event::{Event, KeyEvent, MouseEvent};
pub enum Action { pub enum Action {
@ -6,7 +8,7 @@ pub enum Action {
Pass, // Pass input to another component. Pass, // Pass input to another component.
} }
pub trait ClideComponent { pub trait Component {
fn handle_event(&mut self, event: Event) -> Action { fn handle_event(&mut self, event: Event) -> Action {
match event { match event {
Event::Key(key_event) => self.handle_key_events(key_event), Event::Key(key_event) => self.handle_key_events(key_event),
@ -14,17 +16,15 @@ pub trait ClideComponent {
} }
} }
fn handle_key_events(&mut self, _key: KeyEvent) -> Action { fn handle_key_events(&mut self, key: KeyEvent) -> Action {
Action::Noop Action::Noop
} }
#[allow(dead_code)] fn handle_mouse_events(&mut self, mouse: MouseEvent) -> Action {
fn handle_mouse_events(&mut self, _mouse: MouseEvent) -> Action {
Action::Noop Action::Noop
} }
#[allow(dead_code)] fn update(&mut self, action: Action) -> Action {
fn update(&mut self, _action: Action) -> Action {
Action::Noop Action::Noop
} }
} }

View File

@ -1,4 +1,4 @@
use crate::tui::component::{Action, ClideComponent}; use crate::tui::component::{Action, Component};
use edtui::{ use edtui::{
EditorEventHandler, EditorState, EditorTheme, EditorView, LineNumbers, SyntaxHighlighter, EditorEventHandler, EditorState, EditorTheme, EditorView, LineNumbers, SyntaxHighlighter,
}; };
@ -51,7 +51,7 @@ impl Widget for &mut Editor {
} }
} }
impl ClideComponent for Editor { impl Component for Editor {
fn handle_key_events(&mut self, key: KeyEvent) -> Action { fn handle_key_events(&mut self, key: KeyEvent) -> Action {
self.event_handler.on_key_event(key, &mut self.state); self.event_handler.on_key_event(key, &mut self.state);
Action::Pass Action::Pass

View File

@ -1,4 +1,4 @@
use crate::tui::component::ClideComponent; use crate::tui::component::Component;
use anyhow::Result; use anyhow::Result;
use ratatui::buffer::Buffer; use ratatui::buffer::Buffer;
use ratatui::layout::{Alignment, Rect}; use ratatui::layout::{Alignment, Rect};
@ -11,15 +11,15 @@ use uuid::Uuid;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Explorer<'a> { pub struct Explorer<'a> {
root_path: &'a std::path::Path, root_path: std::path::PathBuf,
tree_items: TreeItem<'a, String>, tree_items: TreeItem<'a, String>,
} }
impl<'a> Explorer<'a> { impl<'a> Explorer<'a> {
pub fn new(path: &'a std::path::Path) -> Self { pub fn new(path: std::path::PathBuf) -> Self {
let explorer = Explorer { let explorer = Explorer {
root_path: path, root_path: path.to_owned(),
tree_items: Self::build_tree_from_path(path.into()), tree_items: Self::build_tree_from_path(path),
}; };
explorer explorer
} }
@ -38,7 +38,10 @@ impl<'a> Explorer<'a> {
} else { } else {
children.push(TreeItem::new_leaf( children.push(TreeItem::new_leaf(
Uuid::new_v4().to_string(), Uuid::new_v4().to_string(),
path.file_name().unwrap().to_string_lossy().to_string(), path.file_name()
.expect("Failed to get file name from path.")
.to_string_lossy()
.to_string(),
)); ));
} }
} }
@ -47,7 +50,7 @@ impl<'a> Explorer<'a> {
TreeItem::new( TreeItem::new(
Uuid::new_v4().to_string(), Uuid::new_v4().to_string(),
path.file_name() path.file_name()
.unwrap_or_default() .expect("Failed to get file name from path.")
.to_string_lossy() .to_string_lossy()
.to_string(), .to_string(),
children, children,
@ -77,4 +80,4 @@ impl<'a> Widget for &Explorer<'a> {
} }
} }
impl<'a> ClideComponent for Explorer<'a> {} impl<'a> Component for Explorer<'a> {}