TUI #1

Merged
shaunrd0 merged 73 commits from ui into master 2026-01-25 20:57:37 +00:00
7 changed files with 28 additions and 23 deletions
Showing only changes of commit 507a4d8651 - Show all commits

1
Cargo.lock generated
View File

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

View File

@ -15,7 +15,8 @@ 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.

View File

@ -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()?;

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::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 {

View File

@ -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
}
}

View File

@ -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

View File

@ -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> {}