diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 53ffb66..e402d02 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,12 +24,6 @@ jobs: - name: Format run: cargo fmt --all -- --check - - name: Setup dependencies - run: | - git clone https://github.com/nushell/nushell - make NUSHELL_PATH=nushell dev-deps - shell: bash - - name: Check the library run: cargo check --workspace --lib @@ -55,11 +49,5 @@ jobs: with: rustflags: "" - - name: Setup dependencies - run: | - git clone https://github.com/nushell/nushell - make NUSHELL_PATH=nushell dev-deps - shell: bash - - name: Tests run: cargo test --workspace diff --git a/Cargo.toml b/Cargo.toml index e14e7ba..a155297 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.87.0" -nu-protocol = { version = "0.87.0", features = ["plugin"] } +nu-plugin = "0.89.0" +nu-protocol = { version = "0.89.0", features = ["plugin"] } ratatui = "0.22.0" url = "2.4.0" @@ -17,4 +17,4 @@ bench = false [package] edition = "2021" name = "nu_plugin_explore" -version = "0.1.1" +version = "0.1.2" diff --git a/nupm.nuon b/nupm.nuon index 2075973..f4dd4f2 100644 --- a/nupm.nuon +++ b/nupm.nuon @@ -1,7 +1,7 @@ { name: nu_plugin_explore, - version: "0.1.1", + version: "0.1.2", description: "A fast structured data explorer for Nushell.", license: LICENSE, type: custom -} \ No newline at end of file +} diff --git a/scripts/setup-dev-deps b/scripts/setup-dev-deps deleted file mode 100755 index 0c8c6e5..0000000 --- a/scripts/setup-dev-deps +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash - -if [[ -z "$NUSHELL_PATH" ]]; then - path=$(cargo install --list | grep '^nu v' | sed 's/^.*(//; s/):$//') - - [[ -z "$path" ]] && { - echo "couldn't find path to nushell source, please set \`NUSHELL_PATH\` manually" - exit 0 - } -else - path="$NUSHELL_PATH" -fi - -cargo add nu-plugin --path "$path/crates/nu-plugin/" -cargo add nu-protocol --path "$path/crates/nu-protocol/" --features plugin diff --git a/src/app.rs b/src/app.rs index d4bce1b..06f1c89 100755 --- a/src/app.rs +++ b/src/app.rs @@ -73,7 +73,7 @@ impl App { optional: vals.is_empty(), }), Value::Record { val: rec, .. } => app.position.members.push(PathMember::String { - val: rec.cols.get(0).unwrap_or(&"".to_string()).into(), + val: rec.cols.first().unwrap_or(&"".to_string()).into(), span: Span::unknown(), optional: rec.cols.is_empty(), }), diff --git a/src/handler.rs b/src/handler.rs index 6fac297..a5664d5 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -72,7 +72,7 @@ pub fn handle_key_events( Value::Record { val: rec, .. } => { // NOTE: app.position.members should never be empty by construction *app.position.members.last_mut().unwrap() = PathMember::String { - val: rec.cols.get(0).unwrap_or(&"".to_string()).to_string(), + val: rec.cols.first().unwrap_or(&"".to_string()).to_string(), span: Span::unknown(), optional: rec.cols.is_empty(), }; diff --git a/src/navigation.rs b/src/navigation.rs index eb70444..c4dc5e0 100644 --- a/src/navigation.rs +++ b/src/navigation.rs @@ -127,7 +127,7 @@ pub(super) fn go_deeper_in_data(app: &mut App) { optional: vals.is_empty(), }), Value::Record { val: rec, .. } => app.position.members.push(PathMember::String { - val: rec.cols.get(0).unwrap_or(&"".to_string()).into(), + val: rec.cols.first().unwrap_or(&"".to_string()).into(), span: Span::unknown(), optional: rec.cols.is_empty(), }), diff --git a/src/nu/value.rs b/src/nu/value.rs index ac766b0..4629839 100644 --- a/src/nu/value.rs +++ b/src/nu/value.rs @@ -45,15 +45,21 @@ pub(crate) fn mutate_value_cell(value: &Value, cell_path: &CellPath, cell: &Valu let id = rec.cols.iter().position(|x| *x == col).unwrap_or(0); - let mut vals = rec.vals.clone(); - vals[id] = mutate_value_cell(&vals[id], &cell_path, cell); - - let mut record = Record::new(); - rec.cols.iter().zip(vals).for_each(|(col, val)| { - record.push(col, val); - }); + let cols = rec.columns().cloned().collect(); + let vals = rec + .values() + .cloned() + .enumerate() + .map(|(i, v)| { + if i == id { + mutate_value_cell(&v, &cell_path, cell) + } else { + v + } + }) + .collect(); - Value::record(record, Span::unknown()) + Value::record(Record::from_raw_cols_vals(cols, vals), Span::unknown()) } _ => cell.clone(), } @@ -173,7 +179,7 @@ pub(crate) fn transpose(value: &Value) -> Value { .map(|row| row.get_data_by_key("2").unwrap()) .collect(); - return Value::record(Record { cols, vals }, Span::unknown()); + return Value::record(Record::from_raw_cols_vals(cols, vals), Span::unknown()); } else { let mut rows = vec![]; let cols: Vec = value_rows @@ -183,13 +189,13 @@ pub(crate) fn transpose(value: &Value) -> Value { for i in 0..(first_row.len() - 1) { rows.push(Value::record( - Record { - cols: cols.clone(), - vals: value_rows + Record::from_raw_cols_vals( + cols.clone(), + value_rows .iter() .map(|v| v.get_data_by_key(&format!("{}", i + 2)).unwrap()) .collect(), - }, + ), Span::unknown(), )); } @@ -208,7 +214,10 @@ pub(crate) fn transpose(value: &Value) -> Value { vs.push(v.get_data_by_key(col).unwrap()); } - rows.push(Value::record(Record { cols, vals: vs }, Span::unknown())); + rows.push(Value::record( + Record::from_raw_cols_vals(cols, vs), + Span::unknown(), + )); } return Value::list(rows, Span::unknown());