From 942bb8031dff1a24111b75d35767d9fa2adc73df Mon Sep 17 00:00:00 2001 From: Antoine Stevan <44101798+amtoine@users.noreply.github.com> Date: Wed, 6 Mar 2024 22:37:07 +0100 Subject: [PATCH] bump Nushell and the plugin (#37) as per title --- Cargo.toml | 6 +++--- src/config/mod.rs | 6 ++++-- src/edit.rs | 2 +- src/handler.rs | 29 ++++++++++++++--------------- src/navigation.rs | 6 ++++-- src/nu/value.rs | 30 ++++++++++++------------------ src/ui.rs | 5 +++-- 7 files changed, 41 insertions(+), 43 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5b87c9d..849aec1 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.90.1" -nu-protocol = { version = "0.90.1", features = ["plugin"] } +nu-plugin = "0.91.0" +nu-protocol = { version = "0.91.0", features = ["plugin"] } ratatui = "0.26.1" url = "2.4.0" @@ -17,4 +17,4 @@ bench = false [package] edition = "2021" name = "nu_plugin_explore" -version = "0.1.2" +version = "0.2.0" diff --git a/src/config/mod.rs b/src/config/mod.rs index 39b76f4..f1c4d82 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -657,8 +657,10 @@ mod tests { let value = Value::test_record(record! { "show_cell_path" => Value::test_bool(false) }); - let mut expected = Config::default(); - expected.show_cell_path = false; + let expected = Config { + show_cell_path: false, + ..Default::default() + }; assert_eq!(Config::from_value(value), Ok(expected)); let value = Value::test_record(record! { diff --git a/src/edit.rs b/src/edit.rs index 50c3914..170d01e 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_expanded_string(" ", &nu_protocol::Config::default()), cursor_position: (0, 0), width: 0, } diff --git a/src/handler.rs b/src/handler.rs index a5664d5..6637078 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -402,7 +402,7 @@ mod tests { let mode = app.mode.clone(); let result = - handle_key_events(KeyEvent::new(key, KeyModifiers::empty()), &mut app, &config) + handle_key_events(KeyEvent::new(key, KeyModifiers::empty()), &mut app, config) .unwrap(); if exit { @@ -438,14 +438,15 @@ mod tests { mode ), }, - None => match result { - TransitionResult::Return(_) => panic!( - "did NOT expect output data after pressing {} in {} mode", - repr_keycode(&key), - mode - ), - _ => {} - }, + None => { + if let TransitionResult::Return(_) = result { + panic!( + "did NOT expect output data after pressing {} in {} mode", + repr_keycode(&key), + mode + ) + } + } } } } @@ -555,13 +556,11 @@ mod tests { for (key, cell_path) in transitions { let expected = to_path_member_vec(&cell_path); - match handle_key_events(KeyEvent::new(key, KeyModifiers::empty()), &mut app, &config) - .unwrap() + if let TransitionResult::Mutate(cell, path) = + handle_key_events(KeyEvent::new(key, KeyModifiers::empty()), &mut app, &config) + .unwrap() { - TransitionResult::Mutate(cell, path) => { - app.value = crate::nu::value::mutate_value_cell(&app.value, &path, &cell) - } - _ => {} + app.value = crate::nu::value::mutate_value_cell(&app.value, &path, &cell) } assert!( diff --git a/src/navigation.rs b/src/navigation.rs index c4dc5e0..08f70d5 100644 --- a/src/navigation.rs +++ b/src/navigation.rs @@ -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_expanded_string(" ", &nu_protocol::Config::default()) ) }); @@ -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_expanded_string(" ", &nu_protocol::Config::default()) ) }); diff --git a/src/nu/value.rs b/src/nu/value.rs index 6948d2d..19ae919 100644 --- a/src/nu/value.rs +++ b/src/nu/value.rs @@ -174,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().as_str().unwrap().into()) .collect(); let vals: Vec = value_rows @@ -191,7 +191,7 @@ pub(crate) fn transpose(value: &Value) -> Value { 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().as_str().unwrap().into()) .collect(); for i in 0..(first_row.len() - 1) { @@ -262,7 +262,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_expanded_string(" ", &Config::default()) } #[test] @@ -410,9 +410,8 @@ mod tests { "b" => Value::test_int(2), }), ]); - assert_eq!( + assert!( is_table(&table), - true, "{} should be a table", default_value_repr(&table) ); @@ -427,9 +426,8 @@ mod tests { "b" => Value::test_int(2), }), ]); - assert_eq!( + assert!( is_table(&table_with_out_of_order_columns), - true, "{} should be a table", default_value_repr(&table_with_out_of_order_columns) ); @@ -444,9 +442,8 @@ mod tests { "b" => Value::test_int(2), }), ]); - assert_eq!( + assert!( is_table(&table_with_nulls), - true, "{} should be a table", default_value_repr(&table_with_nulls) ); @@ -461,9 +458,8 @@ mod tests { "b" => Value::test_float(2.34), }), ]); - assert_eq!( + assert!( is_table(&table_with_number_colum), - true, "{} should be a table", default_value_repr(&table_with_number_colum) ); @@ -477,9 +473,8 @@ mod tests { "b" => Value::test_int(1), }), ]); - assert_eq!( - is_table(¬_a_table_missing_field), - false, + assert!( + !is_table(¬_a_table_missing_field), "{} should not be a table", default_value_repr(¬_a_table_missing_field) ); @@ -494,14 +489,13 @@ mod tests { "b" => Value::test_list(vec![Value::test_int(1)]), }), ]); - assert_eq!( - is_table(¬_a_table_incompatible_types), - false, + assert!( + !is_table(¬_a_table_incompatible_types), "{} should not be a table", default_value_repr(¬_a_table_incompatible_types) ); - assert_eq!(is_table(&Value::test_int(0)), false); + assert!(!is_table(&Value::test_int(0))); } #[test] diff --git a/src/ui.rs b/src/ui.rs index 18b79c8..c602487 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -132,7 +132,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_expanded_string(" ", &nu_protocol::Config::default()), } } @@ -246,7 +246,8 @@ fn render_data(frame: &mut Frame, app: &App, config: &Config) { panic!( "unexpected error when following {:?} in {}", app.position.members, - app.value.into_string(" ", &nu_protocol::Config::default()) + app.value + .to_expanded_string(" ", &nu_protocol::Config::default()) ) });