Skip to content

Commit

Permalink
upgrade to latest verison of tui-crates and native crossterm events. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Dec 26, 2023
1 parent 46fece5 commit 90b65d5
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 134 deletions.
88 changes: 32 additions & 56 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ include = ["src/**/*", "Cargo.*", "LICENSE", "README.md", "CHANGELOG.md", "!**/t

[features]
default = ["tui-crossplatform", "trash-move"]
tui-unix = ["crosstermion/tui-react-termion", "tui-shared"]
tui-crossplatform = ["crosstermion/tui-react-crossterm", "tui-shared"]

tui-shared = ["tui", "tui-react", "open", "unicode-segmentation", "unicode-width"]
Expand All @@ -33,9 +32,9 @@ chrono = { version = "0.4.31", default-features = false, features = ["std"] }
# 'tui' related
unicode-segmentation = { version = "1.3.0", optional = true }
unicode-width = { version = "0.1.5", optional = true }
crosstermion = { version = "0.12.0", default-features = false, optional = true }
tui = { package = "ratatui", version = "0.24.0", optional = true, default-features = false }
tui-react = { version = "0.21.0", optional = true }
crosstermion = { version = "0.13.0", default-features = false, optional = true }
tui = { package = "ratatui", version = "0.25.0", optional = true, default-features = false }
tui-react = { version = "0.22.0", optional = true }
open = { version = "5.0", optional = true }
wild = "2.0.4"
owo-colors = "4.0.0"
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ check:## run cargo-check with various features
cargo check --all
cargo check --all-features
cargo check --no-default-features
cargo check --no-default-features --features tui-unix
cargo check --no-default-features --features tui-crossplatform
cargo check --no-default-features --features trash-move

Expand Down
56 changes: 32 additions & 24 deletions src/interactive/app/eventloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::interactive::{
SortMode,
};
use anyhow::Result;
use crosstermion::input::{input_channel, Event, Key};
use crosstermion::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use crosstermion::input::{input_channel, Event};
use dua::{
traverse::{EntryData, Traversal},
WalkOptions, WalkResult,
Expand Down Expand Up @@ -104,7 +105,7 @@ impl AppState {
where
B: Backend,
{
use crosstermion::input::Key::*;
use crosstermion::crossterm::event::KeyCode::*;
use FocussedPane::*;

{
Expand All @@ -115,28 +116,29 @@ impl AppState {
for event in events {
let key = match event {
Event::Key(key) => key,
Event::Resize(_, _) => Alt('\r'),
Event::Resize(_, _) => refresh_key(),
_ => continue,
};

self.reset_message();

let glob_focussed = self.focussed == Glob;
let mut tree_view = self.tree_view(traversal);
let mut handled = true;
match key {
match key.code {
Esc => {
if let Some(value) = self.handle_quit(&mut tree_view, window) {
return value;
}
}
Char('\t') => {
Tab => {
self.cycle_focus(window);
}
Char('/') if !glob_focussed => {
self.toggle_glob_search(window);
}
Char('?') if !glob_focussed => self.toggle_help_pane(window),
Ctrl('c') if !glob_focussed => {
Char('c') if key.modifiers.contains(KeyModifiers::CONTROL) && !glob_focussed => {
return Ok(ProcessingResult::ExitRequested(WalkResult {
num_errors: tree_view.traversal.io_errors,
}))
Expand Down Expand Up @@ -165,27 +167,19 @@ impl AppState {
}
Glob => {
let glob_pane = window.glob_pane.as_mut().expect("glob pane");
match key {
Char('\n') => {
self.search_glob_pattern(&mut tree_view, &glob_pane.input)
}
match key.code {
Enter => self.search_glob_pattern(&mut tree_view, &glob_pane.input),
_ => glob_pane.process_events(key),
}
}
Main => match key {
Main => match key.code {
Char('O') => self.open_that(&tree_view),
Char(' ') => self.mark_entry(
CursorMode::KeepPosition,
MarkEntryMode::Toggle,
window,
&tree_view,
),
Char('d') => self.mark_entry(
CursorMode::Advance,
MarkEntryMode::Toggle,
window,
&tree_view,
),
Char('x') => self.mark_entry(
CursorMode::Advance,
MarkEntryMode::MarkForDeletion,
Expand All @@ -195,24 +189,34 @@ impl AppState {
Char('a') => {
self.mark_all_entries(MarkEntryMode::Toggle, window, &tree_view)
}
Char('u') | Char('h') | Backspace | Left => {
self.exit_node_with_traversal(&tree_view)
}
Char('o') | Char('l') | Char('\n') | Right => {
Char('o') | Char('l') | Enter | Right => {
self.enter_node_with_traversal(&tree_view)
}
Char('H') | Home => self.change_entry_selection(CursorDirection::ToTop),
Char('G') | End => self.change_entry_selection(CursorDirection::ToBottom),
Ctrl('u') | PageUp => self.change_entry_selection(CursorDirection::PageUp),
PageUp => self.change_entry_selection(CursorDirection::PageUp),
Char('u') if key.modifiers.contains(KeyModifiers::CONTROL) => {
self.change_entry_selection(CursorDirection::PageUp)
}
Char('k') | Up => self.change_entry_selection(CursorDirection::Up),
Char('j') | Down => self.change_entry_selection(CursorDirection::Down),
Ctrl('d') | PageDown => {
PageDown => self.change_entry_selection(CursorDirection::PageDown),
Char('d') if key.modifiers.contains(KeyModifiers::CONTROL) => {
self.change_entry_selection(CursorDirection::PageDown)
}
Char('s') => self.cycle_sorting(&tree_view),
Char('m') => self.cycle_mtime_sorting(&tree_view),
Char('c') => self.cycle_count_sorting(&tree_view),
Char('g') => display.byte_vis.cycle(),
Char('d') => self.mark_entry(
CursorMode::Advance,
MarkEntryMode::Toggle,
window,
&tree_view,
),
Char('u') | Char('h') | Backspace | Left => {
self.exit_node_with_traversal(&tree_view)
}
_ => {}
},
};
Expand Down Expand Up @@ -353,7 +357,7 @@ impl TerminalApp {
&mut self.traversal,
&mut self.display,
terminal,
std::iter::once(Event::Key(Key::Alt('\r'))),
std::iter::once(Event::Key(refresh_key())),
)
.ok();
}
Expand Down Expand Up @@ -482,3 +486,7 @@ pub enum Interaction {
#[allow(dead_code)]
None,
}

fn refresh_key() -> KeyEvent {
KeyEvent::new(KeyCode::Char('\r'), KeyModifiers::ALT)
}
Loading

0 comments on commit 90b65d5

Please sign in to comment.