diff --git a/Cargo.lock b/Cargo.lock index ce5f592280..b48c322e8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4079,7 +4079,7 @@ dependencies = [ [[package]] name = "reedline" version = "0.11.0" -source = "git+https://github.com/nushell/reedline?branch=main#dc091e828590de6fd335af3f1d001ede851ac20a" +source = "git+http://github.com/nushell/reedline?rev=9a6fdd7#9a6fdd78dcf2fc472040748b5c9dc0b0f0ee31f6" dependencies = [ "chrono", "crossterm 0.24.0", diff --git a/Cargo.toml b/Cargo.toml index 7927c162ca..7b31634067 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,7 +53,9 @@ nu-system = { path = "./crates/nu-system", version = "0.68.2" } nu-table = { path = "./crates/nu-table", version = "0.68.2" } nu-term-grid = { path = "./crates/nu-term-grid", version = "0.68.2" } nu-utils = { path = "./crates/nu-utils", version = "0.68.2" } -reedline = { version = "0.11.0", features = ["bashisms", "sqlite"]} +# reedline = { version = "0.11.0", features = ["bashisms", "sqlite"]} +reedline = { git = "http://github.com/nushell/reedline", rev = "9a6fdd7", features = ["bashisms", "sqlite"]} + rayon = "1.5.1" is_executable = "1.0.1" simplelog = "0.12.0" @@ -122,5 +124,5 @@ debug = false name = "nu" path = "src/main.rs" -[patch.crates-io] -reedline = { git = "https://github.com/nushell/reedline", branch = "main" } +# [patch.crates-io] +# reedline = { git = "https://github.com/nushell/reedline", branch = "main" } diff --git a/crates/nu-cli/Cargo.toml b/crates/nu-cli/Cargo.toml index cb2f44ab16..39680f2dbd 100644 --- a/crates/nu-cli/Cargo.toml +++ b/crates/nu-cli/Cargo.toml @@ -20,7 +20,8 @@ nu-protocol = { path = "../nu-protocol", version = "0.68.2" } nu-utils = { path = "../nu-utils", version = "0.68.2" } nu-ansi-term = "0.46.0" nu-color-config = { path = "../nu-color-config", version = "0.68.2" } -reedline = { version = "0.11.0", features = ["bashisms", "sqlite"]} +# reedline = { version = "0.11.0", features = ["bashisms", "sqlite"]} +reedline = { git = "http://github.com/nushell/reedline", rev = "9a6fdd7", features = ["bashisms", "sqlite"]} atty = "0.2.14" chrono = "0.4.21" diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index 46a2a9b4f2..526a456a9c 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -19,8 +19,11 @@ use nu_protocol::{ Spanned, Type, Value, VarId, }; use reedline::{DefaultHinter, EditCommand, Emacs, SqliteBackedHistory, Vi}; -use std::io::{self, Write}; -use std::{sync::atomic::Ordering, time::Instant}; +use std::{ + io::{self, Write}, + sync::atomic::Ordering, + time::Instant, +}; use strip_ansi_escapes::strip; use sysinfo::SystemExt; @@ -98,14 +101,21 @@ pub fn evaluate_repl( ); } - // Get the config once for the history `max_history_size` - // Updating that will not be possible in one session - let config = engine_state.get_config(); - if is_perf_true { info!("setup reedline {}:{}:{}", file!(), line!(), column!()); } + let mut line_editor = Reedline::create(); + + // Now that reedline is created, get the history session id and store it in engine_state + let hist_sesh = match line_editor.get_history_session_id() { + Some(id) => i64::from(id), + None => 0, + }; + engine_state.history_session_id = hist_sesh; + + let config = engine_state.get_config(); + let history_path = crate::config_files::get_history_path( nushell_path, engine_state.config.history_file_format, diff --git a/crates/nu-cli/tests/completions.rs b/crates/nu-cli/tests/completions.rs index 10c88c17b6..2e27a4ab39 100644 --- a/crates/nu-cli/tests/completions.rs +++ b/crates/nu-cli/tests/completions.rs @@ -469,12 +469,13 @@ fn variables_completions() { // Test completions for $nu let suggestions = completer.complete("$nu.", 4); - assert_eq!(9, suggestions.len()); + assert_eq!(10, suggestions.len()); let expected: Vec = vec![ "config-path".into(), "env-path".into(), "history-path".into(), + "history-session-id".into(), "home-path".into(), "loginshell-path".into(), "os-info".into(), @@ -489,9 +490,13 @@ fn variables_completions() { // Test completions for $nu.h (filter) let suggestions = completer.complete("$nu.h", 5); - assert_eq!(2, suggestions.len()); + assert_eq!(3, suggestions.len()); - let expected: Vec = vec!["history-path".into(), "home-path".into()]; + let expected: Vec = vec![ + "history-path".into(), + "history-session-id".into(), + "home-path".into(), + ]; // Match results match_suggestions(expected, suggestions); diff --git a/crates/nu-command/Cargo.toml b/crates/nu-command/Cargo.toml index 29a63c44ef..db4b814606 100644 --- a/crates/nu-command/Cargo.toml +++ b/crates/nu-command/Cargo.toml @@ -87,7 +87,8 @@ unicode-segmentation = "1.8.0" url = "2.2.1" uuid = { version = "1.1.2", features = ["v4"] } which = { version = "4.3.0", optional = true } -reedline = { version = "0.11.0", features = ["bashisms", "sqlite"]} +# reedline = { version = "0.11.0", features = ["bashisms", "sqlite"]} +reedline = { git = "http://github.com/nushell/reedline", rev = "9a6fdd7", features = ["bashisms", "sqlite"]} wax = { version = "0.5.0", features = ["diagnostics"] } rusqlite = { version = "0.28.0", features = ["bundled"], optional = true } sqlparser = { version = "0.23.0", features = ["serde"], optional = true } diff --git a/crates/nu-engine/src/eval.rs b/crates/nu-engine/src/eval.rs index c53da6af3f..a3174d7dd0 100644 --- a/crates/nu-engine/src/eval.rs +++ b/crates/nu-engine/src/eval.rs @@ -1434,6 +1434,9 @@ pub fn eval_variable( output_cols.push("os-info".into()); output_vals.push(os_record); + output_cols.push("history-session-id".into()); + output_vals.push(Value::int(engine_state.history_session_id, span)); + Ok(Value::Record { cols: output_cols, vals: output_vals, diff --git a/crates/nu-protocol/src/engine/engine_state.rs b/crates/nu-protocol/src/engine/engine_state.rs index 11f7d5cd97..0cf719ad0b 100644 --- a/crates/nu-protocol/src/engine/engine_state.rs +++ b/crates/nu-protocol/src/engine/engine_state.rs @@ -87,6 +87,7 @@ pub struct EngineState { #[cfg(not(windows))] sig_quit: Option>, config_path: HashMap, + pub history_session_id: i64, } pub const NU_VARIABLE_ID: usize = 0; @@ -127,6 +128,7 @@ impl EngineState { #[cfg(not(windows))] sig_quit: None, config_path: HashMap::new(), + history_session_id: 0, } }