From 8bb0812754710eb474db8ba07e7a6d330a1ad298 Mon Sep 17 00:00:00 2001 From: FedeClaudi Date: Mon, 5 Dec 2022 10:21:31 -0600 Subject: [PATCH] updated msg and string fmt --- src/__text_utils.jl | 21 +++++++++++++++++++-- src/_errors.jl | 13 +++++-------- src/_text_reshape.jl | 4 ++-- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/__text_utils.jl b/src/__text_utils.jl index 164579765..7ee8dafcb 100644 --- a/src/__text_utils.jl +++ b/src/__text_utils.jl @@ -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) diff --git a/src/_errors.jl b/src/_errors.jl index 2a46a07b6..6d58ffc9c 100644 --- a/src/_errors.jl +++ b/src/_errors.jl @@ -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)", @@ -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 @@ -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 diff --git a/src/_text_reshape.jl b/src/_text_reshape.jl index 4b6aed621..70721ed09 100644 --- a/src/_text_reshape.jl +++ b/src/_text_reshape.jl @@ -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 @@ -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