GithubHelp home page GithubHelp logo

pauljuliusmartinez / jless Goto Github PK

View Code? Open in Web Editor NEW
4.6K 24.0 89.0 2.12 MB

jless is a command-line JSON viewer designed for reading, exploring, and searching through JSON data.

Home Page: https://jless.io

License: MIT License

Shell 0.03% Rust 99.97%
json cli rust

jless's Introduction

jless logo and mascot

jless is a command-line JSON viewer. Use it as a replacement for whatever combination of less, jq, cat and your editor you currently use for viewing JSON files. It is written in Rust and can be installed as a single standalone binary.

ci

Features

  • Clean syntax highlighted display of JSON data, omitting quotes around object keys, closing object and array delimiters, and trailing commas.
  • Expand and collapse objects and arrays so you can see both the high- and low-level structure of the data.
  • A wealth of vim-inspired movement commands for efficiently moving around and viewing data.
  • Full regex-based search for finding exactly the data you're looking for.

jless currently supports macOS and Linux. Windows support is planned.

Installation

You can install jless using various package managers:

Operating System / Package Manager Command
macOS - HomeBrew brew install jless
macOS - MacPorts sudo port install jless
Linux - HomeBrew brew install jless
Arch Linux pacman -S jless
Void Linux sudo xbps-install jless
NetBSD pkgin install jless
FreeBSD pkg install jless
From source (Requires Rust toolchain) cargo install jless

The releases page also contains links to binaries for various architectures.

Dependencies

On Linux systems, X11 libraries are needed to build clipboard access if building from source. On Ubuntu you can install these using:

sudo apt-get install libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev

Website

jless.io is the official website for jless. Code for the website is contained separately on the website branch.

Logo

The mascot of the jless project is Jules the jellyfish.

jless mascot

Art for Jules was created by annatgraphics.

License

jless is released under the MIT License.

jless's People

Contributors

felixonmars avatar gerovanmi avatar jabbate19 avatar lecafard avatar lwhsu avatar pauljuliusmartinez avatar tranzystorekk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jless's Issues

feature request: word wrap

strings longer than the terminal's number of columns are truncated.
would be nice to be able to word wrap these.

jless - NetBSD package

Hi,

I've just packaged jless for NetBSD. I haven't merged the package yet as I have one question about it.

Is this planned to be a viewer only or, do you intend to have editor functionality at some point?
This is basically an internal thing as I would like to know what to assign as package category, either textproc or, editors

I can merge the package very soon, just need a clarification on the above. FYI, it works as expected.
Thanks

feature request: abbreviated truncated views

Would it be possible to add a command line option to render the truncated strings as just a count (key-value pairs for objects, array elements for arrays)? For example, here's what jless currently says with https://api.github.com/repos/PaulJuliusMartinez/jless/commits:

