Skip to content

Commit c5d8261

Browse files
committed
feat: Add PalmerPenguins example ✨
1 parent 302726e commit c5d8261

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

Project.toml

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
2222
Crayons = "4"
2323
Crossterm = "0.5"
2424
InlineTest = "0.2"
25-
KiwiConstraintSolver = "1"
2625
LoggingExtras = "1"
2726
LoggingFormats = "1"
2827
ReTest = "0.3"

examples/Project.toml

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
[deps]
2+
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
23
PalmerPenguins = "8b842266-38fa-440a-9b57-31493939ab85"
4+
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
35
TerminalUserInterfaces = "408767e4-586b-40c7-9657-f9758988469a"

examples/dataframe.jl

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using TerminalUserInterfaces
2+
const TUI = TerminalUserInterfaces
3+
using DataFrames
4+
using PalmerPenguins
5+
using Tables
6+
7+
@kwdef mutable struct Model <: TUI.Model
8+
df = DataFrame(PalmerPenguins.load())
9+
quit = false
10+
end
11+
12+
function TUI.view(m::Model)
13+
columnnames = Tables.columnnames(Tables.columns(m.df))
14+
N = length(columnnames)
15+
header = TUI.Row(; data = [TUI.Datum(; content = string(col)) for col in columnnames])
16+
rows = map(Tables.rows(m.df)) do row
17+
TUI.Row(; data = [TUI.Datum(; content = string(item)) for item in row])
18+
end
19+
widths = [TUI.Percent(100 ÷ N) for _ in 1:N]
20+
TUI.Table(; rows, widths, header)
21+
end
22+
23+
function TUI.update!(m::Model, evt::TUI.KeyEvent)
24+
if TUI.keypress(evt) == "q"
25+
m.quit = true
26+
end
27+
end
28+
29+
function main()
30+
TUI.app(Model())
31+
end
32+
33+
main()
34+

src/TerminalUserInterfaces.jl

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using TextWrap
77
using Unicode
88
using InlineTest
99
using KiwiConstraintSolver
10+
using Tables
1011

1112
export Terminal
1213

src/widgets/table.jl

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ end
1111

1212
total_height(row::Row) = row.height + row.bottom_margin
1313

14-
1514
@kwdef mutable struct TableState
16-
offset::Int
17-
selected::Union{Int,Nothing}
15+
offset::Int = 1
16+
selected::Union{Int,Nothing} = nothing
1817
end
1918

2019
@kwdef struct Table
2120
rows::Vector{Row}
2221
widths::Vector{Constraint}
23-
state::TableState = TableState(; offset = 1, selected = nothing)
22+
state::TableState = TableState()
2423
block::Union{Nothing,Block} = Block()
2524
style::Crayon = Crayon()
2625
column_spacing::Int = 0

0 commit comments

Comments
 (0)