Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup the repo #54

Merged
merged 29 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
aceec44
don't panic when the config is invalid
amtoine Apr 16, 2024
9e41b09
update examples
amtoine Apr 16, 2024
82c479d
update the README
amtoine Apr 16, 2024
d35040c
implement `Table::to_msg`
amtoine Apr 16, 2024
7e13bc1
have `nu::value::mutate_value_cell` return `Option`
amtoine Apr 16, 2024
e7ee973
add documentation to `nu::value::Table`
amtoine Apr 16, 2024
2d0cdc4
refactor "is table" tests
amtoine Apr 16, 2024
b60cf62
add some notes to `nu::value::transpose`
amtoine Apr 16, 2024
cebf208
add NOTEs to `config::parsing`
amtoine Apr 16, 2024
cc69d86
make `config::parsing::try_color` not public
amtoine Apr 16, 2024
54beb7c
return None from `try_fg_bg_colors` if invalid path
amtoine Apr 16, 2024
8a49d94
add NOTE to `Config::from_value`
amtoine Apr 16, 2024
05db92d
refactor imports in `config/mod.rs`
amtoine Apr 16, 2024
b30fde6
move `repr_key` from `config` to `handler`
amtoine Apr 16, 2024
bd698d3
don't have executable source files
amtoine Apr 18, 2024
4fbc6b3
refactor TUI modules in `src/tui/`
amtoine Apr 18, 2024
060ed63
refactor imports in lib
amtoine Apr 18, 2024
70bb8bf
take `value: &Value` in `Config::from_value`
amtoine Apr 18, 2024
9c74d5f
documentation for `app::Mode`
amtoine Apr 18, 2024
9637869
derive default for `app::Mode`
amtoine Apr 18, 2024
9d07e54
derive `Default` for `edit::Editor`
amtoine Apr 18, 2024
d46bba2
make `navigation` an implementation of `app::App`
amtoine Apr 18, 2024
d191f7e
refactor "following data in app"
amtoine Apr 18, 2024
75de095
remove clones and unwraps from navigation
amtoine Apr 18, 2024
7b91dfb
clean handler
amtoine Apr 18, 2024
5fb10d3
isolate Makefile rules
amtoine Apr 19, 2024
e67399e
make `handle_key_events` an impl of `app::App`
amtoine Apr 19, 2024
da3fc51
embed the configuration in the `app::App`
amtoine Apr 19, 2024
eae82ef
use `nuon::from_nuon` from nushell/nushell#12553
amtoine Apr 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ name = "nu_plugin_explore"
anyhow = "1.0.73"
console = "0.15.7"
crossterm = "0.27.0"
nu-plugin = { git = "https://github.com/nushell/nushell", rev = "c06ef201b72b3cbe901820417106b7d65c6f01e1", package = "nu-plugin" }
nu-protocol = { git = "https://github.com/nushell/nushell", rev = "c06ef201b72b3cbe901820417106b7d65c6f01e1", package = "nu-protocol", features = ["plugin"] }
nu-parser = { git = "https://github.com/nushell/nushell", rev = "c06ef201b72b3cbe901820417106b7d65c6f01e1", package = "nu-parser" }
nu-plugin = { git = "https://github.com/nushell/nushell", rev = "55edef5ddaf3d3d55290863446c2dd50c012e9bc", package = "nu-plugin" }
nu-protocol = { git = "https://github.com/nushell/nushell", rev = "55edef5ddaf3d3d55290863446c2dd50c012e9bc", package = "nu-protocol", features = ["plugin"] }
ratatui = "0.26.1"
url = "2.4.0"

[dev-dependencies]
nuon = { git = "https://github.com/nushell/nushell", rev = "55edef5ddaf3d3d55290863446c2dd50c012e9bc", package = "nuon" }

[target.'cfg(target_os = "macos")'.dependencies]
crossterm = { version = "0.27.0", features = ["use-dev-tty"] }

Expand All @@ -21,4 +23,4 @@ bench = false
[package]
edition = "2021"
name = "nu_plugin_explore"
version = "0.92.3-c06ef201b72b3cbe901820417106b7d65c6f01e1"
version = "0.92.3-55edef5ddaf3d3d55290863446c2dd50c012e9bc"
19 changes: 11 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
CLIPPY_OPTIONS="-D warnings"

.PHONY: all check test fmt doc build register install clean
DEFAULT: check lock test
.PHONY: fmt-check fmt check lock clippy test doc build register install clean
DEFAULT: fmt-check check lock clippy test

check:
fmt-check:
cargo fmt --all --verbose -- --check --verbose
fmt:
cargo fmt --all --verbose

check:
cargo check --workspace --lib --tests
cargo clippy --workspace -- "${CLIPPY_OPTIONS}"

lock: check
./.github/workflows/scripts/check-cargo-lock.sh

test: check
cargo test --workspace
clippy:
cargo clippy --workspace -- "${CLIPPY_OPTIONS}"

fmt:
cargo fmt --all --verbose
test:
cargo test --workspace

