Term.jl
Term.jl copied to clipboard
Request: support `TextBox` and `RenderableText` in `@nested_panels`
@nested_panel
works well with panels:
julia> using Faker, Term
julia> panel = @nested_panels Panel(
Panel(
@red(Faker.text()),
style="red",
),
Panel(
@green(Faker.text()),
style="green",
),
style = "cyan",
justify = :center
)
╭────────────────────────────────────────────────────────────────────────────────────────╮
│ ╭──────────────────────────────────────────────────────────────────────────────────╮ │
│ │ Voluptates ipsum et consequatur est. Iste quaerat ea est. Ducimus qui quisqua │ │
│ │ m. Numquam. In animi. Qui. Fugiat quia necessitatibus mollitia sed aut. │ │
│ │ Ex voluptatem. Vel quo perferendis autem. Vel placeat voluptate omnis. │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────╯ │
│ ╭──────────────────────────────────────────────────────────────────────────────────╮ │
│ │ Ut accusamus voluptatem maxime. Dolor debitis dolores dignissimos dolorum │ │
│ │ praesentium. Omnis. Omnis ea commodi rerum distinctio voluptas. Maiores │ │
│ │ dolore nostrum qui voluptas modi. Iusto. Pariatur nobis quas. │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────╯ │
╰────────────────────────────────────────────────────────────────────────────────────────╯
But it does not work well with other text renderables:
julia> panel = @nested_panels Panel(
Panel(
@red(Faker.text()),
style="red",
),
TextBox(
@green(Faker.text()),
style="green",
),
style = "cyan",
justify = :center
)
╭────────────────────────────────────────────────────────────────────────────────────────╮
│ ╭────────────────────────────────────────────────────────────────────────────────── │
│ ╮ │
│ │ Nam. Expedita ut quae debitis laboriosam. Aut modi eos nihil nulla omnis. │
│ │ │
│ │ Et tenetur. Nostrum laborum ut ut. Aliquam sequi asperiores eum. Itaque │
│ │ │
│ │ et quia totam veritatis. Repellat tempora. Aspernatur. Architecto. │
│ │ │
│ ╰────────────────────────────────────────────────────────────────────────────────── │
│ ╯ │
│ │
│ │
│ Temporibus voluptatem et. Vitae aliquam iste voluptatem eos. Eligendi sapiente │
│ │
│ recusandae architecto illo. Quae id officia at culpa ut. Qui nesciunt. Laborum │
│ │
│ aliquam in explicabo quibusdam eos. Nostrum aperiam ad neque. │
│ │
│ │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────╯
julia> panel = @nested_panels Panel(
Panel(
@red(Faker.text()),
style="red",
),
RenderableText(
@green(Faker.text()),
style="green",
),
style = "cyan",
)
╭────────────────────────────────────────────────────────────────────────────────────────╮
│ ╭────────────────────────────────────────────────────────────────────────────────── │
│ ╮ │
│ │ Nostrum et saepe eveniet. Distinctio aut recusandae sed vero velit. In sint │
│ │ │
│ │ voluptas perferendis qui enim. Unde ducimus blanditiis natus. Harum. Quisquam │
│ │ │
│ │ repudiandae commodi. Consequatur voluptatem quam. Cupiditate. │
│ │ │
│ ╰────────────────────────────────────────────────────────────────────────────────── │
│ ╯ │
│ Aut. Tempore. Quia veritatis distinctio. Doloremque quos voluptatem illo. Delectus │
│ sit │
│ veritatis consequatur nesciunt. Eum quasi voluptatem quia in. Ut libero dolores │
│ earum │
│ libero. Sit. Voluptas. Ducimus necessitatibus magnam illum accusamus dolores. │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────╯
My use case is to add footnotes to a table:
julia> ASME_Materials.tableKM620_options()
╭──── Table KM-620 Material Categories ───────────────────────────────────╮
│ ╭────────────┬──────────────────────────────────────────────────────╮ │
│ │ Category │ Material │ │
│ ├────────────┼──────────────────────────────────────────────────────┤ │
│ │ 1 │ Ferritic steel │ │
│ ├────────────┼──────────────────────────────────────────────────────┤ │
│ │ 2 │ Austenitic stainless steel and nickel-based alloys │ │
│ ├────────────┼──────────────────────────────────────────────────────┤ │
│ │ 3 │ Duplex stainless steel │ │
│ ├────────────┼──────────────────────────────────────────────────────┤ │
│ │ 4 │ Precipitation hardening, nickel based │ │
│ ├────────────┼──────────────────────────────────────────────────────┤ │
│ │ 5 │ Aluminum │ │
│ ├────────────┼──────────────────────────────────────────────────────┤ │
│ │ 6 │ Copper │ │
│ ├────────────┼──────────────────────────────────────────────────────┤ │
│ │ 7 │ Titanium and zirconium │ │
│ ╰────────────┴──────────────────────────────────────────────────────╯ │
│ ╭──── Note: ────────────────────────────────────────────────────────╮ │
│ │ (1) Ferritic steel includes carbon, low alloy, and alloy │ │
│ │ steels, and ferritic, martensitic, and iron-based age-hardenin │ │
│ │ g stainless steels. │ │
│ ╰───────────────────────────────────────────────────────────────────╯ │
╰─────────────────────────────────────────────────────────────────────────╯
function tableKM620_options()
table = select(KM620.coefficients_table, "Material")
notes = join(values(metadata(KM620.coefficients_table)), "\n")
panel = @nested_panels Panel(
Term.Table(
hcat(1:nrow(table), table."Material"),
header = ["Category", "Material"],
header_style = "cyan",
columns_justify = [:center, :left],
columns_style = "default",
box = :ROUNDED,
style = "cyan",
),
Panel(
@style(notes, "cyan dim"),
style = "cyan dim",
title = "Note:",
title_style = "cyan dim",
),
title = "Table KM-620 Material Categories",
title_style = "cyan",
style = "cyan",
)
return panel
end
I cannot get it to look nice without the Panel
:
julia> ASME_Materials.tableKM620_options2()
╭──── Table KM-620 Material Categories ───────────────────────────────────╮
│ ╭────────────┬────────────────────────────────────────────────────── │
│ ╮ │
│ │ Category │ Material │
│ │ │
│ ├────────────┼────────────────────────────────────────────────────── │
│ ┤ │
│ │ 1 │ Ferritic steel │
│ │ │
│ ├────────────┼────────────────────────────────────────────────────── │
│ ┤ │
│ │ 2 │ Austenitic stainless steel and nickel-based alloys │
│ │ │
│ ├────────────┼────────────────────────────────────────────────────── │
│ ┤ │
│ │ 3 │ Duplex stainless steel │
│ │ │
│ ├────────────┼────────────────────────────────────────────────────── │
│ ┤ │
│ │ 4 │ Precipitation hardening, nickel based │
│ │ │
│ ├────────────┼────────────────────────────────────────────────────── │
│ ┤ │
│ │ 5 │ Aluminum │
│ │ │
│ ├────────────┼────────────────────────────────────────────────────── │
│ ┤ │
│ │ 6 │ Copper │
│ │ │
│ ├────────────┼────────────────────────────────────────────────────── │
│ ┤ │
│ │ 7 │ Titanium and zirconium │
│ │ │
│ ╰────────────┴────────────────────────────────────────────────────── │
│ ╯ │
│ │
│ │
│ Notes: │
│ │
│ (1) Ferritic steel includes carbon, low alloy, and alloy steels, │
│ │
│ and ferritic, martensitic, and iron-based age-hardening stainless │
│ │
│ steels. │
│ │
│ │
│ │
╰─────────────────────────────────────────────────────────────────────────╯
function tableKM620_options2()
table = select(KM620.coefficients_table, "Material")
notes = "Notes:\n" * join(values(metadata(KM620.coefficients_table)), "\n")
panel = @nested_panels Panel(
Term.Table(
hcat(1:nrow(table), table."Material"),
header = ["Category", "Material"],
header_style = "cyan",
columns_justify = [:center, :left],
columns_style = "default",
box = :ROUNDED,
style = "cyan",
),
TextBox(
@style(notes, "cyan dim"),
),
title = "Table KM-620 Material Categories",
title_style = "cyan",
style = "cyan",
)
return panel
end
(Also in the last example, the styling is only applied to the first line of the TextBox
.)
Hi,
Thanks for reaching out. Unfortunately at the moment I don’t have the bandwidth to keep development work for Term.jl though. I’d you’d like to send a PR though I can review and approve that. I hope this helps.
Sent from Proton Mail for iOS
On Thu, Feb 15, 2024 at 15:39, Nathan Boyer @.***(mailto:On Thu, Feb 15, 2024 at 15:39, Nathan Boyer < wrote:
My use case is to add footnotes to a table:
julia
ASME_Materials
.
tableKM620_options
() ╭──── Table KM
620
Material Categories ───────────────────────────────────╮ │ ╭────────────┬──────────────────────────────────────────────────────╮ │ │ │ Category │ Material │ │ │ ├────────────┼──────────────────────────────────────────────────────┤ │ │ │
1
│ Ferritic steel │ │ │ ├────────────┼──────────────────────────────────────────────────────┤ │ │ │
2
│ Austenitic stainless steel and nickel
based alloys │ │ │ ├────────────┼──────────────────────────────────────────────────────┤ │ │ │
3
│ Duplex stainless steel │ │ │ ├────────────┼──────────────────────────────────────────────────────┤ │ │ │
4
│ Precipitation hardening, nickel based │ │ │ ├────────────┼──────────────────────────────────────────────────────┤ │ │ │
5
│ Aluminum │ │ │ ├────────────┼──────────────────────────────────────────────────────┤ │ │ │
6
│ Copper │ │ │ ├────────────┼──────────────────────────────────────────────────────┤ │ │ │
7
│ Titanium and zirconium │ │ │ ╰────────────┴──────────────────────────────────────────────────────╯ │ │ ╭──── Note
:
────────────────────────────────────────────────────────╮ │ │ │ (
1
) Ferritic steel includes carbon, low alloy, and alloy │ │ │ │ steels, and ferritic, martensitic, and iron
based age
hardenin │ │ │ │ g stainless steels. │ │ │ ╰───────────────────────────────────────────────────────────────────╯ │ ╰─────────────────────────────────────────────────────────────────────────╯
function
tableKM620_options
() table
=
select
(KM620
.
coefficients_table,
"
Material
"
) notes
=
join
(
values
(
metadata
(KM620
.
coefficients_table)),
"
\n
"
) panel
=
@nested_panels
Panel
( Term
.
Table
(
hcat
(
1
:
nrow
(table), table.
"
Material
"
), header
=
[
"
Category
"
,
"
Material
"
], header_style
=
"
cyan
"
, columns_justify
=
[
:center
,
:left
], columns_style
=
"
default
"
, box
=
:ROUNDED
, style
=
"
cyan
"
, ),
Panel
(
@style
(notes,
"
cyan dim
"
), style
=
"
cyan dim
"
, title
=
"
Note:
"
, title_style
=
"
cyan dim
"
, ), title
=
"
Table KM-620 Material Categories
"
, title_style
=
"
cyan
"
, style
=
"
cyan
"
, )
return
panel
end
I cannot get it to look nice without the Panel:
julia
ASME_Materials
.
tableKM620_options2
() ╭──── Table KM
620
Material Categories ───────────────────────────────────╮ │ ╭────────────┬────────────────────────────────────────────────────── │ │ ╮ │ │ │ Category │ Material │ │ │ │ │ ├────────────┼────────────────────────────────────────────────────── │ │ ┤ │ │ │
1
│ Ferritic steel │ │ │ │ │ ├────────────┼────────────────────────────────────────────────────── │ │ ┤ │ │ │
2
│ Austenitic stainless steel and nickel
based alloys │ │ │ │ │ ├────────────┼────────────────────────────────────────────────────── │ │ ┤ │ │ │
3
│ Duplex stainless steel │ │ │ │ │ ├────────────┼────────────────────────────────────────────────────── │ │ ┤ │ │ │
4
│ Precipitation hardening, nickel based │ │ │ │ │ ├────────────┼────────────────────────────────────────────────────── │ │ ┤ │ │ │
5
│ Aluminum │ │ │ │ │ ├────────────┼────────────────────────────────────────────────────── │ │ ┤ │ │ │
6
│ Copper │ │ │ │ │ ├────────────┼────────────────────────────────────────────────────── │ │ ┤ │ │ │
7
│ Titanium and zirconium │ │ │ │ │ ╰────────────┴────────────────────────────────────────────────────── │ │ ╯ │ │ │ │ │ │ Notes
:
│ │ │ │ (
1
) Ferritic steel includes carbon, low alloy, and alloy steels, │ │ │ │ and ferritic, martensitic, and iron
based age
hardening stainless │ │ │ │ steels. │ │ │ │ │ │ │ ╰─────────────────────────────────────────────────────────────────────────╯
function
tableKM620_options2
() table
=
select
(KM620
.
coefficients_table,
"
Material
"
) notes
=
"
Notes:
\n
"
join
(
values
(
metadata
(KM620
.
coefficients_table)),
"
\n
"
) panel
=
@nested_panels
Panel
( Term
.
Table
(
hcat
(
1
:
nrow
(table), table.
"
Material
"
), header
=
[
"
Category
"
,
"
Material
"
], header_style
=
"
cyan
"
, columns_justify
=
[
:center
,
:left
], columns_style
=
"
default
"
, box
=
:ROUNDED
, style
=
"
cyan
"
, ),
TextBox
(
@style
(notes,
"
cyan dim
"
), ), title
=
"
Table KM-620 Material Categories
"
, title_style
=
"
cyan
"
, style
=
"
cyan
"
, )
return
panel
end
(Also in the last example, the styling is only applied to the first line of the TextBox.)
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>