ronisbr / TerminalPager.jl

Pure Julia implementation of the command less
MIT License
116 stars 8 forks source link

show(df) |> pager not working #13

Closed ufechner7 closed 3 years ago

ufechner7 commented 3 years ago

The following code is not working correctly:

using DataFrames, TerminalPager

arr=Float32[-2.60913f-19, 82.7852, 165.38, 247.703, 329.633, 410.999, 491.576]

df1 = DataFrame(time_rel=[0.1,0.2,0.3,0.4], X = [arr, arr, arr, arr])
show(df1, truncate=100) |> pager

The output is:

nothing

:

Any idea?

ronisbr commented 3 years ago

Hi @ufechner7

The problem is that show prints in stdout instead of returning a value. Thus, pager receives nothing, which is returned by show. I need to think how to make this easier (maybe I will create a macro...). Until then, you need to convert to string manually if you want to print Data Frames using custom options:

julia> sprint(io->(show(io, df1, truncate = 100)), context = :color => true) |> pager
ronisbr commented 3 years ago

Until I find a better solution, I think I add a "OK" feature to accomplish this. Now we have a macro @stdout_to_pager that shows the stdout output inside a pager. Hence, you can do:

julia> @stdout_to_pager show(df, truncate = 1000)

It works with any function that prints to stdout.

julia> @stdout_to_pager for i = 1:1000
println(i)
end