# How to combine prettytables and pager?

**URL:** <https://discourse.julialang.org/t/how-to-combine-prettytables-and-pager/85593>\
**Category:** General Usage\
**Tags:** dataframes, prettytables, inmemorydatasets, terminalpager\
**Created:** [August 10, 2022, 7:18pm UTC](https://discourse.julialang.org/t/how-to-combine-prettytables-and-pager/85593 "2022-08-10T19:18:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 10, 2022, 7:18pm UTC](https://discourse.julialang.org/t/how-to-combine-prettytables-and-pager/85593/1 "2022-08-10T19:18:55Z")

</div>

When using prettytables I have a lot of keyword options that I can use to display a pretty table. With the function pager from TerminalPager I can browse through a dataset that does not fit on the screen. How can I combine both?

Example:

```julia-auto
using InMemoryDatasets, TerminalPager

function demo_data()
    n = 100
    m = 8
    time = 0.1:0.1:n*0.1
    addr = rand(Int16(0x101):Int16(0x12e), n)
    data = (Symbol("d", i) => rand(UInt8, n) for i in 1:m)
    ds = Dataset(;time, addr, data...)
    ds.addr[5] = missing
    ds
end
ds = demo_data()

```

Working:

```julia-auto
pager(ds, frozen_rows=2)

```

also

```julia-auto
show(ds, show_row_number=false, eltypes=false)

```

Not working:

```julia-auto
pager(ds, frozen_rows=2, show_row_number=false, eltypes=false)

```

Any idea?

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [August 11, 2022, 3:15am UTC](https://discourse.julialang.org/t/how-to-combine-prettytables-and-pager/85593/2 "2022-08-11T03:15:29Z")

</div>

I’m not familiar with `InMemoryDatasets` but with `DataFrames` (I assume similar) you can do:

```julia
using DataFrames, TerminalPager

n = 100
m = 8
data = (Symbol("d", i) => rand(UInt8, n) for i in 1:m)
ds = DataFrame(collect(data))

io = IOBuffer();
show(io, ds, show_row_number=false, eltypes=false)
pager(String(take!(io)), frozen_rows=2)

```

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 11, 2022, 6:00am UTC](https://discourse.julialang.org/t/how-to-combine-prettytables-and-pager/85593/3 "2022-08-11T06:00:43Z")

</div>

Thanks! Works nicely!

But there is one little thing missing: When I type

```julia
ds

```

in your example the header is highlighted, but the highlighting is not shown when using the pager like

```julia
pager(String(take!(io)), frozen_rows=2)

```

If I do `pager(ds)` the header also highlighted.

How can I achieve that highlighting is preserved when combining show and pager?

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [August 11, 2022, 6:41am UTC](https://discourse.julialang.org/t/how-to-combine-prettytables-and-pager/85593/4 "2022-08-11T06:41:52Z")

</div>

Replace the last three lines with:

```julia
io = IOContext(IOBuffer(), :color => true);
show(io, ds, show_row_number=false, eltypes=false)
pager(String(take!(io.io)), frozen_rows=2)

```

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 11, 2022, 7:44am UTC](https://discourse.julialang.org/t/how-to-combine-prettytables-and-pager/85593/5 "2022-08-11T07:44:11Z")

</div>

Using this function now:

```julia
function browse(ds)
    io = IOContext(IOBuffer(), :color => true);
    show(io, ds, show_row_number=false, eltypes=false)
    pager(String(take!(io.io)), frozen_rows=3)
end

```

Works perfectly! Thank you!
