diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2020-07-06 14:07:06 +0800 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2020-07-06 14:07:06 +0800 |
commit | 0e760d733108a7e3a2153b4cee03f33ef13e5cd4 (patch) | |
tree | 6052f251bcf172bccc582d441a2d6999d939fd80 | |
parent | 40e9eb1d0e548dac3ec896d293291d1e439ba976 (diff) |
Completely rid ourselves of Termion to make backend selection possible
-rw-r--r-- | Cargo.lock | 19 | ||||
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | src/interactive/app_test/journeys_readonly.rs | 35 | ||||
-rw-r--r-- | src/interactive/app_test/journeys_with_writes.rs | 10 | ||||
-rw-r--r-- | src/interactive/app_test/utils.rs | 10 |
5 files changed, 38 insertions, 39 deletions
@@ -46,9 +46,12 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "byte-unit" -version = "4.0.6" +version = "4.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9487e11ebd3b8830053fa5c1654c8da0f2df2133d2ba8b8e1af69f53ac331d0" +checksum = "1ba58563da2fefa88ddca9db6347a1818fc224be2faf916cd4c5e210d2653f4c" +dependencies = [ + "utf8-width", +] [[package]] name = "cassowary" @@ -196,13 +199,12 @@ dependencies = [ [[package]] name = "crosstermion" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d4a0d0ebde096089c6112e28ff4c6874538792b3c792eee8ed4b8a798ca95e4" +checksum = "74ba604c40d092aa60a7a17f6cf148f2ede84f4372e2b691d49fdd89820e7846" dependencies = [ "crossterm", "flume", - "termion", "tui", "tui-react 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -242,7 +244,6 @@ dependencies = [ "petgraph", "pretty_assertions", "structopt", - "termion", "tui", "tui-react 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-segmentation", @@ -785,6 +786,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] +name = "utf8-width" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f2c54fe5e8d6907c60dc6fba532cc8529245d97ff4e26cb490cb462de114ba4" + +[[package]] name = "vec_map" version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -43,9 +43,6 @@ lto = "fat" codegen-units = 1 [dev-dependencies] -# Tests only run on linux as we use some conveniences offered by termion -crosstermion = { version = "0.1.3", default-features = false, features = ["tui-react-termion", "input-thread-flume"]} -termion = "1.5.2" pretty_assertions = "0.6.1" [workspace] diff --git a/src/interactive/app_test/journeys_readonly.rs b/src/interactive/app_test/journeys_readonly.rs index f5337ca..28d94e6 100644 --- a/src/interactive/app_test/journeys_readonly.rs +++ b/src/interactive/app_test/journeys_readonly.rs @@ -1,6 +1,6 @@ use crate::interactive::{ app_test::utils::{ - adapt, fixture_str, index_by_name, initialized_app_and_terminal_from_fixture, + fixture_str, index_by_name, initialized_app_and_terminal_from_fixture, into_keys, node_by_index, node_by_name, }, app_test::FIXTURE_PATH, @@ -9,7 +9,6 @@ use crate::interactive::{ use anyhow::Result; use pretty_assertions::assert_eq; use std::ffi::OsString; -use termion::input::TermRead; #[test] fn simple_user_journey_read_only() -> Result<()> { @@ -54,7 +53,7 @@ fn simple_user_journey_read_only() -> Result<()> { // SORTING { // when hitting the S key - app.process_events(&mut terminal, adapt(b"s".keys()))?; + app.process_events(&mut terminal, into_keys(b"s".iter()))?; assert_eq!( app.state.sorting, SortMode::SizeAscending, @@ -66,7 +65,7 @@ fn simple_user_journey_read_only() -> Result<()> { "it recomputes the cached entries" ); // when hitting the S key again - app.process_events(&mut terminal, adapt(b"s".keys()))?; + app.process_events(&mut terminal, into_keys(b"s".iter()))?; assert_eq!( app.state.sorting, SortMode::SizeDescending, @@ -82,35 +81,35 @@ fn simple_user_journey_read_only() -> Result<()> { // Entry-Navigation { // when hitting the j key - app.process_events(&mut terminal, adapt(b"j".keys()))?; + app.process_events(&mut terminal, into_keys(b"j".iter()))?; 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, adapt(b"j".keys()))?; + app.process_events(&mut terminal, into_keys(b"j".iter()))?; 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, adapt(b"k".keys()))?; + app.process_events(&mut terminal, into_keys(b"k".iter()))?; 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, adapt(b"k".keys()))?; + app.process_events(&mut terminal, into_keys(b"k".iter()))?; 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, adapt(b"o".keys()))?; + app.process_events(&mut terminal, into_keys(b"o".iter()))?; { let new_root_idx = index_by_name(&app, fixture_str(short_root)); assert_eq!( @@ -124,7 +123,7 @@ fn simple_user_journey_read_only() -> Result<()> { ); // when hitting the u key while inside a sub-directory - app.process_events(&mut terminal, adapt(b"u".keys()))?; + app.process_events(&mut terminal, into_keys(b"u".iter()))?; { assert_eq!( app.traversal.root_index, app.state.root, @@ -139,7 +138,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, adapt(b"ju".keys()))?; + app.process_events(&mut terminal, into_keys(b"ju".iter()))?; { assert_eq!( app.traversal.root_index, app.state.root, @@ -156,9 +155,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, adapt(b"k".keys()))?; + app.process_events(&mut terminal, into_keys(b"k".iter()))?; let previously_selected_index = *app.state.selected.as_ref().unwrap(); - app.process_events(&mut terminal, adapt(b"d".keys()))?; + app.process_events(&mut terminal, into_keys(b"d".iter()))?; { assert_eq!( Some(1), @@ -180,7 +179,7 @@ fn simple_user_journey_read_only() -> Result<()> { // when hitting the 'd' key again { - app.process_events(&mut terminal, adapt(b"d".keys()))?; + app.process_events(&mut terminal, into_keys(b"d".iter()))?; assert_eq!( Some(2), @@ -197,7 +196,7 @@ fn simple_user_journey_read_only() -> Result<()> { // when hitting the 'd' key once again { - app.process_events(&mut terminal, adapt(b"d".keys()))?; + app.process_events(&mut terminal, into_keys(b"d".iter()))?; assert_eq!( Some(1), @@ -214,7 +213,7 @@ fn simple_user_journey_read_only() -> Result<()> { } // when hitting the spacebar (after moving up to the first entry) { - app.process_events(&mut terminal, adapt(b"k ".keys()))?; + app.process_events(&mut terminal, into_keys(b"k ".iter()))?; assert_eq!( None, @@ -233,7 +232,7 @@ fn simple_user_journey_read_only() -> Result<()> { // Marking { // select something - app.process_events(&mut terminal, adapt(b" j ".keys()))?; + app.process_events(&mut terminal, into_keys(b" j ".iter()))?; assert_eq!( Some(false), app.window.mark_pane.as_ref().map(|p| p.has_focus()), @@ -247,7 +246,7 @@ fn simple_user_journey_read_only() -> Result<()> { ); // when advancing the selection to the marker pane - app.process_events(&mut terminal, adapt(b"\t".keys()))?; + app.process_events(&mut terminal, into_keys(b"\t".iter()))?; { 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 4efb331..83238b2 100644 --- a/src/interactive/app_test/journeys_with_writes.rs +++ b/src/interactive/app_test/journeys_with_writes.rs @@ -1,10 +1,8 @@ use crate::interactive::app_test::utils::{ - adapt, initialized_app_and_terminal_from_paths, WritableFixture, + initialized_app_and_terminal_from_paths, into_keys, WritableFixture, }; use anyhow::Result; use pretty_assertions::assert_eq; -use std::convert::TryInto; -use termion::{event::Key, input::TermRead}; #[test] fn basic_user_journey_with_deletion() -> Result<()> { @@ -12,7 +10,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, adapt(b"doddd".keys()))?; + app.process_events(&mut terminal, into_keys(b"doddd".iter()))?; assert_eq!( app.window.mark_pane.as_ref().map(|p| p.marked().len()), @@ -30,8 +28,8 @@ fn basic_user_journey_with_deletion() -> Result<()> { app.process_events( &mut terminal, vec![ - Key::Char('\t').try_into().unwrap(), - Key::Ctrl('r').try_into().unwrap(), + crosstermion::input::Key::Char('\t'), + crosstermion::input::Key::Ctrl('r'), ] .into_iter(), )?; diff --git a/src/interactive/app_test/utils.rs b/src/interactive/app_test/utils.rs index c0f1c33..3d1bbb5 100644 --- a/src/interactive/app_test/utils.rs +++ b/src/interactive/app_test/utils.rs @@ -18,12 +18,10 @@ 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 into_keys<'a>( + bytes: impl Iterator<Item = &'a u8> + 'a, +) -> impl Iterator<Item = crosstermion::input::Key> + 'a { + bytes.map(|b| crosstermion::input::Key::Char(std::char::from_u32(*b as u32).unwrap())) } pub fn node_by_index(app: &TerminalApp, id: TreeIndex) -> &EntryData { |