From 047f641b097362a7657e8d81091b0dcc1605b8b3 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Thu, 22 Feb 2024 07:55:11 -0600 Subject: [PATCH] update to latest nushell 0.90.2 --- Cargo.toml | 4 ++-- src/edit.rs | 2 +- src/main.rs | 1 + src/navigation.rs | 12 +++++++----- src/nu/value.rs | 45 +++++++++++++++++++++++++++++++-------------- src/ui.rs | 9 +++++---- 6 files changed, 47 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a155297..f9fa51d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,8 +6,8 @@ name = "nu_plugin_explore" anyhow = "1.0.73" console = "0.15.7" crossterm = "0.27.0" -nu-plugin = "0.89.0" -nu-protocol = { version = "0.89.0", features = ["plugin"] } +nu-plugin = { version = "0.90.2", path = "../nushell/crates/nu-plugin" } +nu-protocol = { version = "0.90.2", path = "../nushell/crates/nu-protocol", features = ["plugin"] } ratatui = "0.22.0" url = "2.4.0" diff --git a/src/edit.rs b/src/edit.rs index a4094d4..3b541e4 100755 --- a/src/edit.rs +++ b/src/edit.rs @@ -37,7 +37,7 @@ impl Editor { pub(super) fn from_value(value: &Value) -> Self { Self { - buffer: value.into_string(" ", &nu_protocol::Config::default()), + buffer: value.to_abbreviated_string(&nu_protocol::Config::default()), cursor_position: (0, 0), width: 0, } diff --git a/src/main.rs b/src/main.rs index 98f7619..b6458aa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,6 +33,7 @@ impl Plugin for Explore { fn run( &mut self, name: &str, + _config: &Option, call: &EvaluatedCall, input: &Value, ) -> Result { diff --git a/src/navigation.rs b/src/navigation.rs index c4dc5e0..4b65ed9 100644 --- a/src/navigation.rs +++ b/src/navigation.rs @@ -19,7 +19,7 @@ pub enum Direction { /// return, you'd be able to scroll the list without seeing it as a whole... confusing, right? /// - cycle the list indices or the record column names => the index / column will wrap around /// -/// > :bulb: **Note** +/// > :bulb: **Note** /// > this function will only modify the last element of the state's *cell path* either by /// > - not doing anything /// > - poping the last element to know where we are and then pushing back the new element @@ -47,7 +47,8 @@ pub(super) fn go_up_or_down_in_data(app: &mut App, direction: Direction) { panic!( "unexpected error when following {:?} in {}", app.position.members, - app.value.into_string(" ", &nu_protocol::Config::default()) + app.value + .to_abbreviated_string(&nu_protocol::Config::default()) ) }); @@ -103,7 +104,7 @@ pub(super) fn go_up_or_down_in_data(app: &mut App, direction: Direction) { /// go one level deeper in the data /// -/// > :bulb: **Note** +/// > :bulb: **Note** /// > this function will /// > - push a new *cell path* member to the state if there is more depth ahead /// > - mark the state as *at the bottom* if the value at the new depth is of a simple type @@ -116,7 +117,8 @@ pub(super) fn go_deeper_in_data(app: &mut App) { panic!( "unexpected error when following {:?} in {}", app.position.members, - app.value.into_string(" ", &nu_protocol::Config::default()) + app.value + .to_abbreviated_string(&nu_protocol::Config::default()) ) }); @@ -137,7 +139,7 @@ pub(super) fn go_deeper_in_data(app: &mut App) { /// pop one level of depth from the data /// -/// > :bulb: **Note** +/// > :bulb: **Note** /// > - the state is always marked as *not at the bottom* /// > - the state *cell path* can have it's last member popped if possible pub(super) fn go_back_in_data(app: &mut App) { diff --git a/src/nu/value.rs b/src/nu/value.rs index 4629839..8977525 100644 --- a/src/nu/value.rs +++ b/src/nu/value.rs @@ -59,7 +59,10 @@ pub(crate) fn mutate_value_cell(value: &Value, cell_path: &CellPath, cell: &Valu }) .collect(); - Value::record(Record::from_raw_cols_vals(cols, vals), Span::unknown()) + match Record::from_raw_cols_vals(cols, vals, Span::unknown(), Span::unknown()) { + Ok(rec) => Value::record(rec, Span::unknown()), + Err(err) => Value::error(err, Span::unknown()), + } } _ => cell.clone(), } @@ -171,7 +174,7 @@ pub(crate) fn transpose(value: &Value) -> Value { if first_row.len() == 2 { let cols: Vec = value_rows .iter() - .map(|row| row.get_data_by_key("1").unwrap().as_string().unwrap()) + .map(|row| row.get_data_by_key("1").unwrap().into_string().unwrap()) .collect(); let vals: Vec = value_rows @@ -179,25 +182,37 @@ pub(crate) fn transpose(value: &Value) -> Value { .map(|row| row.get_data_by_key("2").unwrap()) .collect(); - return Value::record(Record::from_raw_cols_vals(cols, vals), Span::unknown()); + return match Record::from_raw_cols_vals( + cols, + vals, + Span::unknown(), + Span::unknown(), + ) { + Ok(rec) => Value::record(rec, Span::unknown()), + Err(err) => Value::error(err, Span::unknown()), + }; } else { let mut rows = vec![]; let cols: Vec = value_rows .iter() - .map(|v| v.get_data_by_key("1").unwrap().as_string().unwrap()) + .map(|v| v.get_data_by_key("1").unwrap().into_string().unwrap()) .collect(); for i in 0..(first_row.len() - 1) { - rows.push(Value::record( - Record::from_raw_cols_vals( + rows.push( + match Record::from_raw_cols_vals( cols.clone(), value_rows .iter() .map(|v| v.get_data_by_key(&format!("{}", i + 2)).unwrap()) .collect(), - ), - Span::unknown(), - )); + Span::unknown(), + Span::unknown(), + ) { + Ok(rec) => Value::record(rec, Span::unknown()), + Err(err) => Value::error(err, Span::unknown()), + }, + ); } return Value::list(rows, Span::unknown()); @@ -214,10 +229,12 @@ pub(crate) fn transpose(value: &Value) -> Value { vs.push(v.get_data_by_key(col).unwrap()); } - rows.push(Value::record( - Record::from_raw_cols_vals(cols, vs), - Span::unknown(), - )); + rows.push( + match Record::from_raw_cols_vals(cols, vs, Span::unknown(), Span::unknown()) { + Ok(rec) => Value::record(rec, Span::unknown()), + Err(err) => Value::error(err, Span::unknown()), + }, + ); } return Value::list(rows, Span::unknown()); @@ -252,7 +269,7 @@ mod tests { use nu_protocol::{ast::CellPath, record, Config, Value}; fn default_value_repr(value: &Value) -> String { - value.into_string(" ", &Config::default()) + value.to_abbreviated_string(&Config::default()) } #[test] diff --git a/src/ui.rs b/src/ui.rs index 282ffc3..d141fda 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -138,7 +138,7 @@ fn repr_simple_value(value: &Value) -> DataRowRepr { name: None, shape, // FIXME: use a real config - data: value.into_string(" ", &nu_protocol::Config::default()), + data: value.to_abbreviated_string(&nu_protocol::Config::default()), } } @@ -252,7 +252,8 @@ fn render_data(frame: &mut Frame<'_, B>, app: &App, config: &Config) panic!( "unexpected error when following {:?} in {}", app.position.members, - app.value.into_string(" ", &nu_protocol::Config::default()) + app.value + .to_abbreviated_string(&nu_protocol::Config::default()) ) }); @@ -469,7 +470,7 @@ fn render_data(frame: &mut Frame<'_, B>, app: &App, config: &Config) /// this line can be removed through config, see [`crate::config::Config::show_cell_path`] /// /// # Examples -/// > :bulb: **Note** +/// > :bulb: **Note** /// > the `...` are here to signify that the bar might be truncated and the `||` at the start and /// the end of the lines are just to represent the borders of the terminal but will not appear in /// the TUI. @@ -513,7 +514,7 @@ fn render_cell_path(frame: &mut Frame<'_, B>, app: &App) { /// the color depending of the mode is completely configurable! /// /// # Examples -/// > :bulb: **Note** +/// > :bulb: **Note** /// > - the `...` are here to signify that the bar might be truncated and the `||` at the start and /// the end of the lines are just to represent the borders of the terminal but will not appear in /// the TUI.