▽ [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, …]
  ▽ [0]: {sha: "cdcb02038730f0cd3f5ccea594511e3cfb37887a", node_id: "C_kwDOFYWjXtoAKGNkY2IwMjAzODczMGYwY2QzZjVjY2VhNTk0N…", …}
      sha: "cdcb02038730f0cd3f5ccea594511e3cfb37887a"
      node_id: "C_kwDOFYWjXtoAKGNkY2IwMjAzODczMGYwY2QzZjVjY2VhNTk0NTExZTNjZmIzNzg4N2E"
    ▷ commit: {author: {…}, committer: {…}, message: "Upgrade arg parsing to clap v3 (#17)\n\nSwitches arg parsing to st…", …}
      url: "https://api.github.com/repos/PaulJuliusMartinez/jless/commits/cdcb02038730f0cd3f5ccea594511e3cfb37887a"
      html_url: "https://github.com/PaulJuliusMartinez/jless/commit/cdcb02038730f0cd3f5ccea594511e3cfb37887a"
      comments_url: "https://api.github.com/repos/PaulJuliusMartinez/jless/commits/cdcb02038730f0cd3f5ccea594511e3cfb37887a/…"
    ▷ author: {login: "tranzystorek-io", id: 5671049, node_id: "MDQ6VXNlcjU2NzEwNDk=", avatar_url: "https://avatars.gith…", …}
    ▷ committer: {login: "PaulJuliusMartinez", id: 3301004, node_id: "MDQ6VXNlcjMzMDEwMDQ=", avatar_url: "https://avatar…", …}
    ▷ parents: [{sha: "619f74697d1c0277b07d685bcd061262010485f2", url: "https://api.github.com/repos/PaulJuliusMartinez…", …}]
  ▷ [1]: {sha: "619f74697d1c0277b07d685bcd061262010485f2", node_id: "C_kwDOFYWjXtoAKDYxOWY3NDY5N2QxYzAyNzdiMDdkNjg1YmNkM…", …}
  ▷ [2]: {sha: "ba2e6e7dc7855bf32852bd8a113619e91f016e3d", node_id: "C_kwDOFYWjXtoAKGJhMmU2ZTdkYzc4NTViZjMyODUyYmQ4YTExM…", …}
  ▷ [3]: {sha: "bf449651685c8709a2669e360bb3902f9f68afbd", node_id: "C_kwDOFYWjXtoAKGJmNDQ5NjUxNjg1Yzg3MDlhMjY2OWUzNjBiY…", …}
  ▷ [4]: {sha: "b3f21a215a9f3b12156f542cc78f330624d5faf1", node_id: "C_kwDOFYWjXtoAKGIzZjIxYTIxNWE5ZjNiMTIxNTZmNTQyY2M3O…", …}
  ▷ [5]: {sha: "814ac066ae52ad052f2bc685d358821c00f41fea", node_id: "C_kwDOFYWjXtoAKDgxNGFjMDY2YWU1MmFkMDUyZjJiYzY4NWQzN…", …}

I have a tool of my own for viewing JSON that shows the same structure like so:

