[ANN] Announcing TerminalPager.jl

Hi!

After developing PrettyTables.jl, I understood how hard is to design cropping mechanism to show large data into the terminal. We did have a “nice” algorithm, but with some caveats. For example, it is not that easy to crop the table in the middle of the columns. Thus, PrettyTables.jl always crop columns at the end.

Recently, there was a request on Slack (Jerry Ling) to add a way to break the table, printing the columns that does not fit sequentially. However, it would be very, very difficult to do due to corner cases.

That’s why I decided to make a small package trying to replicate the command less. This is 100% written in Julia and should work in all platforms (at least in terminals that support the standard escape sequences).

This new package is called TerminalPager.jl and should fix those problems letting the user to scroll through the table:

Gravação de Tela 2021-04-18 às 16.28.364

(The recording used the old name Less.jl)

68 Likes

Maybe TerminalPager.jl?

The Less.jl link isn’t working for me.

May I request respecting

  • common keybindings of Vim and Emacs like less does
  • the LESS environment variable
  • the .lesskey configuration file
2 Likes

Sorry, I updated the link.

Yes, I think we can go with TerminalPager.jl :slight_smile: it makes sense! Thanks for your suggestion.

Thanks also for the feature requests. Yes, my idea is to add features to match those in less (like search for example).

1 Like

I would prefer Less, and using it as

using Less
df |> less

and of course it would be great as replacement for @less or perhaps usable as

@less sum(a) |> less

Now forgot to say: GREAT, i missed it for a long time. THANK YOU!

2 Likes

Thanks! Let’s hope it can be useful for the community :slight_smile:

The problem of using less as a function name is that less is already a function in Julia.

Also, what less means is usually only clear to some Unix users. The others will find the name very confusing and hard to search

4 Likes

Good point! I will rename to TerminalPager.jl and add a TerminalPager.less function :smiley:

1 Like

Done, everything is fine now. Thank everyone for the suggestions! The package should be merged in three days. If anyone wants to test it before, just do:

julia>]add https://github.com/ronisbr/TerminalPager.jl

julia> using TerminalPager

julia> rand(10,100) |> TerminalPager.less

P.S.: I tested in Windows 10. It seems to work but with terrible performance. However, it could be caused by the virtual machine I was using. Feedback is appreciated!

Maybe pager() instead of TerminalPager.less()

4 Likes

I just add both for now :slight_smile:

1 Like

less(file::AbstractString, [line::Integer])

Show a file using the default pager

Than let me set

TerminalPager.less

as the default pager :slight_smile:

1 Like

Wow this is great. Very often I find myself needing View(df) from R which pop’s up the Table in a GUI/cell format. This is a good replacement in Julia REPL. Could it be possible to add a GUI/HTML so it can also work like R’s View(df)?

2 Likes

Thanks! I think it is better to keep this package to terminal only. My plan is to add it as a dependency of PrettyTables.jl to help showing large data. Hence, if we add a lot of things, then the loading time can be bad. However, we can create another package, something like GraphicalPager / Viewer or something.

The problem is that for GUI you need to find a good toolkit that can easily work along all the platforms. This can be challenging and, unfortunately, I do not have much expertise (creating GUIs using Julia).

2 Likes

Gtk.jl works on some platforms.

1 Like

FloatingTableView.jl does exactly this! with View in mind. (Though the function is called browse like in Stata)

6 Likes

Nice! I did not know about this package, very good :slight_smile:

An awesome use for this pacakge would be for long docstrings. I’ve often wanted ? pretty_table or ? transform to be in a scrollable thing that doesn’t clutter my REPL.

Ill see if I can work on something about that.

4 Likes

You can use it right now! It just a little cumbersome to call the documentation in the current state:

julia> Base.Docs.doc(pretty_table) |> TerminalPager.less

P.S.: The ideia to use this together with the docs is just awesome! Thanks for pointing this out :slight_smile:

EDIT: A more short version @doc(pretty_table) |> TerminalPager.less

10 Likes

Tried TerminalPager.jl in Julia 1.6.0 Win10 (REPL + VS Code terminal) and in Debian REPL in Android.

Performance is very good everywhere but cannot retrieve the advertised behaviors:

  • Do not see the row numbers on the left of the terminal nor the column numbers at the top

  • The SHIFT + left / right arrows seem to move only by 1 column, instead of 10 (while SHIFT + up/down do move by 5 rows OK)

Thanks for the great stuff!

NB: would much prefer using this nice functionality as part of PrettyTables.jl

1 Like

Nice! Good to know, I do not have any linux machine right now to test. Thanks for letting me know.

The pager does not add any content to the string. This information comes from DataFrames.

Hum, we will have a lot of problems with those key codes. This can be related to VS code terminal not passing the correct escape codes for some reason. Can you test in a terminal please?

Thanks! Let’s hope it can be useful :slight_smile:

That’s the idea! Add this package as a dependency to PrettyTables and have an option crop = :less or something.

3 Likes