summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/rust.yml2
-rw-r--r--Cargo.lock252
-rw-r--r--Cargo.toml8
-rw-r--r--src/interactive/app/eventloop.rs33
-rw-r--r--src/interactive/app/handlers.rs2
-rw-r--r--src/interactive/app_test/journeys_readonly.rs36
-rw-r--r--src/interactive/app_test/journeys_with_writes.rs14
-rw-r--r--src/interactive/app_test/utils.rs8
-rw-r--r--src/interactive/widgets/help.rs2
-rw-r--r--src/interactive/widgets/mark.rs2
10 files changed, 303 insertions, 56 deletions
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index 7ffb79b..7a7515e 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -19,7 +19,7 @@ jobs:
run: cargo fmt --all -- --check
- name: clippy
run: cargo clippy
- - name: Check crate package size
+ - name: Check crate package size (feat. 'cargo diet')
run: |
curl -LSfs https://raw.githubusercontent.com/the-lean-crate/cargo-diet/master/ci/install.sh | \
sh -s -- --git the-lean-crate/cargo-diet --target x86_64-unknown-linux-musl
diff --git a/Cargo.lock b/Cargo.lock
index f6f002f..c3577fa 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6,7 +6,7 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
dependencies = [
- "winapi",
+ "winapi 0.3.9",
]
[[package]]
@@ -16,6 +16,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85bb70cc08ec97ca5450e6eba421deeea5f172c0fc61f78b5357b2a8e8be195f"
[[package]]
+name = "arc-swap"
+version = "0.4.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4d25d88fd6b8041580a654f9d0c581a047baee2b3efee13275f2fc392fc75034"
+
+[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -23,7 +29,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
- "winapi",
+ "winapi 0.3.9",
]
[[package]]
@@ -40,9 +46,9 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "byte-unit"
-version = "4.0.4"
+version = "4.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a83e250117a919810172ac4d81016eb6da74f235399ac97df3dd8846275d03b6"
+checksum = "f9487e11ebd3b8830053fa5c1654c8da0f2df2133d2ba8b8e1af69f53ac331d0"
[[package]]
name = "cassowary"
@@ -72,6 +78,15 @@ dependencies = [
]
[[package]]
+name = "cloudabi"
+version = "0.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
+dependencies = [
+ "bitflags",
+]
+
+[[package]]
name = "crossbeam"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -144,6 +159,44 @@ dependencies = [
]
[[package]]
+name = "crossterm"
+version = "0.17.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9851d20b9809e561297ec3ca85d7cba3a57507fe8d01d07ba7b52469e1c89a11"
+dependencies = [
+ "bitflags",
+ "crossterm_winapi",
+ "lazy_static",
+ "libc",
+ "mio",
+ "parking_lot",
+ "signal-hook",
+ "winapi 0.3.9",
+]
+
+[[package]]
+name = "crossterm_winapi"
+version = "0.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "057b7146d02fb50175fd7dbe5158f6097f33d02831f43b4ee8ae4ddf67b68f5c"
+dependencies = [
+ "winapi 0.3.9",
+]
+
+[[package]]
+name = "crosstermion"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6d4a0d0ebde096089c6112e28ff4c6874538792b3c792eee8ed4b8a798ca95e4"
+dependencies = [
+ "crossterm",
+ "flume",
+ "termion",
+ "tui",
+ "tui-react 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "ctor"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -166,6 +219,7 @@ dependencies = [
"anyhow",
"atty",
"byte-unit",
+ "crosstermion",
"filesize",
"flume",
"itertools",
@@ -178,7 +232,7 @@ dependencies = [
"structopt",
"termion",
"tui",
- "tui-react",
+ "tui-react 0.4.0",
"unicode-segmentation",
]
@@ -194,7 +248,7 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12d741e2415d4e2e5bd1c1d00409d1a8865a57892c2d689b504365655d237d43"
dependencies = [
- "winapi",
+ "winapi 0.3.9",
]
[[package]]
@@ -213,6 +267,22 @@ dependencies = [
]
[[package]]
+name = "fuchsia-zircon"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
+dependencies = [
+ "bitflags",
+ "fuchsia-zircon-sys",
+]
+
+[[package]]
+name = "fuchsia-zircon-sys"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
+
+[[package]]
name = "heck"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -223,9 +293,9 @@ dependencies = [
[[package]]
name = "hermit-abi"
-version = "0.1.14"
+version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b9586eedd4ce6b3c498bc3b4dd92fc9f11166aa908a914071953768066c67909"
+checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9"
dependencies = [
"libc",
]
@@ -240,6 +310,15 @@ dependencies = [
]
[[package]]
+name = "iovec"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e"
+dependencies = [
+ "libc",
+]
+
+[[package]]
name = "itertools"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -259,6 +338,16 @@ dependencies = [
]
[[package]]
+name = "kernel32-sys"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
+dependencies = [
+ "winapi 0.2.8",
+ "winapi-build",
+]
+
+[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -271,6 +360,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49"
[[package]]
+name = "lock_api"
+version = "0.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75"
+dependencies = [
+ "scopeguard",
+]
+
+[[package]]
name = "log"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -295,6 +393,48 @@ dependencies = [
]
[[package]]
+name = "mio"
+version = "0.6.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430"
+dependencies = [
+ "cfg-if",
+ "fuchsia-zircon",
+ "fuchsia-zircon-sys",
+ "iovec",
+ "kernel32-sys",
+ "libc",
+ "log",
+ "miow",
+ "net2",
+ "slab",
+ "winapi 0.2.8",
+]
+
+[[package]]
+name = "miow"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
+dependencies = [
+ "kernel32-sys",
+ "net2",
+ "winapi 0.2.8",
+ "ws2_32-sys",
+]
+
+[[package]]
+name = "net2"
+version = "0.2.34"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "winapi 0.3.9",
+]
+
+[[package]]
name = "num_cpus"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -316,7 +456,7 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c283bf0114efea9e42f1a60edea9859e8c47528eae09d01df4b29c1e489cc48"
dependencies = [
- "winapi",
+ "winapi 0.3.9",
]
[[package]]
@@ -325,7 +465,31 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53cdc5b785b7a58c5aad8216b3dfa114df64b0b06ae6e1501cef91df2fbdf8f9"
dependencies = [
- "winapi",
+ "winapi 0.3.9",
+]
+
+[[package]]
+name = "parking_lot"
+version = "0.10.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e"
+dependencies = [
+ "lock_api",
+ "parking_lot_core",
+]
+
+[[package]]
+name = "parking_lot_core"
+version = "0.7.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3"
+dependencies = [
+ "cfg-if",
+ "cloudabi",
+ "libc",
+ "redox_syscall",
+ "smallvec",
+ "winapi 0.3.9",
]
[[package]]
@@ -441,6 +605,39 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
+name = "signal-hook"
+version = "0.1.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "604508c1418b99dfe1925ca9224829bb2a8a9a04dda655cc01fcad46f4ab05ed"
+dependencies = [
+ "libc",
+ "mio",
+ "signal-hook-registry",
+]
+
+[[package]]
+name = "signal-hook-registry"
+version = "1.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "94f478ede9f64724c5d173d7bb56099ec3e2d9fc2774aac65d34b8b890405f41"
+dependencies = [
+ "arc-swap",
+ "libc",
+]
+
+[[package]]
+name = "slab"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
+
+[[package]]
+name = "smallvec"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4"
+
+[[package]]
name = "spin"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -527,6 +724,7 @@ checksum = "9533d39bef0ae8f510e8a99d78702e68d1bbf0b98a78ec9740509d287010ae1e"
dependencies = [
"bitflags",
"cassowary",
+ "crossterm",
"either",
"itertools",
"termion",
@@ -545,6 +743,18 @@ dependencies = [
]
[[package]]
+name = "tui-react"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c585aaa750085a1eeb4b78cdfdd0306e86e8fb76acc2349a787e70b5ce8413d4"
+dependencies = [
+ "log",
+ "tui",
+ "unicode-segmentation",
+ "unicode-width",
+]
+
+[[package]]
name = "unicode-segmentation"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -576,6 +786,12 @@ checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
[[package]]
name = "winapi"
+version = "0.2.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
+
+[[package]]
+name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
@@ -585,6 +801,12 @@ dependencies = [
]
[[package]]
+name = "winapi-build"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
+
+[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -595,3 +817,13 @@ name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
+
+[[package]]
+name = "ws2_32-sys"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
+dependencies = [
+ "winapi 0.2.8",
+ "winapi-build",
+]
diff --git a/Cargo.toml b/Cargo.toml
index 1c4fe5b..fec0328 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,6 +27,12 @@ filesize = "0.2.0"
flume = {version = "0.7.1", default-features = false}
anyhow = "1.0.31"
+[target.'cfg(windows)'.dependencies]
+crosstermion = { version = "0.1.3", features = ["tui-react-crossterm", "input-thread-flume"]}
+
+[target.'cfg(unix)'.dependencies]
+crosstermion = { version = "0.1.3", default-features = false, features = ["tui-react-termion", "input-thread-flume"]}
+
[[bin]]
name="dua"
path="src/main.rs"
@@ -42,6 +48,8 @@ lto = "fat"
codegen-units = 1
[dev-dependencies]
+# Tests only run on linux as we use some conveniences offered by termion
+termion = "1.5.2"
pretty_assertions = "0.6.1"
[workspace]
diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs
index c815ed4..033f6e5 100644
--- a/src/interactive/app/eventloop.rs
+++ b/src/interactive/app/eventloop.rs
@@ -5,12 +5,12 @@ use crate::interactive::{
SortMode,
};
use anyhow::Result;
+use crosstermion::input::{key_input_channel, Key};
use dua::{
traverse::{Traversal, TreeIndex},
WalkOptions, WalkResult,
};
-use std::{collections::BTreeMap, io, path::PathBuf};
-use termion::{event::Key, input::TermRead};
+use std::{collections::BTreeMap, path::PathBuf};
use tui::backend::Backend;
use tui_react::Terminal;
@@ -69,16 +69,16 @@ impl AppState {
traversal: &mut Traversal,
display: &mut DisplayOptions,
terminal: &mut Terminal<B>,
- keys: impl Iterator<Item = std::result::Result<Key, io::Error>>,
+ keys: impl Iterator<Item = Key>,
) -> Result<ProcessingResult>
where
B: Backend,
{
- use termion::event::Key::*;
+ use crosstermion::input::Key::*;
use FocussedPane::*;
self.draw(window, traversal, display.clone(), terminal)?;
- for key in keys.filter_map(Result::ok) {
+ for key in keys {
self.reset_message();
match key {
Char('?') => self.toggle_help_pane(window),
@@ -177,13 +177,13 @@ pub struct TerminalApp {
pub window: MainWindow,
}
-type KeyboardInputAndApp = (flume::Receiver<io::Result<Key>>, TerminalApp);
+type KeyboardInputAndApp = (flume::Receiver<Key>, TerminalApp);
impl TerminalApp {
pub fn process_events<B>(
&mut self,
terminal: &mut Terminal<B>,
- keys: impl Iterator<Item = std::result::Result<Key, io::Error>>,
+ keys: impl Iterator<Item = Key>,
) -> Result<WalkResult>
where
B: Backend,
@@ -213,18 +213,13 @@ impl TerminalApp {
let mut display: DisplayOptions = options.clone().into();
display.byte_vis = ByteVisualization::PercentageAndBar;
let mut window = MainWindow::default();
- let (keys_tx, keys_rx) = flume::unbounded();
- match mode {
- Interaction::None => drop(keys_tx),
- Interaction::Full => drop(std::thread::spawn(move || {
- let keys = std::io::stdin().keys();
- for key in keys {
- if keys_tx.send(key).is_err() {
- break;
- }
- }
- })),
- }
+ let keys_rx = match mode {
+ Interaction::None => {
+ let (_, keys_rx) = flume::unbounded();
+ keys_rx
+ }
+ Interaction::Full => key_input_channel(),
+ };
let fetch_buffered_key_events = || {
let mut keys = Vec::new();
diff --git a/src/interactive/app/handlers.rs b/src/interactive/app/handlers.rs
index 1758177..e940997 100644
--- a/src/interactive/app/handlers.rs
+++ b/src/interactive/app/handlers.rs
@@ -4,11 +4,11 @@ use crate::interactive::{
widgets::{HelpPane, MainWindow, MarkMode, MarkPane},
AppState, DisplayOptions, EntryDataBundle,
};
+use crosstermion::input::Key;
use dua::traverse::{Traversal, TreeIndex};
use itertools::Itertools;
use petgraph::{visit::Bfs, Direction};
use std::{fs, io, path::PathBuf};
-use termion::event::Key;
use tui::backend::Backend;
use tui_react::Terminal;
diff --git a/src/interactive/app_test/journeys_readonly.rs b/src/interactive/app_test/journeys_readonly.rs
index 595491a..f5337ca 100644
--- a/src/interactive/app_test/journeys_readonly.rs
+++ b/src/interactive/app_test/journeys_readonly.rs
@@ -1,7 +1,7 @@
use crate::interactive::{
app_test::utils::{
- fixture_str, index_by_name, initialized_app_and_terminal_from_fixture, node_by_index,
- node_by_name,
+ adapt, fixture_str, index_by_name, initialized_app_and_terminal_from_fixture,
+ node_by_index, node_by_name,
},
app_test::FIXTURE_PATH,
SortMode,
@@ -54,7 +54,7 @@ fn simple_user_journey_read_only() -> Result<()> {
// SORTING
{
// when hitting the S key
- app.process_events(&mut terminal, b"s".keys())?;
+ app.process_events(&mut terminal, adapt(b"s".keys()))?;
assert_eq!(
app.state.sorting,
SortMode::SizeAscending,
@@ -66,7 +66,7 @@ fn simple_user_journey_read_only() -> Result<()> {
"it recomputes the cached entries"
);
// when hitting the S key again
- app.process_events(&mut terminal, b"s".keys())?;
+ app.process_events(&mut terminal, adapt(b"s".keys()))?;
assert_eq!(
app.state.sorting,
SortMode::SizeDescending,
@@ -82,35 +82,35 @@ fn simple_user_journey_read_only() -> Result<()> {
// Entry-Navigation
{
// when hitting the j key
- app.process_events(&mut terminal, b"j".keys())?;
+ app.process_events(&mut terminal, adapt(b"j".keys()))?;
assert_eq!(
node_by_name(&app, fixture_str(long_root)),
node_by_index(&app, *app.state.selected.as_ref().unwrap()),
"it moves the cursor down and selects the next entry based on the current sort mode"
);
// when hitting it while there is nowhere to go
- app.process_events(&mut terminal, b"j".keys())?;
+ app.process_events(&mut terminal, adapt(b"j".keys()))?;
assert_eq!(
node_by_name(&app, fixture_str(long_root)),
node_by_index(&app, *app.state.selected.as_ref().unwrap()),
"it stays at the previous position"
);
// when hitting the k key
- app.process_events(&mut terminal, b"k".keys())?;
+ app.process_events(&mut terminal, adapt(b"k".keys()))?;
assert_eq!(
node_by_name(&app, fixture_str(short_root)),
node_by_index(&app, *app.state.selected.as_ref().unwrap()),
"it moves the cursor up and selects the next entry based on the current sort mode"
);
// when hitting the k key again
- app.process_events(&mut terminal, b"k".keys())?;
+ app.process_events(&mut terminal, adapt(b"k".keys()))?;
assert_eq!(
node_by_name(&app, fixture_str(short_root)),
node_by_index(&app, *app.state.selected.as_ref().unwrap()),
"it stays at the current cursor position as there is nowhere to go"
);
// when hitting the o key with a directory selected
- app.process_events(&mut terminal, b"o".keys())?;
+ app.process_events(&mut terminal, adapt(b"o".keys()))?;
{
let new_root_idx = index_by_name(&app, fixture_str(short_root));
assert_eq!(
@@ -124,7 +124,7 @@ fn simple_user_journey_read_only() -> Result<()> {
);
// when hitting the u key while inside a sub-directory
- app.process_events(&mut terminal, b"u".keys())?;
+ app.process_events(&mut terminal, adapt(b"u".keys()))?;
{
assert_eq!(
app.traversal.root_index, app.state.root,
@@ -139,7 +139,7 @@ fn simple_user_journey_read_only() -> Result<()> {
}
// when hitting the u key while inside of the root directory
// We are moving the cursor down just to have a non-default selection
- app.process_events(&mut terminal, b"ju".keys())?;
+ app.process_events(&mut terminal, adapt(b"ju".keys()))?;
{
assert_eq!(
app.traversal.root_index, app.state.root,
@@ -156,9 +156,9 @@ fn simple_user_journey_read_only() -> Result<()> {
// Deletion
{
// when hitting the 'd' key (also move cursor back to start)
- app.process_events(&mut terminal, b"k".keys())?;
+ app.process_events(&mut terminal, adapt(b"k".keys()))?;
let previously_selected_index = *app.state.selected.as_ref().unwrap();
- app.process_events(&mut terminal, b"d".keys())?;
+ app.process_events(&mut terminal, adapt(b"d".keys()))?;
{
assert_eq!(
Some(1),
@@ -180,7 +180,7 @@ fn simple_user_journey_read_only() -> Result<()> {
// when hitting the 'd' key again
{
- app.process_events(&mut terminal, b"d".keys())?;
+ app.process_events(&mut terminal, adapt(b"d".keys()))?;
assert_eq!(
Some(2),
@@ -197,7 +197,7 @@ fn simple_user_journey_read_only() -> Result<()> {
// when hitting the 'd' key once again
{
- app.process_events(&mut terminal, b"d".keys())?;
+ app.process_events(&mut terminal, adapt(b"d".keys()))?;
assert_eq!(
Some(1),
@@ -214,7 +214,7 @@ fn simple_user_journey_read_only() -> Result<()> {
}
// when hitting the spacebar (after moving up to the first entry)
{
- app.process_events(&mut terminal, b"k ".keys())?;
+ app.process_events(&mut terminal, adapt(b"k ".keys()))?;
assert_eq!(
None,
@@ -233,7 +233,7 @@ fn simple_user_journey_read_only() -> Result<()> {
// Marking
{
// select something
- app.process_events(&mut terminal, b" j ".keys())?;
+ app.process_events(&mut terminal, adapt(b" j ".keys()))?;
assert_eq!(
Some(false),
app.window.mark_pane.as_ref().map(|p| p.has_focus()),
@@ -247,7 +247,7 @@ fn simple_user_journey_read_only() -> Result<()> {
);
// when advancing the selection to the marker pane
- app.process_events(&mut terminal, b"\t".keys())?;
+ app.process_events(&mut terminal, adapt(b"\t".keys()))?;
{
assert_eq!(
Some(true),
diff --git a/src/interactive/app_test/journeys_with_writes.rs b/src/interactive/app_test/journeys_with_writes.rs
index 061fb4b..4efb331 100644
--- a/src/interactive/app_test/journeys_with_writes.rs
+++ b/src/interactive/app_test/journeys_with_writes.rs
@@ -1,10 +1,10 @@
use crate::interactive::app_test::utils::{
- initialized_app_and_terminal_from_paths, WritableFixture,
+ adapt, initialized_app_and_terminal_from_paths, WritableFixture,
};
use anyhow::Result;
use pretty_assertions::assert_eq;
-use termion::event::Key;
-use termion::input::TermRead;
+use std::convert::TryInto;
+use termion::{event::Key, input::TermRead};
#[test]
fn basic_user_journey_with_deletion() -> Result<()> {
@@ -12,7 +12,7 @@ fn basic_user_journey_with_deletion() -> Result<()> {
let (mut terminal, mut app) = initialized_app_and_terminal_from_paths(&[fixture.root.clone()])?;
// With a selection of items
- app.process_events(&mut terminal, b"doddd".keys())?;
+ app.process_events(&mut terminal, adapt(b"doddd".keys()))?;
assert_eq!(
app.window.mark_pane.as_ref().map(|p| p.marked().len()),
@@ -29,7 +29,11 @@ fn basic_user_journey_with_deletion() -> Result<()> {
// When selecting the marker window and pressing the combination to delete entries
app.process_events(
&mut terminal,
- vec![Ok(Key::Char('\t')), Ok(Key::Ctrl('r'))].into_iter(),
+ vec![
+ Key::Char('\t').try_into().unwrap(),
+ Key::Ctrl('r').try_into().unwrap(),
+ ]
+ .into_iter(),
)?;
assert_eq!(
app.window.mark_pane.is_none(),
diff --git a/src/interactive/app_test/utils.rs b/src/interactive/app_test/utils.rs
index 495ac01..c0f1c33 100644
--- a/src/interactive/app_test/utils.rs
+++ b/src/interactive/app_test/utils.rs
@@ -18,6 +18,14 @@ use std::{
use tui::backend::TestBackend;
use tui_react::Terminal;
+pub fn adapt(
+ keys: impl Iterator<Item = std::io::Result<termion::event::Key>>,
+) -> impl Iterator<Item = crosstermion::input::Key> {
+ use std::convert::TryFrom;
+ keys.filter_map(Result::ok)
+ .filter_map(|k| crosstermion::input::Key::try_from(k).ok())
+}
+
pub fn node_by_index(app: &TerminalApp, id: TreeIndex) -> &EntryData {
app.traversal.tree.node_weight(id).unwrap()
}
diff --git a/src/interactive/widgets/help.rs b/src/interactive/widgets/help.rs
index d14d8a6..56cfaea 100644
--- a/src/interactive/widgets/help.rs
+++ b/src/interactive/widgets/help.rs
@@ -1,9 +1,9 @@
use crate::interactive::CursorDirection;
+use crosstermion::{input::Key, input::Key::*};
use std::{
borrow::Borrow,
cell::{Cell, RefCell},
};
-use termion::{event::Key, event::Key::*};
use tui::{
buffer::Buffer,
layout::Rect,
diff --git a/src/interactive/widgets/mark.rs b/src/interactive/widgets/mark.rs
index 3c26a3a..7cc5e30 100644
--- a/src/interactive/widgets/mark.rs
+++ b/src/interactive/widgets/mark.rs
@@ -1,6 +1,7 @@
use crate::interactive::{
fit_string_graphemes_with_ellipsis, path_of, widgets::entry_color, CursorDirection,
};
+use crosstermion::{input::Key, input::Key::*};
use dua::{
traverse::{Tree, TreeIndex},
ByteFormat,
@@ -11,7 +12,6 @@ use std::{
collections::{btree_map::Entry, BTreeMap},
path::PathBuf,
};
-use termion::{event::Key, event::Key::*};
use tui::{
buffer::Buffer,
layout::{Constraint, Direction, Layout, Rect},