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

"autoview", tables, new data formats... #1371

Open
dumblob opened this issue Jul 14, 2021 · 6 comments
Open

"autoview", tables, new data formats... #1371

dumblob opened this issue Jul 14, 2021 · 6 comments

Comments

@dumblob
Copy link

dumblob commented Jul 14, 2021

It seems Elvish has a rather simlistic data types and thus also rather "raw" pretty printing.

Here I'd like to ask for opinions on something like Nushell does - namely it automatically inserts | autoview (interactive pretty printing with scrollbars, graphics support etc.) if there is no sink at the end of a pipeline. Moreover Nushell supports arbitrarily nested data types incl. nested tables of plenty of other data types.

I'd like to see this richer set of data types along with advanced "pretty printing" in Elvish. Any plans for that?

Somewhat related to pretty printing: #1149 (comment)

@krader1961
Copy link
Contributor

FYI, Elvish supports nested data structures. Here I define a map that contains two keys: l's value is a list and m's value is a map with two keys:

> var m = [&l=[1 2 3] &m=[&k1=v1 &k2=v2]]
> pprint $m
[
 &l=	[
   1
   2
   3
  ]
 &m=	[
   &k1=	v1
   &k2=	v2
  ]
]

@dumblob
Copy link
Author

dumblob commented Jul 14, 2021

Sure, that part was clear - sorry for my writing (I first wrote tables, but that'd imply no nesting in a colloquial understanding which wouldn't be true in case of Nushell, so I've added the mention of nesting).

Actually what autoview command in Nushell seems to do is to try hard to come up with two axis and then render data accordingly. This often resembles a table or a row vector or a column vector (with artificial names of columns & rows - but wait, these artificial names can then be also used to refer to them!) with cells showing the data (if it's a scalar) or a syntax how to access the given cell if it's a composite (i.e. nested) structure - often another table 😉.

So as an example JSON (a generic tree structure) can be easily visualized as a table (with nested structures in cells) 😮 - but it feels so intuitive despite it's not a table but a tree.

@krader1961
Copy link
Contributor

@dumblob, I don't see how arbitrary data structures, such as in my previous example, can be meaningfully displayed as a table. The first Nushell documentation link I looked at, which documents the autoview command, does not include an example of what you are proposing. Can you share some links that show the behavior you want from Elvish?

I'm also ambivalent about automatically appending the equivalent of | autoview to any pipeline I run interactively. You wrote "if there is no sink at the end of a pipeline" but I consider my terminal's handling of anything written to it to be that byte stream sink. In no small part because the output might contain terminal escape sequences that affect the appearance of the data. If I want the data to be translated in some way before the terminal renders it I expect to have to explicitly transform the data. Such as by piping it through pprint. I'm uncomfortable with that being done implicitly, but then I started programming when dinosaurs roamed the Earth. 😄

@dumblob
Copy link
Author

dumblob commented Jul 19, 2021

@dumblob, I don't see how arbitrary data structures, such as in my previous example, can be meaningfully displayed as a table. The first Nushell documentation link I looked at, which documents the autoview command, does not include an example of what you are proposing. Can you share some links that show the behavior you want from Elvish?

It's scattered throughout Nutshell's (highly unfinished) documentation. Feel free to read it all (yeah, sounds weird, but I can't explain it better as I'd need to copy past large part of it - it's the same problem as explaining user experience of some moderately advanced GUI).

I'm also ambivalent about automatically appending the equivalent of | autoview to any pipeline I run interactively. You wrote "if there is no sink at the end of a pipeline" but I consider my terminal's handling of anything written to it to be that byte stream sink. In no small part because the output might contain terminal escape sequences that affect the appearance of the data. If I want the data to be translated in some way before the terminal renders it I expect to have to explicitly transform the data. Such as by piping it through pprint. I'm uncomfortable with that being done implicitly, but then I started programming when dinosaurs roamed the Earth.

In my opinion this stems from the fact Nushell is not trying to be a shell for a terminal but a shell on its own (i.e. without any terminal dependency). Classical terminal (e.g. VT100) is for Nushell just one of many possible "gateways" conceptual-wise (not necessarily technical-wise).

So I think it's really about the mind shift between "more piping and less programming" (Nushell) and "more programming less piping" (Elvish). I'm too new to Elvish to make more claims or observations - I'm just exploring the options I have with Elvish and speaking up lound while I'm at it 😉.

@ilius
Copy link

ilius commented Jan 8, 2022

Nushell is not as Unix-friendly as common Unix shell (bash, zsh, sh, etc) or Evlish (as far as I understand), but rather tries to choose a common between Unix shells and Windows PowerShell IMO.

For example, when the output is a table, the entire table is loaded into a list/array in memory, then either printed as a table, or passed down to the next command in the pipe.
I think that's somewhat against the Unix philosophy.

That being said, the flexibility it offers for dealing with tables is astonishing.
It allows inserting/removing/re-ordering/modifying columns, or filtering rows in various way.

I think the reason it automatically and implicitly does | autoview is because rows are not just lines of bytes (except maybe for external commands that don't give a table) so it needs to convert it to string/bytes somehow.

Here is an example of playing with a table:

(nu) elvish $ ls | where size > 3kb | select name size modified | insert mtime {each {echo $it.modified | date format %s}}
───┬─────────────────────────┬────────┬──────────────┬────────────
 # │          name           │  size  │   modified   │   mtime    
───┼─────────────────────────┼────────┼──────────────┼────────────
 0 │ 0.17.0-release-notes.md │ 3.1 KB │ 10 hours ago │ 1641595430 
 1 │ CONTRIBUTING.md         │ 6.1 KB │ 10 hours ago │ 1641595430 
 2 │ PACKAGING.md            │ 4.7 KB │ 20 hours ago │ 1641562116 
 3 │ README.md               │ 3.6 KB │ 20 hours ago │ 1641562116 
 4 │ cmd                     │ 4.1 KB │ 20 hours ago │ 1641562116 
 5 │ pkg                     │ 4.1 KB │ 20 hours ago │ 1641562116 
 6 │ tools                   │ 4.1 KB │ 10 hours ago │ 1641595430 
 7 │ website                 │ 4.1 KB │ 10 hours ago │ 1641595430 
───┴─────────────────────────┴────────┴──────────────┴────────────

@ilius
Copy link

ilius commented Jan 8, 2022

I have wrote a bunch of functions (and a plugin in Python) for nushell here:
https://github.com/ilius/nu-addons

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

No branches or pull requests

3 participants