|
| 1 | +# ------------------------------------------------------------------------------ # |
| 2 | +# ANSI helpers and generic Expr printing |
| 3 | +# ------------------------------------------------------------------------------ # |
| 4 | + |
| 5 | +""" |
| 6 | +Generate ANSI escape sequence for the specified color and formatting. |
| 7 | +""" |
| 8 | +function _ansi_color(color::Symbol, bold::Bool=false) |
| 9 | + color_codes = Dict( |
| 10 | + :black => 30, |
| 11 | + :red => 31, |
| 12 | + :green => 32, |
| 13 | + :yellow => 33, |
| 14 | + :blue => 34, |
| 15 | + :magenta => 35, |
| 16 | + :cyan => 36, |
| 17 | + :white => 37, |
| 18 | + :default => 39, |
| 19 | + ) |
| 20 | + |
| 21 | + code = get(color_codes, color, 39) |
| 22 | + return bold ? "\033[1;$(code)m" : "\033[$(code)m" |
| 23 | +end |
| 24 | + |
| 25 | +"""Generate ANSI reset sequence to clear formatting.""" |
| 26 | +_ansi_reset() = "\033[0m" |
| 27 | + |
| 28 | +""" |
| 29 | +Print text with ANSI color formatting for Documenter compatibility. |
| 30 | +""" |
| 31 | +function _print_ansi_styled( |
| 32 | + io, text::Union{String,Symbol,Type}, color::Symbol, bold::Bool=false |
| 33 | +) |
| 34 | + print(io, _ansi_color(color, bold), string(text), _ansi_reset()) |
| 35 | +end |
| 36 | + |
| 37 | +""" |
| 38 | +$(TYPEDSIGNATURES) |
| 39 | +
|
| 40 | +Print an expression with indentation. |
| 41 | +
|
| 42 | +# Arguments |
| 43 | +
|
| 44 | +- `e::Expr`: The expression to print. |
| 45 | +- `io::IO`: The output stream. |
| 46 | +- `l::Int`: The indentation level (number of spaces). |
| 47 | +""" |
| 48 | +function __print(e::Expr, io::IO, l::Int) |
| 49 | + MLStyle.@match e begin |
| 50 | + :(($a, $b)) => println(io, " "^l, a, ", ", b) |
| 51 | + _ => println(io, " "^l, e) |
| 52 | + end |
| 53 | +end |
0 commit comments