1- # Custom display functions for user-friendly error messages
2-
3- # ANSI formatting primitives
4- """
5- _apply_ansi(s, code, io::IO)
6-
7- Apply ANSI escape codes to a string if color is enabled in the IO context.
8-
9- # Arguments
10- - `s::AbstractString`: The string to style.
11- - `code::String`: The ANSI code (e.g., "2" for dim, "1" for bold, "1;31" for red).
12- - `io::IO`: Output stream to check for color support.
13-
14- # Returns
15- - `String`: The string wrapped in ANSI escape codes if `get(io, :color, false)` is true,
16- otherwise the plain string.
17- """
18- _apply_ansi (s, code, io:: IO ) = get (io, :color , false ) ? " \0 33[$(code) m$(s) \0 33[0m" : s
19-
20- """
21- $(TYPEDSIGNATURES)
22-
23- Apply dimmed (faint) ANSI styling to a string.
24-
25- # Arguments
26- - `s::AbstractString`: The string to style.
27- - `io::IO`: Output stream to check for color support.
28-
29- # Returns
30- - `String`: The string wrapped in dim ANSI escape codes if color is enabled.
31- """
32- _dim (s, io:: IO ) = _apply_ansi (s, " 2" , io)
33-
34- """
35- $(TYPEDSIGNATURES)
36-
37- Apply bold ANSI styling to a string.
38-
39- # Arguments
40- - `s::AbstractString`: The string to style.
41- - `io::IO`: Output stream to check for color support.
42-
43- # Returns
44- - `String`: The string wrapped in bold ANSI escape codes if color is enabled.
45- """
46- _bold (s, io:: IO ) = _apply_ansi (s, " 1" , io)
47-
48- """
49- $(TYPEDSIGNATURES)
50-
51- Apply red ANSI styling to a string.
52-
53- # Arguments
54- - `s::AbstractString`: The string to style.
55- - `io::IO`: Output stream to check for color support.
56-
57- # Returns
58- - `String`: The string wrapped in red ANSI escape codes if color is enabled.
59- """
60- _red (s, io:: IO ) = _apply_ansi (s, " 1;31" , io)
61-
62- """
63- $(TYPEDSIGNATURES)
64-
65- Apply yellow ANSI styling to a string.
66-
67- # Arguments
68- - `s::AbstractString`: The string to style.
69- - `io::IO`: Output stream to check for color support.
70-
71- # Returns
72- - `String`: The string wrapped in yellow ANSI escape codes if color is enabled.
73- """
74- _yellow (s, io:: IO ) = _apply_ansi (s, " 33" , io)
75-
76- """
77- $(TYPEDSIGNATURES)
78-
79- Apply green ANSI styling to a string.
80-
81- # Arguments
82- - `s::AbstractString`: The string to style.
83- - `io::IO`: Output stream to check for color support.
84-
85- # Returns
86- - `String`: The string wrapped in green ANSI escape codes if color is enabled.
87- """
88- _green (s, io:: IO ) = _apply_ansi (s, " 32" , io)
89-
901"""
912 extract_user_frames(st::Vector)
923
@@ -360,16 +271,16 @@ function _print_pipe_field(io, label::String, value, max_len::Int, color::Symbol
360271 # Multi-line case: AmbiguousDescription.candidates
361272 for (i, v) in enumerate (value)
362273 if i == 1
363- print (io, _dim (" │" , io), " " , _bold (rpad (label, max_len), io), " " )
274+ print (io, Core . _dim (" │" , io), " " , Core . _bold (rpad (label, max_len), io), " " )
364275 _print_colored (io, string (v), color)
365276 println (io)
366277 else
367- println (io, _dim (" │" , io), " " , " " ^ max_len, " " , string (v))
278+ println (io, Core . _dim (" │" , io), " " , " " ^ max_len, " " , string (v))
368279 end
369280 end
370281 else
371282 # Single value
372- print (io, _dim (" │" , io), " " , _bold (rpad (label, max_len), io), " " )
283+ print (io, Core . _dim (" │" , io), " " , Core . _bold (rpad (label, max_len), io), " " )
373284 _print_colored (io, string (value), color)
374285 println (io)
375286 end
@@ -390,9 +301,9 @@ Print colored text based on a color symbol.
390301"""
391302function _print_colored (io, text, color:: Symbol )
392303 if color == :yellow
393- print (io, _yellow (text, io))
304+ print (io, Core . _yellow (text, io))
394305 elseif color == :green
395- print (io, _green (text, io))
306+ print (io, Core . _green (text, io))
396307 else
397308 print (io, text)
398309 end
@@ -413,22 +324,22 @@ function _format_user_friendly_error(io::IO, e::CTException)
413324 frame = isempty (user_frames) ? nothing : user_frames[1 ]
414325
415326 type_name = string (nameof (typeof (e)))
416- print (io, _red (type_name, io))
327+ print (io, Core . _red (type_name, io))
417328
418329 if ! isnothing (frame)
419330 func_name = string (frame. func)
420331 file_name = basename (string (frame. file))
421332 line_num = frame. line
422- print (io, " " , _dim (" →" , io), " " , _bold (func_name, io), " " )
423- print (io, _yellow (" $(file_name) :$(line_num) " , io))
333+ print (io, " " , Core . _dim (" →" , io), " " , Core . _bold (func_name, io), " " )
334+ print (io, Core . _yellow (" $(file_name) :$(line_num) " , io))
424335 end
425336 println (io)
426337
427338 # Blank pipe separator
428- println (io, _dim (" │" , io))
339+ println (io, Core . _dim (" │" , io))
429340
430341 # Message
431- println (io, _dim (" │" , io), " " , _bold (e. msg, io))
342+ println (io, Core . _dim (" │" , io), " " , Core . _bold (e. msg, io))
432343
433344 # Build field pairs
434345 primary_pairs = _build_primary_pairs (e)
@@ -440,7 +351,7 @@ function _format_user_friendly_error(io::IO, e::CTException)
440351 max_len = maximum (length (p[1 ]) for p in all_pairs)
441352
442353 # Blank pipe separator
443- println (io, _dim (" │" , io))
354+ println (io, Core . _dim (" │" , io))
444355
445356 # Primary fields
446357 for p in primary_pairs
@@ -449,7 +360,7 @@ function _format_user_friendly_error(io::IO, e::CTException)
449360
450361 # Separator between primary and secondary
451362 if ! isempty (primary_pairs) && ! isempty (secondary_pairs)
452- println (io, _dim (" │" , io))
363+ println (io, Core . _dim (" │" , io))
453364 end
454365
455366 # Secondary fields
@@ -459,7 +370,7 @@ function _format_user_friendly_error(io::IO, e::CTException)
459370 end
460371
461372 # Closing visual
462- return println (io, _dim (" └─" , io))
373+ return println (io, Core . _dim (" └─" , io))
463374end
464375
465376"""
0 commit comments