Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch v2.0.1 #209

Merged
merged 19 commits into from
Mar 18, 2023
Merged
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Term"
uuid = "22787eb5-b846-44ae-b979-8e399b8463ab"
authors = ["FedeClaudi <federicoclaudi@protonmail.com> and contributors"]
version = "2.0.1"
version = "2.0.2"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
1 change: 1 addition & 0 deletions src/_errors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ function add_stack_frame!(
source_file = RenderableText(
string(frame.file) * ":$(frame.line)";
style = "underline dim",
width = ctx.func_name_w,
)
_out = func_line / source_file
else
Expand Down
3 changes: 1 addition & 2 deletions src/link.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import ..Style: apply_style
import ..Renderables: RenderableText, AbstractRenderable
import ..Renderables
import ..Layout: pad
import Term:
get_relative_path, textlen, TERM_THEME, cleantext, excise_link_display_text, remove_ansi
import Term: textlen, TERM_THEME, cleantext, excise_link_display_text, remove_ansi
import Term

export Link
Expand Down
6 changes: 3 additions & 3 deletions src/logs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,16 @@ Create string display for a log message value.
function log_value_display end

function log_value_display(x::AbstractArray)
a = highlight(str_trunc(string(x), 100); ignore_ansi = true)
a = highlight(str_trunc(string(x), 1000); ignore_ansi = true)

s = foldl((a, b) -> a * " × " * b, string.(size(x)))
b = highlight("{bold dim}Size: $(s){/bold dim}"; ignore_ansi = true)
return a * "\n" * b
end

log_value_display(x::AbstractDict) =
highlight(str_trunc(string(x), 100); ignore_ansi = true)
log_value_display(x) = highlight(str_trunc(string(x), 100);)
highlight(str_trunc(string(x), 1000); ignore_ansi = true)
log_value_display(x) = highlight(str_trunc(string(x), 1000);)

"""
handle_message(logger::TermLogger, lvl, msg, _mod, group, id, file, line; kwargs...)
Expand Down
2 changes: 1 addition & 1 deletion src/markdown.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function parse_md(
"{$(theme.md_code)}`{/$(theme.md_code)}"
else
panel = Panel(
syntax;
RenderableText(syntax; style = "on_$(theme.md_codeblock_bg)");
style = "white on_$(theme.md_codeblock_bg)",
box = :SQUARE,
subtitle = length(code.language) > 0 ? code.language : nothing,
Expand Down
7 changes: 4 additions & 3 deletions src/panels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ content_as_renderable(
justify::Symbol,
background::Union{String,Nothing},
)::RenderableText =
RenderableText(content, width = width - Δw, background = background, justify = justify)
RenderableText(content; width = width - Δw, background = background, justify = justify)

"""

Expand Down Expand Up @@ -225,7 +225,7 @@ function Panel(
Δh = padding.top + padding.bottom

# create content
# @info "panel fit" width height Δw Δh
# @info "panel fit" width height Δw Δh background
content = content_as_renderable(content, width, Δw, justify, background)

# estimate panel size
Expand Down Expand Up @@ -282,7 +282,7 @@ function Panel(
content = content_as_renderable(content, width, Δw, justify, background)
height = something(height, content.measure.h + Δh + 2)
panel_measure = Measure(height, width)
# @info "panel nofit" width Δw Δh height panel_measure
# @info "panel nofit" width Δw Δh height panel_measure background content.measure

# if the content is too tall, exclude some lines
if content.measure.h > height - Δh - 2
Expand All @@ -292,6 +292,7 @@ function Panel(
style = "dim",
width = content.measure.w,
justify = :center,
background = background,
)

segments = if lines_to_drop < content.measure.h
Expand Down
10 changes: 9 additions & 1 deletion src/progress.jl
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ function foreachprogress(
n = _getn(iter),
transient = true,
parallel = false,
columns_kwargs = Dict(),
kwargs...,
)
task = nothing
Expand All @@ -687,9 +688,16 @@ function foreachprogress(
start!(pbar)
task = Threads.@spawn _startrenderloop(pbar)
end
return

# The job tracks the iteration through `iter`
job = addjob!(pbar; N = n, transient, kwargs...)
job = addjob!(
pbar;
N = n,
transient = transient,
columns_kwargs = columns_kwargs,
kwargs...,
)
if parallel
Threads.@threads for elem in iter
f(elem)
Expand Down
6 changes: 3 additions & 3 deletions src/renderables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ function RenderableText(
text = apply_style(text)

style = isnothing(style) ? "" : style
background = isnothing(background) ? "" : get_bg_color(background)
style = style * background
# background = isnothing(background) ? "" : get_bg_color(background)
# style = style * background

style_init, style_finish = get_style_codes(MarkupStyle(style))

Expand All @@ -168,7 +168,7 @@ function RenderableText(
rt
else
text = join_lines([seg.text for seg in rt.segments])
RenderableText(text; style = style, width = width)
RenderableText(text; style = style, width = width, kwargs...)
end
end

Expand Down
5 changes: 5 additions & 0 deletions src/trees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ function Tree(
kwargs...,
)
_TREE_PRINTING_TITLE[] = title
_theme = TERM_THEME[]
TERM_THEME[] = theme

# print tree
guides = guides isa Symbol ? treeguides[guides] : guides
Expand Down Expand Up @@ -168,6 +170,9 @@ function Tree(

# turn into a renderable
rt = RenderableText(tree)

# restore theme
TERM_THEME[] = _theme
return Tree(rt.segments, rt.measure)
end

Expand Down
14 changes: 12 additions & 2 deletions test/08_test_panel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,17 @@ end
end

@testset "\e[34mPanel - background" begin
p = Panel(
RenderableText(
"testste";
style = "white on_red",
background = "on_blue",
width = 25,
);
background = "green",
)
IS_WIN || @compare_to_string p "panel_background_1"

p = Panel(apply_style(
"""
asasd
Expand All @@ -331,8 +342,7 @@ ads
"on_blue",
); background = "on_red", fit = true)

@test string(p) ==
"\e[0m\e[22m╭──────────────────────╮\e[22m\e[0m\n\e[22m│\e[22m\e[41m \e[49m\e[41m\e[44m asasd\e[49m\e[41m \e[49m\e[49m\e[41m \e[49m\e[22m│\e[22m\n\e[22m│\e[22m\e[41m \e[49m\e[41m\e[44masdasadas\e[49m\e[41m \e[49m\e[49m\e[41m \e[49m\e[22m│\e[22m\n\e[22m│\e[22m\e[41m \e[49m\e[41m\e[44masdsasdasdsadasdsa\e[49m\e[49m\e[41m \e[49m\e[22m│\e[22m\n\e[22m│\e[22m\e[41m \e[49m\e[41m\e[44mads\e[49m\e[41m \e[49m\e[49m\e[41m \e[49m\e[22m│\e[22m\n\e[22m│\e[22m\e[41m \e[49m\e[41m\e[44m \e[49m\e[41m \e[49m\e[49m\e[41m \e[49m\e[22m│\e[22m\n\e[0m\e[22m╰──────────────────────╯\e[22m\e[0m\e[0m"
IS_WIN || @compare_to_string p "panel_background_2"
end

@testset "\e[34mPANEL - UnicodePlots" begin
Expand Down
20 changes: 10 additions & 10 deletions test/txtfiles/automatic_repr_showme_1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

Method definition
┌────────────────────────────────────────────────────────────────────┐
│ function tprint(io::IO, x::AbstractString; highlight = true)  │
│  x = (highlight ? apply_style ∘ highlighter : apply_style)(  │
│ x)  │
│   │
│  x =  │
│  Measure(x).w <= console_width(io) ? x :  │
│  string(RenderableText(string(x), width = console_width  │
│ (io)))  │
│  print(io, x)  │
│ end  │
│ function tprint(io::IO, x::AbstractString; highlight = true)   │
│  x = (highlight ? apply_style ∘ highlighter : apply_style)(  │
│ x)   │
│    │
│  x =   │
│  Measure(x).w <= console_width(io) ? x :   │
│  string(RenderableText(string(x), width = console_width  │
│ (io)))   │
│  print(io, x)   │
│ end   │
└────────────────────────────────────────────────────────────────────┘
10 changes: 5 additions & 5 deletions test/txtfiles/markdown_3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ and footnotes {#9aacdb}[1]{/#9aacdb} for your content {#9aacdb}[named]{/#9aacdb}
And, of course, you can show some code too:

┌──────────────────────────────────────────────┐
│ function say_hi(x)  │
│  print("Hellow World")  │
│ end  │
│ function say_hi(x)   │
│  print("Hello World")  │
│ end   │
└──────────────────────────────────── julia ───┘

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

You can use "quotes" to highlight a section:

> “Multi-line quotes can be helpful to make a paragram
┃ stand out, so that users
> “Multi-line quotes can be helpful to make a paragraph
┃ stand out, so that users
┃ won't miss it! You can use other inline syntax in
┃ you `quotes` too.”

Expand Down
Loading