[
  {
    "sha": "cdcb02038730f0cd3f5ccea594511e3cfb37887a",
    "node_id": "C_kwDOFYWjXtoAKGNkY2IwMjAzODczMGYwY2QzZjVjY2VhNTk0NTExZTNjZmIzNzg4N2E",
    "commit": { 7 },
    "url": "https://api.github.com/repos/PaulJuliusMartinez/jless/commits/cdcb02038730f0cd3f5ccea594511e3cfb37887a",
    "html_url": "https://github.com/PaulJuliusMartinez/jless/commit/cdcb02038730f0cd3f5ccea594511e3cfb37887a",
    "comments_url": "https://api.github.com/repos/PaulJuliusMartinez/jless/commits/cdcb02038730f0cd3f5ccea594511e3cfb37887a/co
mments",
    "author": { 18 },
    "committer": { 18 },
    "parents": [ 1 ]
  },
  { 9 },
  { 9 },
  { 9 },
  { 9 },
  { 9 },
  { 9 },

While I don't need an exact match, I figure that jless could (optionally) produce something like:

▽ [ 30 ]
  ▽ [0]: { 9 }
      sha: "cdcb02038730f0cd3f5ccea594511e3cfb37887a"
      node_id: "C_kwDOFYWjXtoAKGNkY2IwMjAzODczMGYwY2QzZjVjY2VhNTk0NTExZTNjZmIzNzg4N2E"
    ▷ commit: { 7 }
      url: "https://api.github.com/repos/PaulJuliusMartinez/jless/commits/cdcb02038730f0cd3f5ccea594511e3cfb37887a"
      html_url: "https://github.com/PaulJuliusMartinez/jless/commit/cdcb02038730f0cd3f5ccea594511e3cfb37887a"
      comments_url: "https://api.github.com/repos/PaulJuliusMartinez/jless/commits/cdcb02038730f0cd3f5ccea594511e3cfb37887a/…"
    ▷ author: { 18 }
    ▷ committer: { 18 }
    ▷ parents: [ 1 ]
  ▷ [1]: { 9 }
  ▷ [2]: { 9 }
  ▷ [3]: { 9 }
  ▷ [4]: { 9 }
  ▷ [5]: { 9 }

I'm happy to give this a try if you could point me to a starting place. I know zero rust, but am familiar with lots of other languages. It looks like lineprinter.rs:fill_in_value() is where these labels are generated, and maybe from there into truncatedstrview.rs, but I quickly got lost in there.

Cannot press Escape to cancel entering a command or search input.

When you press : to enter a command, or / or ? to enter a search input, you cannot press escape to cancel the operation. You must hit Enter to submit your input and get back to the normal viewing experience.

jless uses Rustyline for the readline-esque functionality. I'm unsure if this is simply something that's not supported by Rustyline, or if my input code is doing something weird to mask the escapes.

Simple transformations: get all elements in a path

I have lots of json files with one object per line. It would be awesome if i could interactively get all values in a certain path, e.g. key1.key2[1] would give me 12345 from {key1:{key2:[12345,9999]}}.

Support for YAML

Support for YAML would be great, using the collapse/expand behaviour to traverse large YAML files! 😄

Syntax highlighting looks bad in certain color schemes

The syntax highlighting looks bad in certain color schemes. Most notably, when using Solarized Dark, sometimes the background and foreground color are indistinguishable:

Gruvbox:
gruvbox-jless

Solarized Dark:
solarized-dark-jless
solarized-dark-jless2

The highlighting of search results in the previews are invisible, and the text of currently focused object keys is also unreadable.

In general, the text of the currently focused object key is often unreadable.

I'm unsure of how to solve this well and respect the user's chosen color scheme by using only the base set of 16 colors. Handling light vs. dark modes is especially difficult. (Solarized is bad because all of its Bright variants are so close together.)

The current code uses a mix of dimmed and inverted mode, but these don't always work well together in all terminals / color schemes.

No non-zero exit code in case of parsing errors

Description

jless currently returns 0 (success) as an exit code, even if the command failed (e.g. if the input wasn't valid JSON). To reproduce:

jless - <<<"This is no JSON"; echo $?

will result the following output:

Unable to parse input: "Parse error"
0

Impact / use-case

Having a non-zero exit code increases interoperability and allows for fallbacks in scripts, e.g. jless "$@" || less "$@"

lib issue

Hi,
I am getting this error when try to run it:
/lib64/libc.so.6: version `GLIBC_2.18' not found

Any chance to adapt the jless to older centos version?

Looks like very useful tool.

Fails to build on 32-bits systems

Trying to package this for Alpine Linux, and I noticed it fails on 32-bits arches (x86, armv7, armhf), it fails to build due to the following errors:

error: literal out of range for `usize`
   --> src/search.rs:455:55
    |
455 |         assert_eq!(search.jump_to_match(1, &fj, Next, 1000000000001), 4);
    |                                                       ^^^^^^^^^^^^^
    |
    = note: `#[deny(overflowing_literals)]` on by default
    = note: the literal `1000000000001` does not fit into the type `usize` whose range is `0..=4294967295`
error: literal out of range for `usize`
   --> src/search.rs:456:55
    |
456 |         assert_eq!(search.jump_to_match(4, &fj, Prev, 1000000000001), 1);
    |                                                       ^^^^^^^^^^^^^
    |
    = note: the literal `1000000000001` does not fit into the type `usize` whose range is `0..=4294967295`

Deb package or snap installation for Ubuntu

I use Ubuntu all the time in my work, but none of the utilities I have installed offer Homebrew to install them. In my personal experience, the most popular choices are the deb-package and the classic snap app.

Initial Release Checklist / Project Roadmap

Friends and Family Release

Basic Functionality:

  • Finish basic set of movement commands
    • zt, zz, zb (1910b36)
    • number arguments to hjkl/scrolling, maybe others (eb7e116, 2d11dee)
      • Add count support to focus prev/next sibling (J and K) (6fb6218)
    • Support PageUp and PageDown (Move up/down by height of screen) (acf8ee3)
    • H to focus parent without collapsing current node (ed21d57)
  • Don't let long lines overflow horizontally (0ff12d4, a1dd70e, 849ef97)
    • Fix issue with displaying empty strings (3ee50d0)
    • Update LinePrinter to handle Containers (7be3404)
  • Better formatting of collapsed cells in Line and Data modes (b5f29b3)
    • Quote non-JS identifier keys and all keys in Line mode (168d14f)
    • Write lots of tests (2396477)
  • Display full controls in help menu (Just pipe to less for now; -r to use colored output) (fbfd842, 5b898e7, 458271e)
  • Command line arguments, --help documentation (ee1eb8c, 41a1018)
  • Basic error handling of JSON parsing errors
  • Show input source in status bar (3ade459)
    • Make it not overflow (84600c9)
      • Make this code not horrendous (5d15b5a)
  • Pretty print JSON to stdout if output is not a TTY (04bc1ac)

Polish

  • Properly restore terminal on close (6570011)
  • Move cursor to middle of screen when jumping "far" from place on screen (b9e07c6)
  • Play visual bell at appropriate points
  • Immediately respond to escape key (60f0f06)
  • Handle escape key in Rustyline (If possible to do simply)
  • Handle mouse wheel events (0ee52c8)
  • Handle mouse click events (2a11873, f2fea1e)
    • Don't execute click event when clicking on the status bar
    • Try to figure out a way to still allow highlighting (Only do stuff on Release?)

Release

  • Figure out how to actually generate release builds (bf44965)

Development / Debug

  • Add bind command / command-line-args for experimenting with new commands
  • "Record" mode (print all input to stderr)

Public Release

~ndjson

  • Different JSON parser (216210b)
  • Support multiple JSON objects separated by newlines (a4ecfbe)
    • Actually enforce that they are separated by newlines
  • Fix ndjson issues/bugs
    • Show focus indicator next to top level primitives in data mode (f5d8d65)
    • G causes panic when last top level thing is collapsed (20d5252)

Search

  • Update FlatJson to store ranges for keys and values, and for Rows (0502235, a226811, 5d10274)
  • Next/previous Object key with * and # (8505634)
  • Plain text search with / and ? (b9068f6)
    • Support /<CR> and ?<CR> as longcuts for next/previous match (1c2bff8)
  • Support count arguments to n and N (i.e., 3n jumps ahead three occurrences) (6795e7b)
  • Support count arguments to /, ?, * and # (814ac06)
  • Support smart case searching (case insensitive if all lowercase, case sensitive if any capital letters) (3641740)
  • Escape/unescape braces and square brackets for better search experience (2fce67a)
  • Search highlighting (baf1fb3, c53dfa6)
    • Highlight matching text in literal values (37172ae)
    • Highlight matching text in object keys (05d3c26)
    • Highlight matching text in collapsed previews (f1015a8)
    • Highlight container delimiters ([/] and {/}) when part of matching text (6fe0c11, c3e7a39)
    • Highlight currently focused match in different color (c094dfb)
  • Handle too many search results
  • Show messages when no results are found (9a81088)
    • Show message when regex compilation fails (aa1d8ed)

Focus

  • f to "focus" on a node

Logo

  • Jules the Jellyfish

Codebase/Project Quality & Presentation

Performance

  • Only paint lines that need repainting
  • Pack OptionIndex into single usize
  • Parameterize by u16/u32/u64 and upgrade as needed

Unclear prioritization

  • Hiding keys
  • No color mode
  • Explore additional commands
  • y to copy value to clipboard
    • Different things to paste: yy, value; yPpretty-printed value; yp, path (input.foo[0].bar[33]); yq, jq style path, .foo[].bar[] ?

Bugs

  • Respond immediately to WINCH events
  • Prevent flashes while scrolling (iTerm only?)
  • Path to key is truncated prematurely on long_values.json; doesn't include last character of key

V2

  • Windows support (Need help; I don't know what this means)
  • More robust syntax support for :focus
  • Stream input

Ctrl+Up/Down/Left/Right crashes the software

$ jless -V
jless 0.7.2

Prepending the command with RUST_BACKTRACE=1, I was able to acquire the following error message.

:thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: Other, error: "Could not parse an event" }, src/app.rs:98:31
2022-03-07.18-04-44-375.mp4

Parse error with NaN, Infinity, -Infinity

By default Python's json module allows NaN and Infinity when serialising to json:

>>> import json
>>> json.dumps({'a':float('nan'), 'b':float('inf')})
'{"a": NaN, "b": Infinity}'

Though technically this isn't complient JSON, it would be nice if jless was more permissive to allow the viewing of these files?:

>>> echo '{"x": NaN}' | jless
Unable to parse input: "Parse error"

feature request: man page

Synopsis

Make the User Guide available in the terminal with a man page.

Description

The User Guide is great! I'd love it if this were available in the terminal as a man page. (That's the whole point of this project, right? Keep me in the comfort of a keyboard-driven environment, yes? 😃 ) ripgrep has an excellent man page that comes when you install with brew—that might furnish a good example of how to do this.

Misc

This is a beautiful little utility! Thank you so much for making it!

Exec format error (Windows WSL2 Debian)

Staging: Windows 10 WSL2 "bullseye/sid"
brew --version
Homebrew 3.4.1
Homebrew/homebrew-core (git revision 7aa6ef8a215; last commit 2022-03-12)

Steps to reproduce:
$ brew install jless
$ jless
Error:
-bash: /home/linuxbrew/.linuxbrew/bin/jless: cannot execute binary file: Exec format error

zoom / filter feature

Allow removing all parents from the view, except for the currently entered container (map / list).


Use case: I'm running aws ec2 describe-instances - I / search for the instance I care about.

Now I'd like to zoom into that map and remove all parents from the status.

Next I'd like to /public_ip

It can be done without zooming, but because the block is so giant, I'm not sure if I'm looking at the public_ip of some other instance.


Of course you'd also want to zoom out.

I suggest the keys z for zoom and u for up Z for unzoom

Feature request: add search/filter à la jq

jless is awesome, thank you very much for your work on it!

Description of the feature:

At the moment jless search works à la Vim, searching back and forth for patterns with /?; in particular the documentations says:

The search is not performed over the original input, but over a single-line pretty formatted version of the input JSON.

would it be possible to introduce some sort of jq grammar where we can filter via, say

.key <-- get values of nested key
[] <--- get array elements
select(.key|test("<regex>") <--- search for regex and return key or value

and similar? Or is this already present and I overlooked it?

Thank you again for the great work!

Cannot `cargo install jless` on Ubuntu 21.10

Hey Paul (@PaulJuliusMartinez),

Tried to install via cargo install jless under:

Ubuntu 21.10 64b

$ ldd --version
ldd (Ubuntu GLIBC 2.34-0ubuntu3) 2.34
$ rustc --version
rustc 1.51.0 (2fd73fabe 2021-03-23)
$ cargo --version
cargo 1.51.0 (43b129a20 2021-03-16)

And got this:

$ cargo install jless
    Updating crates.io index
  Installing jless v0.7.1
   Compiling libc v0.2.117
   Compiling proc-macro2 v1.0.36
   Compiling unicode-xid v0.2.2
   Compiling version_check v0.9.4
   Compiling syn v1.0.86
   Compiling bitflags v1.3.2
   Compiling autocfg v1.1.0
   Compiling memchr v2.4.1
   Compiling cfg-if v1.0.0
   Compiling io-lifetimes v0.4.4
   Compiling rustix v0.32.1
   Compiling unicode-width v0.1.9
   Compiling log v0.4.14
   Compiling unicode-segmentation v1.9.0
   Compiling linux-raw-sys v0.0.37
   Compiling smallvec v1.8.0
   Compiling utf8-ranges v1.0.4
   Compiling vec_map v0.8.2
   Compiling signal-hook v0.3.13
   Compiling endian-type v0.1.2
   Compiling fnv v1.0.7
   Compiling beef v0.5.1
   Compiling ansi_term v0.12.1
   Compiling regex-syntax v0.6.25
   Compiling strsim v0.8.0
   Compiling utf8parse v0.2.0
   Compiling numtoa v0.1.0
   Compiling lazy_static v1.4.0
   Compiling cfg-if v0.1.10
   Compiling proc-macro-error-attr v1.0.4
   Compiling proc-macro-error v1.0.4
   Compiling memoffset v0.6.5
   Compiling textwrap v0.11.0
   Compiling heck v0.3.3
   Compiling nibble_vec v0.1.0
   Compiling radix_trie v0.2.1
   Compiling dirs-sys-next v0.1.2
   Compiling atty v0.2.14
   Compiling signal-hook-registry v1.4.0
   Compiling isatty v0.1.9
   Compiling termion v1.5.6
   Compiling quote v1.0.15
   Compiling aho-corasick v0.7.18
   Compiling dirs-next v2.0.0
   Compiling clap v2.34.0
   Compiling regex v1.5.4
   Compiling nix v0.23.1
   Compiling fd-lock v3.0.3
   Compiling logos-derive v0.12.0
   Compiling rustyline v9.1.2
   Compiling logos v0.12.0
   Compiling structopt-derive v0.4.18
   Compiling structopt v0.3.26
   Compiling jless v0.7.1
error[E0658]: or-patterns syntax is experimental
   --> /home/gcarreno/.cargo/registry/src/github.com-1ecc6299db9ec823/jless-0.7.1/src/app.rs:101:26
    |
101 |                 KeyEvent(Key::Ctrl('c') | Key::Char('q')) => break,
    |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: see issue #54883 <https://github.com/rust-lang/rust/issues/54883> for more information

error[E0658]: or-patterns syntax is experimental
  --> /home/gcarreno/.cargo/registry/src/github.com-1ecc6299db9ec823/jless-0.7.1/src/jsonparser.rs:67:24
   |
67 |         while let Some(JsonToken::Whitespace | JsonToken::Newline) = self.peek_token_or_eof() {
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #54883 <https://github.com/rust-lang/rust/issues/54883> for more information

error[E0658]: use of unstable library feature 'partition_point': new API
   --> /home/gcarreno/.cargo/registry/src/github.com-1ecc6299db9ec823/jless-0.7.1/src/search.rs:275:55
    |
275 |                         let next_match = self.matches.partition_point(|match_range| {
    |                                                       ^^^^^^^^^^^^^^^
    |
    = note: see issue #73831 <https://github.com/rust-lang/rust/issues/73831> for more information

error[E0658]: use of unstable library feature 'partition_point': new API
   --> /home/gcarreno/.cargo/registry/src/github.com-1ecc6299db9ec823/jless-0.7.1/src/search.rs:293:55
    |
293 |                         let next_match = self.matches.partition_point(|match_range| {
    |                                                       ^^^^^^^^^^^^^^^
    |
    = note: see issue #73831 <https://github.com/rust-lang/rust/issues/73831> for more information

error[E0658]: use of unstable library feature 'partition_point': new API
   --> /home/gcarreno/.cargo/registry/src/github.com-1ecc6299db9ec823/jless-0.7.1/src/search.rs:365:14
    |
365 |             .partition_point(|row| row.full_range().start <= match_range.start)
    |              ^^^^^^^^^^^^^^^
    |
    = note: see issue #73831 <https://github.com/rust-lang/rust/issues/73831> for more information

error: aborting due to 5 previous errors

For more information about this error, try `rustc --explain E0658`.
error: failed to compile `jless v0.7.1`, intermediate artifacts can be found at `/tmp/cargo-installQy5khE`

Caused by:
  could not compile `jless`

To learn more, run the command again with --verbose.

Cheers,
Gus

Scrolling doesn't respond correctly to window resizing

Steps to reproduce

  1. Open a terminal
  2. Pass some data to jless
    • Enough that more than the screen height is needed to display
  3. Resize the height of the window
  4. Scroll to the bottom to observe the active line go off-screen

Info

  • Reproduceable on current main (9ed0cbf)
  • $ uname -a: Linux ai 5.16.11-arch1-2 #1 SMP PREEMPT Mon, 28 Feb 2022 10:17:30 +0000 x86_64 GNU/Linux

Thanks for the great tool, and let me know if you want any more info! I use i3-gaps so resizing windows is pretty common (tiling WM and all)

mouse conflict with terminal copy

Jless is great !

On thing is frustrating to me, I can't manage to copy some text in jless as it seems to take over the mouse.

Is there a way ?

cannot use `C+f/b/d/u` to page up/down

Thank you for your great work! It is really enjoyable.

I found that the movement commands of vim below are not working. Is it an omission or by design?

[Control][b] - Move back one full screen
[Control][f] - Move forward one full screen
[Control][d] - Move forward 1/2 screen
[Control][u] - Move back (up) 1/2 screen

p.s. I know I can use PageUp and PageDown to achieve it but my keyboard doesn't have these keys😅

Cannot use `/` to search when piped.

This tool is glorious!

But, I found a problem. If you pipe info to it, say from an aws cli: aws iam list-instance-profiles | jless for example, I cannot search.

Hitting / immediately exits, which was surprising.

Feature Request: disable single-line previews in Data Mode

Hello,

I find single-line previews of objects and arrays in Data Mode distracting. I'd like Data Mode to look somewhat similar to Line Mode . It would be great to have a flag or command to disable it.

Example:

Current
CleanShot 2022-02-15 at 15 36 40

Proposal
CleanShot 2022-02-15 at 15 36 40 copy

Thanks!

Mass collapsing

Hello! I saw the HN post just now, and I happened to be working on a side project where I've been frequently using jq and less to reference the sample JSON I downloaded for an API I'm using (a frequent pattern of mine that I'm excited to find a new tool for!), and I realized that my preferred usage pattern some of the time would be to have everything start collapsed and then slowly expand fields as I need information about them. I'd love for there to be an option to start with all of the fields collapsed rather than expanded. Alternately (or as well), having a shortcut or command from within the viewer to collapse all of the fields would help me with this; I imagine it might even be reasonable to encode a larger swath of within-editor options as command line flags that just execute those commands when starting up (e.g. jless --collapse-all --search "foo" bar.json).

As an anecdotal point in favor of this sort of functionality, consider that most browser devtools will open the HTML inspector with the elements partially collapsed; even though this is likely due to the fact that the devtools pane will only take up a small part of the screen, it's still likely true that the JSON that this tool is most useful for will tend to be much longer than the number of lines the screen can show at once, as anything smaller than that could be just viewed entirely with cat (and maybe a pipe to something for syntax highlighting).

Immediately redraw the display when terminal window is resized

jless does not immediately redraw the screen when the terminal window is resized; you have to press to key first.

The relevant code is in src/input.rs, which is quite convoluted.

When I originally wrote this code, I had two goals: 1) immediately respond to both keypresses and SIGWINCH (clearly a failure), and 2) do so without busy-looping.

To accomplish this, I tried to setup a pipe to receive the signals and then use poll on that pipe and stdin to respond to the first change from either input.

Along the way there's added complexity because termion's parse_event doesn't detect pure escapes.

I think this is possible, because vim does it, but I'm not totally sure. vim might be doing some busy looping in the background.

Add Windows Support

Placeholder issue for supporting Windows, which I want to do before a 1.0.0 release.

Main pieces of incompatibility are:

  • ANSI escape sequences (I think this mostly solves it? https://github.com/sunshowers-code/enable-ansi-support)
  • Reading keyboard input; macOS and Linux can read from /dev/tty, but I'm not sure what the equivalent is on Windows
  • Responding to changes in terminal size
    • Current code registers a SIGWINCH signal handler, not sure what equivalent is on Windows
    • Current code uses poll to listen for both SIGWINCH / keyboard input

src/input.rs maybe undergo some changes as part of fixing #2.

I don't have immediate access to a Windows machine, and am totally unfamiliar with the Windows terminal/dev environment.

Incorrect installation command for Arch linux

The installation command in the README for Arch linux is pacman -U jless, but jless is not (yet!) in the main arch repositories. The link to the AUR is correct, but the pacman command cannot install from the AUR.

Since using tools like yay/aurman etc. which do install from the AUR are not officially supported by arch, and arch users presumably know how to install from the AUR anyway, I'd recommend just keeping the link, and not giving an installation command, just a message like "Available in the AUR".

Love the tool!

Add an easier way to view long string values

This is neat! One thing though, I tried to use this on JSON data from an API that contains written text in fairly long string values (like a few hundred characters). Inspecting these by scrolling the single truncated line from left to right is very tiring, and there's no way I can find to view these strings in an unescaped form similar to what jq -r .somestringkey does (like replace \n with actual newlines). I'd love to have a shortcut to expand long strings with newlines into their multiline unescaped representation and be able to read them in a more natural way.

0.8.0 requires at least glibc 2.29

I upgraded from 0.7.x (don't remember which one, sorry) to the new 0.8.0 and apparently the binary now refers to some GLIBC_2.28 and GLIBC_2.29 symbols. I'm currently running Linux Mint 19.3 which is based on Ubuntu 18.04 using glibc 2.27 so 0.8.0 doesn't run there.

I realize this is a rather old distro but it's still supported until April 2023 because it was an LTS release.

I'll let you decide whether you still can/want to support this. No hard feelings if you don't and an extra incentive for me to upgrade 😄

Copy full path of specific element(s) ?

After drilling down to a specific value, is it possible to copy the full path of that value? I can see it on the status line, but I can't see how you can extract the full path.

tree view

One cool idea from a similar tool (jsonui) is that of a tree-view so you can see top-level keys at a glance.

No idea if this is desirable or feasible for jless, just figured an idea for the project going forward.

cargo build fail on M1 Mac Rust

I got a error on cargo build:

% sudo cargo install jless
... snip ...
error[E0658]: or-patterns syntax is experimental
   --> /Users/user1/.cargo/registry/src/github.com-1ecc6299db9ec823/jless-0.7.1/src/app.rs:101:26
    |
101 |                 KeyEvent(Key::Ctrl('c') | Key::Char('q')) => break,
    |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: see issue #54883 <https://github.com/rust-lang/rust/issues/54883> for more information
error[E0658]: or-patterns syntax is experimental
  --> /Users/user1/.cargo/registry/src/github.com-1ecc6299db9ec823/jless-0.7.1/src/jsonparser.rs:67:24
   |
67 |         while let Some(JsonToken::Whitespace | JsonToken::Newline) = self.peek_token_or_eof() {
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #54883 <https://github.com/rust-lang/rust/issues/54883> for more information
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0658`.
error: failed to compile `jless v0.7.1`, intermediate artifacts can be found at `/tmp/cargo-installoCXkLq`
Caused by:
  could not compile `jless`
To learn more, run the command again with --verbose.

How can I build this? Thank you for your help.

binary name

Hi,

As you already know I've imported a package into pkgsrc.
During the night I got an e-mail from Japan pointing out that the command name conficts with the existing Japanease version of less.

I need to rename the resulting binary during installation, which is no big deal but, thought I'd ask if you have any preferences regarding the name.

Korean not supported

Hi, I use Korean (ko_kr) but seems that jless doesn't support this language.
given:

echo '{"hello":"헬로"}' | jless

expected:

{"hello":"헬로"}

result:

{"hello":"<ED><97><AC><EB><A1><9C>"}

Releases

Hello, thanks for making this! Can you please release one of the versions? Currently they're pre-release, and, as such, some tools and binary managers skip them when considering what to install. What's worse, they aren't even pre-release, as they are the actual versions. The pre-release is meant for things like 0.8.0-rc2, for example, which should legitimately not be upgraded to automatically.

Screen flickers when fast scrolling

Operating system:

Ubuntu 20.04 (WSL2)

Terminal:

Windows Terminal

Steps to reproduce:

  1. Run curl -s https://jsonplaceholder.typicode.com/todos/ | jless
  2. Hold the down key

Additional notes

I think this happens because the whole screen is cleared before each redraw instead of clearing lines as needed.

Ignore comments in JSON with comments file

JSON with comments file cannot be open now. The program simply shows Unable to parse input: "Parse error" and exits.

A JSON with comments file may look like this:

// This is a JSON with comments file
{
  "a": [
      1 // A single line comment
  ]
}

CSI Excapes not handled by termion cause panic

Some valid escape sequences like shift+right (1;2C) are not properly parsed by termion and therefore return an Err result. This causes a panic in the input loop of App.run, which unwraps the event variable yielded by the input iterator.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.