doc:
cargo doc --document-private-items --no-deps --open
Expand Down
61 changes: 13 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ A fast *interactive explorer* tool for *structured data* inspired by [`nu-explor
- [*the idea behind an explorer*](#the-idea-behind-an-explorer)
- [*why not `nu-explore`?*](#why-not-nu-explore)
- [*installation*](#installation)
- [*building from source*](#building-from-source)
- [*installing manually*](#installing-manually)
- [*using `nupm install` (recommended)*](#using-nupm-install-recommended)
- [*building from source*](#building-from-source)
- [*usage*](#usage)
- [*demo*](#demo)
- [*configuration*](#configuration)
Expand Down Expand Up @@ -42,21 +41,16 @@ will come very handy in a day-to-day basis for me at least :)
so here we are... LET'S GO :muscle:

# installation
## requirements
> **Note**
> this is the development version of `nu_plugin_explore`, thus it does not require Nushell to be
> installed with a stable version.

let's setup the Nushell dependencies locally, because `nu-plugin` and `nu-protocol` are not release
in version `0.xx.1`, only the stable `0.xx.0` :open_mouth:

- clone the [Nushell repository][nushell/nushell] somewhere
- setup the dependencies
```shell
make dev-deps
## using `nupm install` (recommended)
- download [nushell/nupm](https://github.com/nushell/nupm)
- load the `nupm` module
```nushell
use /path/to/nupm/
```
- run the install process
```nushell
nupm install --path .
```

there are three ways to do it:
## building from source
- build the plugin
```shell
Expand All @@ -71,35 +65,6 @@ make register
> **Note**
> alternatively, you can use directly `make install`

## installing manually
- define the install root, e.g. `$env.CARGO_HOME` or `/some/where/plugins/`
```nushell
let install_root: path = ...
```
- build and install the plugin
```nushell
cargo install --path . --root $install_root
```
- register the plugin in [Nushell]
```nushell
nu --commands $"register ($install_root | path join "bin" $name)"
```
- do not forget to restart [Nushell]

## using `nupm install` (recommended)
> **Warning**
> this is a very alpha software

- download [nushell/nupm](https://github.com/nushell/nupm)
- load the `nupm` module
```nushell
use /path/to/nupm/
```
- run the install process
```nushell
nupm install --path .
```

# usage
- get some help
```nushell
Expand All @@ -117,7 +82,7 @@ open Cargo.toml | nu_plugin_explore
## default configuration
you can find it in [`default.nuon`](./examples/config/default.nuon).

you can copy-paste it in your `config.nu` and set `$env.explore_config` to it:
you can copy-paste it in your `config.nu` and set `$env.config.plugins.explore` to it:
```nushell
$env.config.plugins.explore = {
# content of the default config
Expand Down Expand Up @@ -157,8 +122,8 @@ in order to help, you can have a look at
- [ ] when going into a file or URL, open it
- [x] give different colors to names and type
- [x] show true tables as such
- [ ] get the config from `$env.config` => can parse configuration from CLI
- [ ] add check for the config to make sure it's valid
- [x] get the config from `$env.config` => can parse configuration from CLI
- [x] add check for the config to make sure it's valid
- [ ] support for editing cells in INSERT mode
- [x] string cells
- [ ] other simple cells
Expand Down
2 changes: 1 addition & 1 deletion nupm.nuon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
name: nu_plugin_explore,
version: "0.92.3-c06ef201b72b3cbe901820417106b7d65c6f01e1",
version: "0.92.3-55edef5ddaf3d3d55290863446c2dd50c012e9bc"
description: "A fast structured data explorer for Nushell.",
license: LICENSE,
type: custom
Expand Down
54 changes: 38 additions & 16 deletions src/app.rs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,26 @@ use nu_protocol::{
Span, Value,
};

use crate::edit::Editor;
use crate::{config::Config, edit::Editor};

/// the mode in which the application is
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Default)]
pub enum Mode {
/// the NORMAL mode is the *navigation* mode, where the user can move around in the data
/// the *navigation* mode, where the user can move around in the data
#[default]
Normal,
/// the INSERT mode lets the user edit cells of the structured data
/// lets the user edit cells of the structured data
Insert,
/// the PEEKING mode lets the user *peek* data out of the application, to be reused later
/// lets the user *peek* data out of the application, to be reused later
Peeking,
/// indicates that the user has arrived to the very bottom of the nested data, i.e. there is
/// nothing more to the right
Bottom,
/// waits for more keys to perform an action, e.g. jumping to a line or motion repetition that
/// both require to enter a number before the actual action
Waiting(usize),
}

impl Default for Mode {
fn default() -> Self {
Self::Normal
}
}

impl std::fmt::Display for Mode {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let repr = match self {
Expand All @@ -38,6 +37,7 @@ impl std::fmt::Display for Mode {
}
}

#[derive(Clone)]
/// the complete state of the application
pub struct App {
/// the full current path in the data
Expand All @@ -50,6 +50,8 @@ pub struct App {
pub editor: Editor,
/// the value that is being explored
pub value: Value,
/// the configuration for the app
pub config: Config,
}

impl Default for App {
Expand All @@ -60,6 +62,7 @@ impl Default for App {
mode: Mode::default(),
editor: Editor::default(),
value: Value::default(),
config: Config::default(),
}
}
}
Expand Down Expand Up @@ -103,11 +106,7 @@ impl App {
}

pub(super) fn enter_editor(&mut self) -> Result<(), String> {
let value = self
.value
.clone()
.follow_cell_path(&self.position.members, false)
.unwrap();
let value = self.value_under_cursor(None);

if matches!(value, Value::String { .. }) {
self.mode = Mode::Insert;
Expand All @@ -122,4 +121,27 @@ impl App {
))
}
}

pub(crate) fn value_under_cursor(&self, alternate_cursor: Option<CellPath>) -> Value {
self.value
.clone()
.follow_cell_path(
&alternate_cursor.unwrap_or(self.position.clone()).members,
false,
)
.unwrap_or_else(|_| {
panic!(
"unexpected error when following {:?} in {}",
self.position.members,
self.value
.to_expanded_string(" ", &nu_protocol::Config::default())
)
})
}

pub(crate) fn with_config(&self, config: Config) -> Self {
let mut app = self.clone();
app.config = config;
app
}
}
Loading
Loading