Hi!
I just tag a new version of PrettyTables.jl (v1.2.2) and I would like to point out an amazing work done by @lorenzoh (GitHub, I am not sure if he is here in Discourse). He had an idea to use CustomTextCell
so that we can have cells with ANSI escape sequences. Thus, we can now display anything inside a text cell composed of text and ANSI escape sequences (only those that change the decoration).
Hence, we can now create complex tables using PrettyTables to render tables inside cells:
julia> using PrettyTables
julia> sc1 = [7.4 73.5; 3.1 27.2; 2.5 15.6; 1.8 9.0];
julia> sc2 = [7.4 73.5; 3.1 27.2; 2.5 15.6; 1.8 9.0];
julia> case = ["< 5000", "5000 - 10000", "10000 - 15000", "> 15000"];
julia> str_sc1 = pretty_table(String, sc1, header = ["avg.", "max"], color = true, hlines = [:header], vlines = :none, newline_at_end = false, highlighters = hl_row(4, crayon"bold red"));
str
julia> str_sc2 = pretty_table(String, sc2, header = ["avg.", "max"], color = true, hlines = [:header], vlines = :none, newline_at_end = false, highlighters = hl_row(4, crayon"bold red"));
julia> str_case = pretty_table(String, case, header = [" "], color = true, hlines = [:header], vlines = :none, tf = tf_borderless, newline_at_end = false);
julia> table = [AnsiTextCell(str_case) AnsiTextCell(str_sc1) AnsiTextCell(str_sc2)];
We can also add plots inside the table cells using UnicodePlots:
julia> using PrettyTables, UnicodePlots
julia> str_pop = sprint(io -> show(io, barplot(
["", "", ""],
[12.396, 6.748, 0.729]
)), context = :color => true);
julia> str_idh = sprint(io -> show(io, barplot(
["", "", ""],
[0.805, 0.799, 0.807]
)), context = :color => true);
julia> table = ["\nSão Paulo\nRio de Janeiro\nSão José dos Campos" AnsiTextCell(str_pop) AnsiTextCell(str_idh)];
julia> pretty_table(table, header = ["", "Population (in mil.)", "IDH"], alignment = :l, header_alignment = :c, linebreaks = true, vlines = :none, hlines = [:header])