|
1 | 1 | # ------------------------------------------------------------------------------ # |
2 | 2 | # PRINT |
3 | 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, :red => 31, :green => 32, :yellow => 33, |
| 11 | + :blue => 34, :magenta => 35, :cyan => 36, :white => 37, |
| 12 | + :default => 39 |
| 13 | + ) |
| 14 | + |
| 15 | + code = get(color_codes, color, 39) |
| 16 | + return bold ? "\033[1;$(code)m" : "\033[$(code)m" |
| 17 | +end |
| 18 | + |
| 19 | +"""Generate ANSI reset sequence to clear formatting.""" |
| 20 | +_ansi_reset() = "\033[0m" |
| 21 | + |
| 22 | +""" |
| 23 | +Print text with ANSI color formatting for Documenter compatibility. |
| 24 | +""" |
| 25 | +function _print_ansi_styled(io, text::Union{String,Symbol,Type}, color::Symbol, bold::Bool=false) |
| 26 | + print(io, _ansi_color(color, bold), string(text), _ansi_reset()) |
| 27 | +end |
4 | 28 | """ |
5 | 29 | $(TYPEDSIGNATURES) |
6 | 30 |
|
@@ -35,7 +59,7 @@ Print the abstract definition of an optimal control problem. |
35 | 59 | """ |
36 | 60 | function __print_abstract_definition(io::IO, ocp::Union{Model,PreModel}) |
37 | 61 | @assert hasproperty(definition(ocp), :head) |
38 | | - printstyled(io, "Abstract definition:\n\n"; bold=true) |
| 62 | + _print_ansi_styled(io, "Abstract definition:\n\n", :default, true) |
39 | 63 | tab = 4 |
40 | 64 | code = MacroTools.striplines(definition(ocp)) |
41 | 65 | MLStyle.@match code.head begin |
@@ -109,17 +133,17 @@ function __print_mathematical_definition( |
109 | 133 |
|
110 | 134 | # |
111 | 135 | some_printing && println(io) |
112 | | - printstyled(io, "The "; bold=true) |
| 136 | + _print_ansi_styled(io, "The ", :default, true) |
113 | 137 | if is_time_dependent |
114 | | - printstyled(io, "(non autonomous) "; bold=true) |
| 138 | + _print_ansi_styled(io, "(non autonomous) ", :default, true) |
115 | 139 | else |
116 | | - printstyled(io, "(autonomous) "; bold=true) |
| 140 | + _print_ansi_styled(io, "(autonomous) ", :default, true) |
117 | 141 | end |
118 | | - printstyled(io, "optimal control problem is of the form:\n"; bold=true) |
| 142 | + _print_ansi_styled(io, "optimal control problem is of the form:\n", :default, true) |
119 | 143 | println(io) |
120 | 144 |
|
121 | 145 | # J |
122 | | - printstyled(io, " minimize "; color=:blue) |
| 146 | + _print_ansi_styled(io, " minimize ", :blue, false) |
123 | 147 | # Only include control in objective if u_dim > 0 |
124 | 148 | u_in_obj = u_dim > 0 ? ", " * u_name : "" |
125 | 149 | print(io, "J(" * x_name * u_in_obj * _v * ") = ") |
@@ -149,7 +173,7 @@ function __print_mathematical_definition( |
149 | 173 |
|
150 | 174 | # constraints |
151 | 175 | println(io, "") |
152 | | - printstyled(io, " subject to\n"; color=:blue) |
| 176 | + _print_ansi_styled(io, " subject to\n", :blue, false) |
153 | 177 | println(io, "") |
154 | 178 |
|
155 | 179 | # dynamics |
|
0 commit comments