diff --git a/Cargo.lock b/Cargo.lock index 238dbd9..b73c783 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -256,6 +256,7 @@ dependencies = [ "log", "ratatui", "structopt", + "strum", "syntect", "tui-tree-widget", "uuid", diff --git a/Cargo.toml b/Cargo.toml index 6c6ad8a..8fc100c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,8 +15,9 @@ ratatui = "0.30.0" anyhow = "1.0.100" tui-tree-widget = "0.24.0" uuid = { version = "1.19.0", features = ["v4"] } -edtui = "0.11.0" +edtui = "0.11.1" +strum = "0.27.2" [build-dependencies] # The link_qt_object_files feature is required for statically linking Qt 6. -cxx-qt-build = { version = "0.7", features = [ "link_qt_object_files" ] } \ No newline at end of file +cxx-qt-build = { version = "0.7", features = [ "link_qt_object_files" ] } diff --git a/src/tui.rs b/src/tui.rs index ecb2ce7..d10ff05 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -1,4 +1,4 @@ -pub mod app; +mod app; mod component; mod editor; mod explorer; @@ -38,7 +38,7 @@ impl Tui { )?; enable_raw_mode()?; - let app_result = app::App::new(&self.root_path) + let app_result = app::App::new(self.root_path) .run(self.terminal) .context("Failed to start the TUI editor."); Self::stop()?; diff --git a/src/tui/app.rs b/src/tui/app.rs index 2d7af4e..47bd6b5 100644 --- a/src/tui/app.rs +++ b/src/tui/app.rs @@ -1,4 +1,4 @@ -use crate::tui::component::{Action, ClideComponent}; +use crate::tui::component::{Action, Component}; use crate::tui::editor::Editor; use crate::tui::explorer::Explorer; use ratatui::buffer::Buffer; @@ -16,7 +16,7 @@ pub struct 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 { explorer: Explorer::new(root_path), 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 { match key { KeyEvent { diff --git a/src/tui/component.rs b/src/tui/component.rs index 6ec0289..1ba4d60 100644 --- a/src/tui/component.rs +++ b/src/tui/component.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused_variables)] + use ratatui::crossterm::event::{Event, KeyEvent, MouseEvent}; pub enum Action { @@ -6,7 +8,7 @@ pub enum Action { Pass, // Pass input to another component. } -pub trait ClideComponent { +pub trait Component { fn handle_event(&mut self, event: Event) -> Action { match 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 } - #[allow(dead_code)] - fn handle_mouse_events(&mut self, _mouse: MouseEvent) -> Action { + fn handle_mouse_events(&mut self, mouse: MouseEvent) -> Action { Action::Noop } - #[allow(dead_code)] - fn update(&mut self, _action: Action) -> Action { + fn update(&mut self, action: Action) -> Action { Action::Noop } } diff --git a/src/tui/editor.rs b/src/tui/editor.rs index 9657184..dfa88f2 100644 --- a/src/tui/editor.rs +++ b/src/tui/editor.rs @@ -1,4 +1,4 @@ -use crate::tui::component::{Action, ClideComponent}; +use crate::tui::component::{Action, Component}; use edtui::{ 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 { self.event_handler.on_key_event(key, &mut self.state); Action::Pass diff --git a/src/tui/explorer.rs b/src/tui/explorer.rs index 37f2bee..e934cee 100644 --- a/src/tui/explorer.rs +++ b/src/tui/explorer.rs @@ -1,4 +1,4 @@ -use crate::tui::component::ClideComponent; +use crate::tui::component::Component; use anyhow::Result; use ratatui::buffer::Buffer; use ratatui::layout::{Alignment, Rect}; @@ -11,15 +11,15 @@ use uuid::Uuid; #[derive(Clone, Debug)] pub struct Explorer<'a> { - root_path: &'a std::path::Path, + root_path: std::path::PathBuf, tree_items: TreeItem<'a, String>, } impl<'a> Explorer<'a> { - pub fn new(path: &'a std::path::Path) -> Self { + pub fn new(path: std::path::PathBuf) -> Self { let explorer = Explorer { - root_path: path, - tree_items: Self::build_tree_from_path(path.into()), + root_path: path.to_owned(), + tree_items: Self::build_tree_from_path(path), }; explorer } @@ -38,7 +38,10 @@ impl<'a> Explorer<'a> { } else { children.push(TreeItem::new_leaf( 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( Uuid::new_v4().to_string(), path.file_name() - .unwrap_or_default() + .expect("Failed to get file name from path.") .to_string_lossy() .to_string(), children, @@ -77,4 +80,4 @@ impl<'a> Widget for &Explorer<'a> { } } -impl<'a> ClideComponent for Explorer<'a> {} +impl<'a> Component for Explorer<'a> {}