mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
add history session id to $nu (#6585)
* add history session id to $nu * get nushell to compile * update test
This commit is contained in:
@ -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"
|
||||
|
@ -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,
|
||||
|
@ -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<String> = 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<String> = vec!["history-path".into(), "home-path".into()];
|
||||
let expected: Vec<String> = vec![
|
||||
"history-path".into(),
|
||||
"history-session-id".into(),
|
||||
"home-path".into(),
|
||||
];
|
||||
|
||||
// Match results
|
||||
match_suggestions(expected, suggestions);
|
||||
|
@ -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 }
|
||||
|
@ -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,
|
||||
|
@ -87,6 +87,7 @@ pub struct EngineState {
|
||||
#[cfg(not(windows))]
|
||||
sig_quit: Option<Arc<AtomicBool>>,
|
||||
config_path: HashMap<String, PathBuf>,
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user