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

feature request: abbreviated truncated views #38

Open
brewingcode opened this issue Feb 16, 2022 · 2 comments · May be fixed by #40
Open

feature request: abbreviated truncated views #38

brewingcode opened this issue Feb 16, 2022 · 2 comments · May be fixed by #40
Labels
Feature Request New feature or request

Comments

@brewingcode
Copy link

brewingcode commented Feb 16, 2022

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.

@brewingcode brewingcode linked a pull request Feb 16, 2022 that will close this issue
@ducaale
Copy link

ducaale commented Feb 18, 2022

Since the count might be confused with an actual value, what if you appended items to the counts?

[
  {
    "sha": "cdcb02038730f0cd3f5ccea594511e3cfb37887a",
    "node_id": "C_kwDOFYWjXtoAKGNkY2IwMjAzODczMGYwY2QzZjVjY2VhNTk0NTExZTNjZmIzNzg4N2E",
    "commit": { 7 items },
    "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 item },
    "committer": { 18 items },
    "parents": [ 1 item ] // <---- without 'item', it would be easy to confuse it with a value 
  },
  { 9 items },
  { 9 items },
  { 9 items },
  { 9 items },
  { 9 items },
  { 9 items },

Another approach would be to show the count next to the braces e.g

[
  {
    "sha": "cdcb02038730f0cd3f5ccea594511e3cfb37887a",
    "node_id": "C_kwDOFYWjXtoAKGNkY2IwMjAzODczMGYwY2QzZjVjY2VhNTk0NTExZTNjZmIzNzg4N2E",
    "commit": { … }, // 7 items
    "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": { … }, // 1 item
    "committer": { … }, // 18 items
    "parents": [ … ] // 1 item
  },
  { … }, // 9 items
  { … }, // 9 items
  { … }, // 9 items
  { … }, // 9 items
  { … }, // 9 items
  { … }, // 9 items

The latter approach is how the JSON Formatter extension for chrome handles collapsed nodes.

@brewingcode
Copy link
Author

brewingcode commented Feb 18, 2022

Hmmm, I initially didn't like the added busy-ness of having "items" all over the place, and also the terminal coloring makes it very clear what is a preview and what is not. But I don't like assuming terminal coloring will fix everything, and I did stumble across one case where it is ambiguous without terminal coloring, and that's in line mode, which renders collapsed arrays as previews on a single line:

        },
        "geometry": {
          "type": "Point",
          "coordinates": [ 3 ]
        }
      },

So I'll add "item"/"items". Good suggestion, thanks @ducaale.

In fact, since line mode relies on single-line previews, I've disabled Preview::None in line mode, too. Otherwise, collapsed nodes in line mode show nothing, which is super bad:

        },
        "geometry": {
          "type": "Point",
          "coordinates":            // nothing here, oops
        }

@PaulJuliusMartinez PaulJuliusMartinez added the Feature Request New feature or request label Jun 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants