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

Different preview modes: full, count, none #40

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

brewingcode
Copy link

@brewingcode brewingcode commented Feb 16, 2022

Adds two new ways to preview child nodes (only in --mode line, doesn't affect --mode data).

The existing single way full:

image

The first new way count shows objects as { N items }, where N is the number of key-value pairs. It shows [ N items ] for arrays.

image

The second new way none just removes the child counts/previews entirely:

image

Closes #38

This just prints the container's number of children, while keeping the
opening/closing characters. So:

    foo: [ 2 ]
    bar: { 3 }
```
$ cargo build
   Compiling jless v0.7.1 (/...)
error[E0308]: mismatched types
   --> src/lineprinter.rs:765:12
    |
765 |         Ok(num_printed)
    |            ^^^^^^^^^^^ expected `isize`, found `usize`
    |
help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit
    |
765 |         Ok(num_printed.try_into().unwrap())
    |                       ++++++++++++++++++++
```

I'm not sure why this error only showed up after my changes. I haven't
changed the type of `num_printed`, and I've only changed it by calling
`+=` on it a few extra times.
This is modeled exactly after the existing `JsonViewer.mode`, down to
its arg handling and toggling.
Rather than calling `highlight_str` a bunch, use `format!` to assemble
the string. This also removes the need to `use std::convert::TryInto`,
since I'm `as isize`ing everywhere. It also respects and updates
`available_space`, though I'm not quite sure if a string as short as
this should do so.
This is used in lots of places, so it's not worth changing every single
call to `::new()` just to add `preview`. Just set it right after `::new`
in app.rs and let it default everywhere else.
This involved adding an extra string to `generate_container_count`,
because Rust has weird memory rules around str::len() that was causing
the returned value to get stuck based on the initial assigned value of
`count_str`, rather than its final value. Or something, I don't know.
@brewingcode brewingcode force-pushed the optional-container-counts branch from ebb770c to a9a4225 Compare February 16, 2022 20:57
This renders nothing, as it's been requested in a couple other Github
issues. Toggling now goes `full (default)` --> `count` --> `none`, then
repeats.
@brewingcode
Copy link
Author

This PR could also close #37, which asks to just hide the previews.

It might also close #33, which asks the previews to be rendered conditionally. Maybe just switching from the full previews to a count-of-children would be sufficient for that issue's purposes.

@brewingcode brewingcode changed the title Optional container counts Different preview modes: full, count, none Feb 16, 2022
…counts

* origin/master:
  Change Space command to toggle collapsed state of focused node. (PaulJuliusMartinez#42)
@brewingcode brewingcode force-pushed the optional-container-counts branch from dc7f238 to b5bccfe Compare February 17, 2022 18:30
Need to call `highlight_str()` in `fill_in_container_preview()`,
otherwise the renderer thinks the lines extend off to the right, and
display `>` as if the line is truncated and h-scroll is available.
`.len()` was not the right method for number of characters in a string,
`.chars().count()` is.
@brewingcode brewingcode force-pushed the optional-container-counts branch from b5bccfe to 2ee1eb6 Compare February 18, 2022 17:04
In the absence of terminal colors, `[ 3 ]` could be read as either an
array with three elements, or an array with just `3` as its sole
element.
Mode::Line relies on rendering collapsed nodes as single-line previews,
so Preview::None hides these. Rather than changing the way Mode::Line
works, its better to just disable Preview::None in Mode::Line.

This makes JsonViewer::preview private, since it now has funny rules.
@brewingcode
Copy link
Author

See #38 (comment) for a bit more context around 6f71ce0 and 26a6059

…counts

Fixed a few conflicts around viewer.rs:toggle_mode()
* origin/master:
  Update constant in test to fit within usize on 32-bit systems.
  Keep focused line at same height when toggling between Line and Data mode.
  Implement ctrl-d/ctrl-u commands to jump by half a screen or specified number of lines.
  v0.7.2 Release
  Use freopen to move /dev/tty input to stdin so rustyline works when piping in input. (PaulJuliusMartinez#32)
  Remove x86_64-unknown-linux-musl from CI platforms; libc-stdhandle fails to compile with it.
  Don't run ci on pull_request event; it's redundant.
  Add CI badge to README.
  Only run release workflow when tags are pushed; remove aarch64 architecture.
  Fix clippy errors.
  Add CI and Release Workflows.
@brewingcode brewingcode force-pushed the optional-container-counts branch 2 times, most recently from e6666e6 to f386d0a Compare February 21, 2022 01:36
The CI gods demand it
@brewingcode brewingcode force-pushed the optional-container-counts branch from f386d0a to 41079e9 Compare February 21, 2022 01:45
]
.into_iter()
for (available_space, used_space, expected) in
vec![(14, 11, r#"[ 3 items ]"#), (4, 3, r#"[…]"#), (2, 0, r#""#)].into_iter()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the linter is being overzealous here, and in the rest of the test_ functions in this commit. It's way harder to read this vec![...] on a single line. They were on their own lines with specific spacing to make it easier for humans to read.

…counts

* origin/master:
  Remove code for website. (Now on website branch.)
  Update README.md with updated installation instructions and info about the website.
…unts

* origin/main:
  Remove .value_range field from LinePrinter. (Can be accessed through .row.range.)
  Show square bracket delimiter around all non-string keys.
  Use Row in LinePrinter when printing out value, rather than passed in value field.
  Pass FlatJson and Row into LinePrinter; have it figure out Label stuff
  Add basic YAML support. (PaulJuliusMartinez#57)
  Revert Arch Linux installation command now that the package has been added to the official community repository.
  Remove incorrect Arch Linux installation command; simply state that jless is available in the AUR.
  Add install instruction for FreeBSD to README (PaulJuliusMartinez#48)
@hacker-DOM
Copy link

Is there a ETA on this PR? 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature request: abbreviated truncated views
2 participants