diff --git a/Cargo.lock b/Cargo.lock index 6c4dea2fd8..1afea9d53b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -180,12 +180,6 @@ dependencies = [ "stable_deref_trait", ] -[[package]] -name = "async-std" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8056f1455169ab86dd47b47391e4ab0cbd25410a70e9fe675544f49bafaf952" - [[package]] name = "async-stream" version = "0.3.2" @@ -2324,18 +2318,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "minus" -version = "3.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4157dc2cce665432eeb14110669961b4746d5fbd04b399b9af3a0edee37104c" -dependencies = [ - "async-std", - "crossterm", - "regex", - "thiserror", -] - [[package]] name = "mio" version = "0.7.13" @@ -2611,7 +2593,6 @@ dependencies = [ "md-5", "meval", "mime", - "minus", "nu-ansi-term", "nu-data", "nu-engine", diff --git a/Cargo.toml b/Cargo.toml index 89205f919e..287d94fe68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -127,9 +127,6 @@ tree = ["nu_plugin_tree"] xpath = ["nu_plugin_xpath"] zip-support = ["nu-command/zip"] -#This is disabled in extra for now -table-pager = ["nu-command/table-pager"] - #dataframe feature for nushell dataframe = [ "nu-engine/dataframe", diff --git a/crates/nu-command/Cargo.toml b/crates/nu-command/Cargo.toml index 203867db81..f14e69cf0a 100644 --- a/crates/nu-command/Cargo.toml +++ b/crates/nu-command/Cargo.toml @@ -56,7 +56,6 @@ lazy_static = "1.*" log = "0.4.14" md-5 = "0.9.1" meval = "0.2.0" -minus = { version="3.4.0", optional=true, features=["async_std_lib", "search"] } num-bigint = { version="0.3.1", features=["serde"] } num-format = { version="0.4.0", features=["with-num-bigint"] } num-traits = "0.2.14" @@ -117,7 +116,6 @@ clipboard-cli = ["arboard"] rustyline-support = ["rustyline"] stable = [] trash-support = ["trash"] -table-pager = ["minus", "crossterm"] dataframe = ["nu-protocol/dataframe", "polars"] fetch = ["reqwest", "tokio"] post = ["reqwest", "tokio"] diff --git a/crates/nu-command/src/commands/viewers/table/command.rs b/crates/nu-command/src/commands/viewers/table/command.rs index c4c712811e..6caa91c6d6 100644 --- a/crates/nu-command/src/commands/viewers/table/command.rs +++ b/crates/nu-command/src/commands/viewers/table/command.rs @@ -11,13 +11,6 @@ use std::collections::HashMap; use std::sync::atomic::Ordering; use std::time::Instant; -#[cfg(feature = "table-pager")] -use { - futures::future::join, - minus::{ExitStrategy, Pager}, - std::fmt::Write, -}; - const STREAM_PAGE_SIZE: usize = 1000; const STREAM_TIMEOUT_CHECK_INTERVAL: usize = 100; @@ -186,28 +179,9 @@ fn table(mut args: CommandArgs) -> Result { let term_width = args.host().lock().width(); - #[cfg(feature = "table-pager")] - let pager = Pager::new() - .set_exit_strategy(ExitStrategy::PagerQuit) - .set_searchable(true) - .set_page_if_havent_overflowed(false) - .set_input_handler(Box::new(input_handling::MinusInputHandler {})) - .finish(); - let stream_data = async { let finished = Arc::new(AtomicBool::new(false)); // we are required to clone finished, for use within the callback, otherwise we get borrow errors - #[cfg(feature = "table-pager")] - let finished_within_callback = finished.clone(); - #[cfg(feature = "table-pager")] - { - // This is called when the pager finishes, to indicate to the - // while loop below to finish, in case of long running InputStream consumer - // that doesn't finish by the time the user quits out of the pager - pager.lock().await.add_exit_callback(move || { - finished_within_callback.store(true, Ordering::Relaxed); - }); - } while !finished.clone().load(Ordering::Relaxed) { let mut new_input: VecDeque = VecDeque::new(); @@ -263,161 +237,22 @@ fn table(mut args: CommandArgs) -> Result { if !input.is_empty() { let t = from_list(&input, &configuration, start_number, &color_hm); let output = draw_table(&t, term_width, &color_hm); - #[cfg(feature = "table-pager")] - { - let mut pager = pager.lock().await; - writeln!(pager.lines, "{}", output).map_err(|_| { - ShellError::untagged_runtime_error("Error writing to pager") - })?; - } - #[cfg(not(feature = "table-pager"))] println!("{}", output); } start_number += input.len(); } - #[cfg(feature = "table-pager")] - { - let mut pager_lock = pager.lock().await; - pager_lock.data_finished(); - } - Result::<_, ShellError>::Ok(()) }; - #[cfg(feature = "table-pager")] - { - let (minus_result, streaming_result) = - block_on(join(minus::async_std_updating(pager.clone()), stream_data)); - minus_result.map_err(|_| ShellError::untagged_runtime_error("Error paging data"))?; - streaming_result?; - } - - #[cfg(not(feature = "table-pager"))] block_on(stream_data) .map_err(|_| ShellError::untagged_runtime_error("Error streaming data"))?; Ok(OutputStream::empty()) } -#[cfg(feature = "table-pager")] -mod input_handling { - use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind}; - use minus::{InputEvent, InputHandler, LineNumbers, SearchMode}; - pub struct MinusInputHandler; - - impl InputHandler for MinusInputHandler { - fn handle_input( - &self, - ev: Event, - upper_mark: usize, - search_mode: SearchMode, - ln: LineNumbers, - rows: usize, - ) -> Option { - match ev { - // Scroll up by one. - Event::Key(KeyEvent { - code: KeyCode::Up, - modifiers: KeyModifiers::NONE, - }) => Some(InputEvent::UpdateUpperMark(upper_mark.saturating_sub(1))), - - // Scroll down by one. - Event::Key(KeyEvent { - code: KeyCode::Down, - modifiers: KeyModifiers::NONE, - }) => Some(InputEvent::UpdateUpperMark(upper_mark.saturating_add(1))), - - // Mouse scroll up/down - Event::Mouse(MouseEvent { - kind: MouseEventKind::ScrollUp, - .. - }) => Some(InputEvent::UpdateUpperMark(upper_mark.saturating_sub(5))), - Event::Mouse(MouseEvent { - kind: MouseEventKind::ScrollDown, - .. - }) => Some(InputEvent::UpdateUpperMark(upper_mark.saturating_add(5))), - // Go to top. - Event::Key(KeyEvent { - code: KeyCode::Home, - modifiers: KeyModifiers::NONE, - }) => Some(InputEvent::UpdateUpperMark(0)), - // Go to bottom. - Event::Key(KeyEvent { - code: KeyCode::End, - modifiers: KeyModifiers::NONE, - }) => Some(InputEvent::UpdateUpperMark(usize::MAX)), - - // Page Up/Down - Event::Key(KeyEvent { - code: KeyCode::PageUp, - modifiers: KeyModifiers::NONE, - }) => Some(InputEvent::UpdateUpperMark( - upper_mark.saturating_sub(rows - 1), - )), - Event::Key(KeyEvent { - code: KeyCode::PageDown, - modifiers: KeyModifiers::NONE, - }) => Some(InputEvent::UpdateUpperMark( - upper_mark.saturating_add(rows - 1), - )), - - // Resize event from the terminal. - Event::Resize(_, height) => Some(InputEvent::UpdateRows(height as usize)), - // Switch line number display. - Event::Key(KeyEvent { - code: KeyCode::Char('l'), - modifiers: KeyModifiers::CONTROL, - }) => Some(InputEvent::UpdateLineNumber(!ln)), - // Quit. - Event::Key(KeyEvent { - code: KeyCode::Char('q'), - modifiers: KeyModifiers::NONE, - }) - | Event::Key(KeyEvent { - code: KeyCode::Char('Q'), - modifiers: KeyModifiers::SHIFT, - }) - | Event::Key(KeyEvent { - code: KeyCode::Esc, - modifiers: KeyModifiers::NONE, - }) - | Event::Key(KeyEvent { - code: KeyCode::Char('c'), - modifiers: KeyModifiers::CONTROL, - }) => Some(InputEvent::Exit), - Event::Key(KeyEvent { - code: KeyCode::Char('/'), - modifiers: KeyModifiers::NONE, - }) => Some(InputEvent::Search(SearchMode::Unknown)), - Event::Key(KeyEvent { - code: KeyCode::Down, - modifiers: KeyModifiers::CONTROL, - }) => { - if search_mode == SearchMode::Unknown { - Some(InputEvent::NextMatch) - } else { - None - } - } - Event::Key(KeyEvent { - code: KeyCode::Up, - modifiers: KeyModifiers::CONTROL, - }) => { - if search_mode == SearchMode::Unknown { - Some(InputEvent::PrevMatch) - } else { - None - } - } - _ => None, - } - } - } -} - #[cfg(test)] mod tests { use super::Command;