TUI #1
3
.cargo/config.toml
Normal file
3
.cargo/config.toml
Normal file
@ -0,0 +1,3 @@
|
||||
|
||||
[build]
|
||||
rustflags = [ "-C", "link-arg=-fuse-ld=lld", ]
|
||||
@ -6,7 +6,7 @@ use crate::tui::logger::Logger;
|
||||
use crate::tui::menu_bar::MenuBar;
|
||||
use AppComponent::AppMenuBar;
|
||||
use anyhow::{Context, Result};
|
||||
use log::{error, info, trace, warn};
|
||||
use log::{error, info, trace};
|
||||
use ratatui::DefaultTerminal;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::crossterm::event;
|
||||
|
||||
@ -24,13 +24,12 @@ impl Editor {
|
||||
"Editor"
|
||||
}
|
||||
|
||||
// TODO: You shouldnt be able to construct the editor without a path?
|
||||
pub fn new() -> Self {
|
||||
pub fn new(path: &std::path::PathBuf) -> Self {
|
||||
trace!(target:Self::id(), "Building {}", Self::id());
|
||||
Editor {
|
||||
state: EditorState::default(),
|
||||
event_handler: EditorEventHandler::default(),
|
||||
file_path: None,
|
||||
file_path: Some(path.to_owned()),
|
||||
syntax_set: SyntaxSet::load_defaults_nonewlines(),
|
||||
component_state: ComponentState::default().with_help_text(concat!(
|
||||
"CTRL+S: Save file | ALT+(←/h): Previous tab | ALT+(l/→): Next tab |",
|
||||
|
||||
@ -27,7 +27,7 @@ impl EditorTab {
|
||||
trace!(target:Self::id(), "Building EditorTab with path {path:?}");
|
||||
let tab_order = vec![path.to_string_lossy().to_string()];
|
||||
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,
|
||||
current_editor: 0,
|
||||
}
|
||||
@ -68,7 +68,7 @@ impl EditorTab {
|
||||
|
||||
let path_str = path.to_string_lossy().to_string();
|
||||
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")?;
|
||||
self.editors.insert(path_str, editor);
|
||||
self.current_editor = self.tab_order.len() - 1;
|
||||
|
||||
@ -32,7 +32,7 @@ impl<'a> Explorer<'a> {
|
||||
tree_state: TreeState::default(),
|
||||
component_state: ComponentState::default().with_help_text(concat!(
|
||||
"(↑/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)
|
||||
@ -149,7 +149,7 @@ impl<'a> Component for Explorer<'a> {
|
||||
return Ok(Action::OpenTab);
|
||||
}
|
||||
}
|
||||
return Ok(Action::Noop);
|
||||
// Otherwise fall through and handle Enter in the next match case.
|
||||
}
|
||||
|
||||
let changed = match key.code {
|
||||
@ -160,6 +160,9 @@ impl<'a> Component for Explorer<'a> {
|
||||
let key = self.tree_state.selected().to_owned();
|
||||
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(),
|
||||
_ => false,
|
||||
};
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use crate::tui::component::{Action, Component, ComponentState, Focus};
|
||||
use log::trace;
|
||||
use log::{LevelFilter, trace};
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent};
|
||||
use ratatui::layout::Rect;
|
||||
@ -24,7 +24,9 @@ impl Logger {
|
||||
let state = TuiWidgetState::new();
|
||||
state.transition(TuiWidgetEvent::HideKey);
|
||||
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!(
|
||||
"Space: Hide/show logging target selector panel | (↑/k)/(↓/j): Select target |",
|
||||
" (←/h)/(→/l): Display level | f: Focus target | +/-: Filter level |",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user