Skip to content

Commit

Permalink
updated msg and string fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeClaudi committed Dec 5, 2022
1 parent ee7d573 commit 8bb0812
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
21 changes: 19 additions & 2 deletions src/__text_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,28 @@ end
Shorten a string of text to a target width
"""
function str_trunc(text::AbstractString, width::Int; trailing_dots = "...")::String
function str_trunc(
text::AbstractString,
width::Int;
trailing_dots = "...",
ignore_markup = false,
)::String
width < 0 && return text
textlen(text) width && return text
if contains(text, '\n')
return do_by_line(
l -> str_trunc(
l,
width;
trailing_dots = trailing_dots,
ignore_markup = ignore_markup,
),
text,
)
end

trunc = reshape_text(text, width - textwidth(trailing_dots))
trunc =
reshape_text(text, width - textwidth(trailing_dots); ignore_markup = ignore_markup)
out = first(split_lines(trunc))
textlen(out) == 0 && return out
out[end] != ' ' && (out *= trailing_dots)
Expand Down
13 changes: 5 additions & 8 deletions src/_errors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ function show_error_code_line(frame::StackFrame; δ = 2)

(isnothing(error_source) || length(error_source) == 0) && return nothing

_width = min(60, default_stacktrace_width() - 6)
code_error_panel = Panel(
error_source;
str_trunc(error_source, _width - 5; ignore_markup = true);
fit = δ == 0,
style = δ > 0 ? "$(theme.text_accent) dim" : "dim",
width = min(60, default_stacktrace_width() - 6),
width = _width,
subtitle_justify = :center,
subtitle = δ > 0 ? "error line" : nothing,
subtitle_style = "default $(theme.text_accent)",
Expand All @@ -33,11 +34,7 @@ function show_error_code_line(frame::StackFrame; δ = 2)
# background = δ > 0 ? nothing : theme.md_codeblock_bg
)

δ == 0 && (
code_error_panel =
" " * RenderableText("\n╰─"; style = "dim") * code_error_panel
)
δ > 0 && (code_error_panel = " " * code_error_panel)
code_error_panel = " " * RenderableText("\n╰─"; style = "dim") * code_error_panel

return code_error_panel
end
Expand Down Expand Up @@ -136,7 +133,7 @@ function render_backtrace_frame(
padding = (2, 2, 1, 1),
style = TERM_THEME[].err_btframe_panel,
fit = false,
width = default_stacktrace_width() - 12,
width = default_stacktrace_width() - 6,
kwargs...,
)
else
Expand Down
4 changes: 2 additions & 2 deletions src/_text_reshape.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Reshape a text to have a given width.
Insert newline characters in a string so that each line is within the given width.
"""
function reshape_text(text::AbstractString, width::Int)
function reshape_text(text::AbstractString, width::Int; ignore_markup = false)
occursin('\n', text) && (return do_by_line(ln -> reshape_text(ln, width), text))
textlen(text) width && return text

Expand All @@ -23,7 +23,7 @@ function reshape_text(text::AbstractString, width::Int)
if c == '\e'
in_escape_code = true
end
if c == '{'
if c == '{' && !ignore_markup
bracketed = true
end

Expand Down

0 comments on commit 8bb0812

Please sign in to comment.