forked from extern/nushell
Remove the broken scrolling support (#4063)
* Remove the broken scrolling support * Remove the broken scrolling support
This commit is contained in:
parent
574c5961c8
commit
f000d5d0a1
19
Cargo.lock
generated
19
Cargo.lock
generated
@ -180,12 +180,6 @@ dependencies = [
|
|||||||
"stable_deref_trait",
|
"stable_deref_trait",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "async-std"
|
|
||||||
version = "1.10.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f8056f1455169ab86dd47b47391e4ab0cbd25410a70e9fe675544f49bafaf952"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-stream"
|
name = "async-stream"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
@ -2324,18 +2318,6 @@ dependencies = [
|
|||||||
"autocfg",
|
"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]]
|
[[package]]
|
||||||
name = "mio"
|
name = "mio"
|
||||||
version = "0.7.13"
|
version = "0.7.13"
|
||||||
@ -2611,7 +2593,6 @@ dependencies = [
|
|||||||
"md-5",
|
"md-5",
|
||||||
"meval",
|
"meval",
|
||||||
"mime",
|
"mime",
|
||||||
"minus",
|
|
||||||
"nu-ansi-term",
|
"nu-ansi-term",
|
||||||
"nu-data",
|
"nu-data",
|
||||||
"nu-engine",
|
"nu-engine",
|
||||||
|
@ -127,9 +127,6 @@ tree = ["nu_plugin_tree"]
|
|||||||
xpath = ["nu_plugin_xpath"]
|
xpath = ["nu_plugin_xpath"]
|
||||||
zip-support = ["nu-command/zip"]
|
zip-support = ["nu-command/zip"]
|
||||||
|
|
||||||
#This is disabled in extra for now
|
|
||||||
table-pager = ["nu-command/table-pager"]
|
|
||||||
|
|
||||||
#dataframe feature for nushell
|
#dataframe feature for nushell
|
||||||
dataframe = [
|
dataframe = [
|
||||||
"nu-engine/dataframe",
|
"nu-engine/dataframe",
|
||||||
|
@ -56,7 +56,6 @@ lazy_static = "1.*"
|
|||||||
log = "0.4.14"
|
log = "0.4.14"
|
||||||
md-5 = "0.9.1"
|
md-5 = "0.9.1"
|
||||||
meval = "0.2.0"
|
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-bigint = { version="0.3.1", features=["serde"] }
|
||||||
num-format = { version="0.4.0", features=["with-num-bigint"] }
|
num-format = { version="0.4.0", features=["with-num-bigint"] }
|
||||||
num-traits = "0.2.14"
|
num-traits = "0.2.14"
|
||||||
@ -117,7 +116,6 @@ clipboard-cli = ["arboard"]
|
|||||||
rustyline-support = ["rustyline"]
|
rustyline-support = ["rustyline"]
|
||||||
stable = []
|
stable = []
|
||||||
trash-support = ["trash"]
|
trash-support = ["trash"]
|
||||||
table-pager = ["minus", "crossterm"]
|
|
||||||
dataframe = ["nu-protocol/dataframe", "polars"]
|
dataframe = ["nu-protocol/dataframe", "polars"]
|
||||||
fetch = ["reqwest", "tokio"]
|
fetch = ["reqwest", "tokio"]
|
||||||
post = ["reqwest", "tokio"]
|
post = ["reqwest", "tokio"]
|
||||||
|
@ -11,13 +11,6 @@ use std::collections::HashMap;
|
|||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::time::Instant;
|
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_PAGE_SIZE: usize = 1000;
|
||||||
const STREAM_TIMEOUT_CHECK_INTERVAL: usize = 100;
|
const STREAM_TIMEOUT_CHECK_INTERVAL: usize = 100;
|
||||||
|
|
||||||
@ -186,28 +179,9 @@ fn table(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
let term_width = args.host().lock().width();
|
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 stream_data = async {
|
||||||
let finished = Arc::new(AtomicBool::new(false));
|
let finished = Arc::new(AtomicBool::new(false));
|
||||||
// we are required to clone finished, for use within the callback, otherwise we get borrow errors
|
// 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) {
|
while !finished.clone().load(Ordering::Relaxed) {
|
||||||
let mut new_input: VecDeque<Value> = VecDeque::new();
|
let mut new_input: VecDeque<Value> = VecDeque::new();
|
||||||
|
|
||||||
@ -263,161 +237,22 @@ fn table(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
if !input.is_empty() {
|
if !input.is_empty() {
|
||||||
let t = from_list(&input, &configuration, start_number, &color_hm);
|
let t = from_list(&input, &configuration, start_number, &color_hm);
|
||||||
let output = draw_table(&t, term_width, &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);
|
println!("{}", output);
|
||||||
}
|
}
|
||||||
|
|
||||||
start_number += input.len();
|
start_number += input.len();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "table-pager")]
|
|
||||||
{
|
|
||||||
let mut pager_lock = pager.lock().await;
|
|
||||||
pager_lock.data_finished();
|
|
||||||
}
|
|
||||||
|
|
||||||
Result::<_, ShellError>::Ok(())
|
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)
|
block_on(stream_data)
|
||||||
.map_err(|_| ShellError::untagged_runtime_error("Error streaming data"))?;
|
.map_err(|_| ShellError::untagged_runtime_error("Error streaming data"))?;
|
||||||
|
|
||||||
Ok(OutputStream::empty())
|
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<InputEvent> {
|
|
||||||
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::Command;
|
use super::Command;
|
||||||
|
Loading…
Reference in New Issue
Block a user