TUI #1

Merged
shaunrd0 merged 73 commits from ui into master 2026-01-25 20:57:37 +00:00
6 changed files with 17 additions and 10 deletions
Showing only changes of commit a3d850acd9 - Show all commits

3
.cargo/config.toml Normal file
View File

@ -0,0 +1,3 @@
[build]
rustflags = [ "-C", "link-arg=-fuse-ld=lld", ]

View File

@ -6,7 +6,7 @@ use crate::tui::logger::Logger;
use crate::tui::menu_bar::MenuBar; use crate::tui::menu_bar::MenuBar;
use AppComponent::AppMenuBar; use AppComponent::AppMenuBar;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use log::{error, info, trace, warn}; use log::{error, info, trace};
use ratatui::DefaultTerminal; use ratatui::DefaultTerminal;
use ratatui::buffer::Buffer; use ratatui::buffer::Buffer;
use ratatui::crossterm::event; use ratatui::crossterm::event;

View File

@ -24,13 +24,12 @@ impl Editor {
"Editor" "Editor"
} }
// TODO: You shouldnt be able to construct the editor without a path? pub fn new(path: &std::path::PathBuf) -> Self {
pub fn new() -> Self {
trace!(target:Self::id(), "Building {}", Self::id()); trace!(target:Self::id(), "Building {}", Self::id());
Editor { Editor {
state: EditorState::default(), state: EditorState::default(),
event_handler: EditorEventHandler::default(), event_handler: EditorEventHandler::default(),
file_path: None, file_path: Some(path.to_owned()),
syntax_set: SyntaxSet::load_defaults_nonewlines(), syntax_set: SyntaxSet::load_defaults_nonewlines(),
component_state: ComponentState::default().with_help_text(concat!( component_state: ComponentState::default().with_help_text(concat!(
"CTRL+S: Save file | ALT+(←/h): Previous tab | ALT+(l/→): Next tab |", "CTRL+S: Save file | ALT+(←/h): Previous tab | ALT+(l/→): Next tab |",

View File

@ -27,7 +27,7 @@ impl EditorTab {
trace!(target:Self::id(), "Building EditorTab with path {path:?}"); trace!(target:Self::id(), "Building EditorTab with path {path:?}");
let tab_order = vec![path.to_string_lossy().to_string()]; let tab_order = vec![path.to_string_lossy().to_string()];
Self { Self {
editors: HashMap::from([(tab_order.first().unwrap().to_owned(), Editor::new())]), editors: HashMap::from([(tab_order.first().unwrap().to_owned(), Editor::new(path))]),
tab_order, tab_order,
current_editor: 0, current_editor: 0,
} }
@ -68,7 +68,7 @@ impl EditorTab {
let path_str = path.to_string_lossy().to_string(); let path_str = path.to_string_lossy().to_string();
self.tab_order.push(path_str.clone()); self.tab_order.push(path_str.clone());
let mut editor = Editor::new(); let mut editor = Editor::new(path);
editor.set_contents(path).context("Failed to open tab")?; editor.set_contents(path).context("Failed to open tab")?;
self.editors.insert(path_str, editor); self.editors.insert(path_str, editor);
self.current_editor = self.tab_order.len() - 1; self.current_editor = self.tab_order.len() - 1;

View File

@ -32,7 +32,7 @@ impl<'a> Explorer<'a> {
tree_state: TreeState::default(), tree_state: TreeState::default(),
component_state: ComponentState::default().with_help_text(concat!( component_state: ComponentState::default().with_help_text(concat!(
"(↑/k)/(↓/j): Select item | ←/h: Close folder | →/l: Open folder |", "(↑/k)/(↓/j): Select item | ←/h: Close folder | →/l: Open folder |",
" Enter: Open editor tab" " Space: Open / close folder | Enter: Open file in new editor tab"
)), )),
}; };
Ok(explorer) Ok(explorer)
@ -149,7 +149,7 @@ impl<'a> Component for Explorer<'a> {
return Ok(Action::OpenTab); return Ok(Action::OpenTab);
} }
} }
return Ok(Action::Noop); // Otherwise fall through and handle Enter in the next match case.
} }
let changed = match key.code { let changed = match key.code {
@ -160,6 +160,9 @@ impl<'a> Component for Explorer<'a> {
let key = self.tree_state.selected().to_owned(); let key = self.tree_state.selected().to_owned();
self.tree_state.close(key.as_ref()) self.tree_state.close(key.as_ref())
} }
KeyCode::Char(' ') | KeyCode::Enter => self
.tree_state
.toggle(self.tree_state.selected().to_owned()),
KeyCode::Right | KeyCode::Char('l') => self.tree_state.key_right(), KeyCode::Right | KeyCode::Char('l') => self.tree_state.key_right(),
_ => false, _ => false,
}; };

View File

@ -1,5 +1,5 @@
use crate::tui::component::{Action, Component, ComponentState, Focus}; use crate::tui::component::{Action, Component, ComponentState, Focus};
use log::trace; use log::{LevelFilter, trace};
use ratatui::buffer::Buffer; use ratatui::buffer::Buffer;
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent}; use ratatui::crossterm::event::{Event, KeyCode, KeyEvent};
use ratatui::layout::Rect; use ratatui::layout::Rect;
@ -24,7 +24,9 @@ impl Logger {
let state = TuiWidgetState::new(); let state = TuiWidgetState::new();
state.transition(TuiWidgetEvent::HideKey); state.transition(TuiWidgetEvent::HideKey);
Self { Self {
state, state: state
.set_level_for_target("arboard::platform::linux::x11", LevelFilter::Off)
.set_level_for_target("mio::poll", LevelFilter::Off),
component_state: ComponentState::default().with_help_text(concat!( component_state: ComponentState::default().with_help_text(concat!(
"Space: Hide/show logging target selector panel | (↑/k)/(↓/j): Select target |", "Space: Hide/show logging target selector panel | (↑/k)/(↓/j): Select target |",
" (←/h)/(→/l): Display level | f: Focus target | +/-: Filter level |", " (←/h)/(→/l): Display level | f: Focus target | +/-: Filter level |",