Update crossterm version to 0.26 (#8623)

# Description

This pr is a companion to https://github.com/nushell/reedline/pull/560

Fortunally, we don't need to change too much nushell code.

## Additional note about lscolor dependency
https://github.com/sharkdp/lscolors/pull/58~~
lscolor is using 0.26 for now
This commit is contained in:
WindSoilder 2023-04-15 04:14:57 +08:00 committed by GitHub
parent 71611dec4f
commit 9b35d59023
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 338 additions and 291 deletions

526
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -43,7 +43,7 @@ members = [
[dependencies] [dependencies]
chrono = { version = "0.4.23", features = ["serde"] } chrono = { version = "0.4.23", features = ["serde"] }
crossterm = "0.24.0" crossterm = "0.26"
ctrlc = "3.2.1" ctrlc = "3.2.1"
log = "0.4" log = "0.4"
miette = { version = "5.7.0", features = ["fancy-no-backtrace"] } miette = { version = "5.7.0", features = ["fancy-no-backtrace"] }
@ -65,7 +65,7 @@ nu-std = { path = "./crates/nu-std", version = "0.78.1" }
nu-utils = { path = "./crates/nu-utils", version = "0.78.1" } nu-utils = { path = "./crates/nu-utils", version = "0.78.1" }
nu-ansi-term = "0.47.0" nu-ansi-term = "0.47.0"
reedline = { version = "0.18.0", features = ["bashisms", "sqlite"] } reedline = { version = "0.18.0", features = ["bashisms", "sqlite"]}
rayon = "1.7.0" rayon = "1.7.0"
is_executable = "1.0.1" is_executable = "1.0.1"
@ -160,7 +160,7 @@ bench = false
# To use a development version of a dependency please use a global override here # To use a development version of a dependency please use a global override here
# changing versions in each sub-crate of the workspace is tedious # changing versions in each sub-crate of the workspace is tedious
[patch.crates-io] [patch.crates-io]
# reedline = { git = "https://github.com/nushell/reedline.git", branch = "main" } reedline = { git = "https://github.com/nushell/reedline.git", branch = "main" }
# nu-ansi-term = {git = "https://github.com/nushell/nu-ansi-term.git", branch = "main"} # nu-ansi-term = {git = "https://github.com/nushell/nu-ansi-term.git", branch = "main"}
# Criterion benchmarking setup # Criterion benchmarking setup

View File

@ -24,11 +24,11 @@ nu-utils = { path = "../nu-utils", version = "0.78.1" }
nu-color-config = { path = "../nu-color-config", version = "0.78.1" } nu-color-config = { path = "../nu-color-config", version = "0.78.1" }
nu-ansi-term = "0.47.0" nu-ansi-term = "0.47.0"
reedline = { version = "0.18.0", features = ["bashisms", "sqlite"] } reedline = { version = "0.18.0", features = ["bashisms", "sqlite"]}
atty = "0.2.14" atty = "0.2.14"
chrono = { default-features = false, features = ["std"], version = "0.4.23" } chrono = { default-features = false, features = ["std"], version = "0.4.23" }
crossterm = "0.24.0" crossterm = "0.26"
fancy-regex = "0.11.0" fancy-regex = "0.11.0"
fuzzy-matcher = "0.3.7" fuzzy-matcher = "0.3.7"
is_executable = "1.0.1" is_executable = "1.0.1"

View File

@ -102,7 +102,13 @@ pub fn print_events(engine_state: &EngineState) -> Result<Value, ShellError> {
// are printed, it's a good chance your terminal is eating // are printed, it's a good chance your terminal is eating
// those events. // those events.
fn print_events_helper(event: Event) -> Result<Value, ShellError> { fn print_events_helper(event: Event) -> Result<Value, ShellError> {
if let Event::Key(KeyEvent { code, modifiers }) = event { if let Event::Key(KeyEvent {
code,
modifiers,
kind,
state,
}) = event
{
match code { match code {
KeyCode::Char(c) => { KeyCode::Char(c) => {
let record = Value::Record { let record = Value::Record {
@ -111,12 +117,16 @@ fn print_events_helper(event: Event) -> Result<Value, ShellError> {
"code".into(), "code".into(),
"modifier".into(), "modifier".into(),
"flags".into(), "flags".into(),
"kind".into(),
"state".into(),
], ],
vals: vec![ vals: vec![
Value::string(format!("{c}"), Span::unknown()), Value::string(format!("{c}"), Span::unknown()),
Value::string(format!("{:#08x}", u32::from(c)), Span::unknown()), Value::string(format!("{:#08x}", u32::from(c)), Span::unknown()),
Value::string(format!("{modifiers:?}"), Span::unknown()), Value::string(format!("{modifiers:?}"), Span::unknown()),
Value::string(format!("{modifiers:#08b}"), Span::unknown()), Value::string(format!("{modifiers:#08b}"), Span::unknown()),
Value::string(format!("{kind:?}"), Span::unknown()),
Value::string(format!("{state:?}"), Span::unknown()),
], ],
span: Span::unknown(), span: Span::unknown(),
}; };

View File

@ -5,7 +5,7 @@ use crate::{
util::eval_source, util::eval_source,
NuHighlighter, NuValidator, NushellPrompt, NuHighlighter, NuValidator, NushellPrompt,
}; };
use crossterm::cursor::CursorShape; use crossterm::cursor::SetCursorStyle;
use log::{trace, warn}; use log::{trace, warn};
use miette::{IntoDiagnostic, Result}; use miette::{IntoDiagnostic, Result};
use nu_color_config::StyleComputer; use nu_color_config::StyleComputer;
@ -707,11 +707,11 @@ pub fn evaluate_repl(
Ok(()) Ok(())
} }
fn map_nucursorshape_to_cursorshape(shape: NuCursorShape) -> CursorShape { fn map_nucursorshape_to_cursorshape(shape: NuCursorShape) -> SetCursorStyle {
match shape { match shape {
NuCursorShape::Block => CursorShape::Block, NuCursorShape::Block => SetCursorStyle::SteadyBlock,
NuCursorShape::UnderScore => CursorShape::UnderScore, NuCursorShape::UnderScore => SetCursorStyle::DefaultUserShape,
NuCursorShape::Line => CursorShape::Line, NuCursorShape::Line => SetCursorStyle::BlinkingBar,
} }
} }

View File

@ -42,7 +42,7 @@ calamine = "0.19.1"
chrono = { version = "0.4.23", features = ["std", "unstable-locales"], default-features = false } chrono = { version = "0.4.23", features = ["std", "unstable-locales"], default-features = false }
chrono-humanize = "0.2.1" chrono-humanize = "0.2.1"
chrono-tz = "0.8.1" chrono-tz = "0.8.1"
crossterm = "0.24.0" crossterm = "0.26"
csv = "1.2.0" csv = "1.2.0"
dialoguer = { default-features = false, version = "0.10.3" } dialoguer = { default-features = false, version = "0.10.3" }
digest = { default-features = false, version = "0.10.0" } digest = { default-features = false, version = "0.10.0" }
@ -58,7 +58,7 @@ indicatif = "0.17.2"
is-root = "0.1.2" is-root = "0.1.2"
itertools = "0.10.0" itertools = "0.10.0"
log = "0.4.14" log = "0.4.14"
lscolors = { version = "0.12.0", features = ["crossterm"], default-features = false } lscolors = { version = "0.14", default-features = false, features = ["nu-ansi-term"] }
md5 = { package = "md-5", version = "0.10.0" } md5 = { package = "md-5", version = "0.10.0" }
miette = { version = "5.7.0", features = ["fancy-no-backtrace"] } miette = { version = "5.7.0", features = ["fancy-no-backtrace"] }
mime = "0.3.16" mime = "0.3.16"

View File

@ -248,10 +248,10 @@ fn highlight_terms_in_record(
// Get the original LS_COLORS color // Get the original LS_COLORS color
let style = ls_colors.style_for_path(val_str.clone()); let style = ls_colors.style_for_path(val_str.clone());
let ansi_style = style let ansi_style = style
.map(LsColors_Style::to_crossterm_style) .map(LsColors_Style::to_nu_ansi_term_style)
.unwrap_or_default(); .unwrap_or_default();
let ls_colored_val = ansi_style.apply(&val_str).to_string(); let ls_colored_val = ansi_style.paint(&val_str).to_string();
let ansi_term_style = style let ansi_term_style = style
.map(to_nu_ansi_term_style) .map(to_nu_ansi_term_style)

View File

@ -207,23 +207,27 @@ fn create_grid_output(
let ls_colors_style = ls_colors.style_for_path(path); let ls_colors_style = ls_colors.style_for_path(path);
let icon_style = match ls_colors_style { let icon_style = match ls_colors_style {
Some(c) => c.to_crossterm_style(), Some(c) => c.to_nu_ansi_term_style(),
None => crossterm::style::ContentStyle::default(), None => nu_ansi_term::Style::default(),
}; };
let ansi_style = ls_colors_style let ansi_style = ls_colors_style
.map(Style::to_crossterm_style) .map(Style::to_nu_ansi_term_style)
.unwrap_or_default(); .unwrap_or_default();
let item = format!("{} {}", icon_style.apply(icon), ansi_style.apply(value)); let item = format!(
"{} {}",
icon_style.paint(String::from(icon)),
ansi_style.paint(value)
);
let mut cell = Cell::from(item); let mut cell = Cell::from(item);
cell.alignment = Alignment::Left; cell.alignment = Alignment::Left;
grid.add(cell); grid.add(cell);
} else { } else {
let style = ls_colors.style_for_path(value.clone()); let style = ls_colors.style_for_path(value.clone());
let ansi_style = style.map(Style::to_crossterm_style).unwrap_or_default(); let ansi_style = style.map(Style::to_nu_ansi_term_style).unwrap_or_default();
let mut cell = Cell::from(ansi_style.apply(value).to_string()); let mut cell = Cell::from(ansi_style.paint(value).to_string());
cell.alignment = Alignment::Left; cell.alignment = Alignment::Left;
grid.add(cell); grid.add(cell);
} }

View File

@ -1845,10 +1845,7 @@ fn render_path_name(
let in_ssh_session = std::env::var("SSH_CLIENT").is_ok(); let in_ssh_session = std::env::var("SSH_CLIENT").is_ok();
let show_clickable_links = config.show_clickable_links_in_ls && !in_ssh_session && has_metadata; let show_clickable_links = config.show_clickable_links_in_ls && !in_ssh_session && has_metadata;
let ansi_style = style let ansi_style = style.map(Style::to_nu_ansi_term_style).unwrap_or_default();
.map(Style::to_crossterm_style)
// .map(ToNuAnsiStyle::to_nu_ansi_style)
.unwrap_or_default();
let full_path = PathBuf::from(stripped_path.as_ref()) let full_path = PathBuf::from(stripped_path.as_ref())
.canonicalize() .canonicalize()
@ -1860,7 +1857,7 @@ fn render_path_name(
show_clickable_links, show_clickable_links,
); );
let val = ansi_style.apply(full_path_link).to_string(); let val = ansi_style.paint(full_path_link).to_string();
Some(Value::String { val, span }) Some(Value::String { val, span })
} }

View File

@ -22,7 +22,7 @@ nu-utils = { path = "../nu-utils", version = "0.78.1" }
terminal_size = "0.2.1" terminal_size = "0.2.1"
strip-ansi-escapes = "0.1.1" strip-ansi-escapes = "0.1.1"
crossterm = "0.24.0" crossterm = "0.26"
tui = "0.19.0" tui = "0.19.0"
ansi-str = "0.7.2" ansi-str = "0.7.2"
lscolors = { version = "0.12.0", features = ["crossterm"], default-features = false } lscolors = { version = "0.14", default-features = false, features = ["nu-ansi-term"] }

View File

@ -743,9 +743,11 @@ fn handle_exit_key_event(key: &KeyEvent) -> bool {
KeyEvent { KeyEvent {
code: KeyCode::Char('d'), code: KeyCode::Char('d'),
modifiers: KeyModifiers::CONTROL, modifiers: KeyModifiers::CONTROL,
..
} | KeyEvent { } | KeyEvent {
code: KeyCode::Char('z'), code: KeyCode::Char('z'),
modifiers: KeyModifiers::CONTROL, modifiers: KeyModifiers::CONTROL,
..
} }
) )
} }

View File

@ -18,7 +18,7 @@ bench = false
[dependencies] [dependencies]
log = "0.4" log = "0.4"
lscolors = { version = "0.12.0", features = ["crossterm"], default-features = false } lscolors = { version = "0.14", default-features = false, features = ["nu-ansi-term"] }
num-format = { version = "0.4.3" } num-format = { version = "0.4.3" }
strip-ansi-escapes = "0.1.1" strip-ansi-escapes = "0.1.1"
sys-locale = "0.3.0" sys-locale = "0.3.0"