FedeClaudi / Term.jl

Julia library for stylized terminal output
MIT License
447 stars 37 forks source link

Request: support DataFrame directly with Table #239

Open nathanrboyer opened 7 months ago

nathanrboyer commented 7 months ago

I thought that I could make a Term.Table out of a DataFrame directly since DataFrames conform to the Tables.jl interface. However, it did not work, and I have to manually redefine the header after converting.

julia> using DataFrames, Term

julia> table = DataFrame(x = 1:3, y = ["A","B","C"])
3×2 DataFrame
 Row │ x      y      
     │ Int64  String 
─────┼───────────────
   1 │     1  A
   2 │     2  B
   3 │     3  C

julia> Term.Table(
           table,
           style="red",
       )
ERROR: MethodError: no method matching Term.Tables.Table(::DataFrame; style::String)

julia> Term.Table(
           Matrix(table),
           style="red",
       )
            ╷
   Column1  │  Column2  
╺━━━━━━━━━━━┿━━━━━━━━━━━╸
      1     │     A
╶───────────┼───────────╴
      2     │     B
╶───────────┼───────────╴
      3     │     C
FedeClaudi commented 5 months ago

That would be nice to have - if anyone wants to submit a PR for it I'd be happy to add it.