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]
chrono = { version = "0.4.23", features = ["serde"] }
crossterm = "0.24.0"
crossterm = "0.26"
ctrlc = "3.2.1"
log = "0.4"
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-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"
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
# changing versions in each sub-crate of the workspace is tedious
[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"}
# 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-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"
chrono = { default-features = false, features = ["std"], version = "0.4.23" }
crossterm = "0.24.0"
crossterm = "0.26"
fancy-regex = "0.11.0"
fuzzy-matcher = "0.3.7"
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
// those events.
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 {
KeyCode::Char(c) => {
let record = Value::Record {
@ -111,12 +117,16 @@ fn print_events_helper(event: Event) -> Result<Value, ShellError> {
"code".into(),
"modifier".into(),
"flags".into(),
"kind".into(),
"state".into(),
],
vals: vec![
Value::string(format!("{c}"), Span::unknown()),
Value::string(format!("{:#08x}", u32::from(c)), Span::unknown()),
Value::string(format!("{modifiers:?}"), Span::unknown()),
Value::string(format!("{modifiers:#08b}"), Span::unknown()),
Value::string(format!("{kind:?}"), Span::unknown()),
Value::string(format!("{state:?}"), Span::unknown()),
],
span: Span::unknown(),
};

View File

@ -5,7 +5,7 @@ use crate::{
util::eval_source,
NuHighlighter, NuValidator, NushellPrompt,
};
use crossterm::cursor::CursorShape;
use crossterm::cursor::SetCursorStyle;
use log::{trace, warn};
use miette::{IntoDiagnostic, Result};
use nu_color_config::StyleComputer;
@ -707,11 +707,11 @@ pub fn evaluate_repl(
Ok(())
}
fn map_nucursorshape_to_cursorshape(shape: NuCursorShape) -> CursorShape {
fn map_nucursorshape_to_cursorshape(shape: NuCursorShape) -> SetCursorStyle {
match shape {
NuCursorShape::Block => CursorShape::Block,
NuCursorShape::UnderScore => CursorShape::UnderScore,
NuCursorShape::Line => CursorShape::Line,
NuCursorShape::Block => SetCursorStyle::SteadyBlock,
NuCursorShape::UnderScore => SetCursorStyle::DefaultUserShape,
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-humanize = "0.2.1"
chrono-tz = "0.8.1"
crossterm = "0.24.0"
crossterm = "0.26"
csv = "1.2.0"
dialoguer = { default-features = false, version = "0.10.3" }
digest = { default-features = false, version = "0.10.0" }
@ -58,7 +58,7 @@ indicatif = "0.17.2"
is-root = "0.1.2"
itertools = "0.10.0"
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" }
miette = { version = "5.7.0", features = ["fancy-no-backtrace"] }
mime = "0.3.16"

View File

@ -248,10 +248,10 @@ fn highlight_terms_in_record(
// Get the original LS_COLORS color
let style = ls_colors.style_for_path(val_str.clone());
let ansi_style = style
.map(LsColors_Style::to_crossterm_style)
.map(LsColors_Style::to_nu_ansi_term_style)
.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
.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 icon_style = match ls_colors_style {
Some(c) => c.to_crossterm_style(),
None => crossterm::style::ContentStyle::default(),
Some(c) => c.to_nu_ansi_term_style(),
None => nu_ansi_term::Style::default(),
};
let ansi_style = ls_colors_style
.map(Style::to_crossterm_style)
.map(Style::to_nu_ansi_term_style)
.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);
cell.alignment = Alignment::Left;
grid.add(cell);
} else {
let style = ls_colors.style_for_path(value.clone());
let ansi_style = style.map(Style::to_crossterm_style).unwrap_or_default();
let mut cell = Cell::from(ansi_style.apply(value).to_string());
let ansi_style = style.map(Style::to_nu_ansi_term_style).unwrap_or_default();
let mut cell = Cell::from(ansi_style.paint(value).to_string());
cell.alignment = Alignment::Left;
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 show_clickable_links = config.show_clickable_links_in_ls && !in_ssh_session && has_metadata;
let ansi_style = style
.map(Style::to_crossterm_style)
// .map(ToNuAnsiStyle::to_nu_ansi_style)
.unwrap_or_default();
let ansi_style = style.map(Style::to_nu_ansi_term_style).unwrap_or_default();
let full_path = PathBuf::from(stripped_path.as_ref())
.canonicalize()
@ -1860,7 +1857,7 @@ fn render_path_name(
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 })
}

View File

@ -539,16 +539,16 @@ fn test_expand_big_0() {
repository = "https://github.com/nushell/nushell"
rust-version = "1.60"
version = "0.74.1"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[package.metadata.binstall]
pkg-url = "{ repo }/releases/download/{ version }/{ name }-{ version }-{ target }.{ archive-format }"
pkg-fmt = "tgz"
[package.metadata.binstall.overrides.x86_64-pc-windows-msvc]
pkg-fmt = "zip"
[workspace]
members = [
"crates/nu-cli",
@ -565,7 +565,7 @@ fn test_expand_big_0() {
"crates/nu_plugin_custom_values",
"crates/nu-utils",
]
[dependencies]
chrono = { version = "0.4.23", features = ["serde"] }
crossterm = "0.24.0"
@ -576,25 +576,25 @@ fn test_expand_big_0() {
nu-cli = { path = "./crates/nu-cli", version = "0.74.1" }
nu-engine = { path = "./crates/nu-engine", version = "0.74.1" }
reedline = { version = "0.14.0", features = ["bashisms", "sqlite"] }
rayon = "1.6.1"
is_executable = "1.0.1"
simplelog = "0.12.0"
time = "0.3.12"
[target.'cfg(not(target_os = "windows"))'.dependencies]
# Our dependencies don't use OpenSSL on Windows
openssl = { version = "0.10.38", features = ["vendored"], optional = true }
signal-hook = { version = "0.3.14", default-features = false }
[target.'cfg(windows)'.build-dependencies]
winres = "0.1"
[target.'cfg(target_family = "unix")'.dependencies]
nix = { version = "0.25", default-features = false, features = ["signal", "process", "fs", "term"] }
atty = "0.2"
[dev-dependencies]
nu-test-support = { path = "./crates/nu-test-support", version = "0.74.1" }
tempfile = "3.2.0"
@ -605,7 +605,7 @@ fn test_expand_big_0() {
hamcrest2 = "0.3.0"
rstest = { version = "0.15.0", default-features = false }
itertools = "0.10.3"
[features]
plugin = [
"nu-plugin",
@ -620,10 +620,10 @@ fn test_expand_big_0() {
default = ["plugin", "which-support", "trash-support", "sqlite"]
stable = ["default"]
wasi = []
# Enable to statically link OpenSSL; otherwise the system version will be used. Not enabled by default because it takes a while to build
static-link-openssl = ["dep:openssl"]
# Stable (Default)
which-support = ["nu-command/which-support"]
trash-support = ["nu-command/trash-support"]
@ -632,12 +632,12 @@ fn test_expand_big_0() {
[[bin]]
name = "nu"
path = "src/main.rs"
# 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
[patch.crates-io]
reedline = { git = "https://github.com/nushell/reedline.git", branch = "main" }
# Criterion benchmarking setup
# Run all benchmarks with `cargo bench`
# Run individual benchmarks like `cargo bench -- <regex>` e.g. `cargo bench -- parse`

View File

@ -22,7 +22,7 @@ nu-utils = { path = "../nu-utils", version = "0.78.1" }
terminal_size = "0.2.1"
strip-ansi-escapes = "0.1.1"
crossterm = "0.24.0"
crossterm = "0.26"
tui = "0.19.0"
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 {
code: KeyCode::Char('d'),
modifiers: KeyModifiers::CONTROL,
..
} | KeyEvent {
code: KeyCode::Char('z'),
modifiers: KeyModifiers::CONTROL,
..
}
)
}

View File

@ -18,7 +18,7 @@ bench = false
[dependencies]
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" }
strip-ansi-escapes = "0.1.1"
sys-locale = "0.3.0"