I’m trying to spice up my Julia REPL prompt with ANSI color codes (not just one single color, but multiple colors in the same line). However, it messes up the cursor alignment, because the code in REPL.jl also counts the ANSI control sequences when it computes the length of the prompt. AFAICT, the “culprit” is Base.textwidth:
The \e is already ignored, since it’s invisible, and this could arguably be considered a bug, to not ignore what follows and is interpreted for it, and then get 10. Not too important since (assume a similar feature for underlining):
This is a standard library as of Julia 1.11. A version compatible with Julia 1.0 through to 1.10 has also been registered in General — allowing StyledStrings to be used anywhere without compromising compatibility.
Well, StyledString.jl might be backported to earlier Julia versions, but the support is limited. First and foremost, the REPL prompt doesn’t expect AnnotatedStrings, and it throws a typeasset.
TypeError: in typeassert, expected String, got a value of type StyledStrings.AnnotatedStrings.AnnotatedString{String}
Stacktrace:
[1] write_prompt(terminal::IO, s::Union{AbstractString, Function}, color::Bool)
@ REPL.LineEdit ~/.local/share/mise/installs/julia/1.10.5/share/julia/stdlib/v1.10/REPL/src/LineEdit.jl:1525
(On a related note, in Julia 1.10, concatenating StyledStrings seems to be a PITA, regular join and * return plain Strings. The documentation says otherwise. I also can’t get it to load my faces.toml file on startup. Odd.)
julia> using StyledStrings
julia> styled"{my_custom_face:test test}"
"test test" # this is not visibly styled
julia> StyledStrings.load_customisations!(force=true)
julia> styled"{my_custom_face:test test}"
"test test" # this is visibly styled
This happens both with 1.10.5 and 1.11.0-rc4. Using --startup-file=no doesn’t help, either, so its not my local setup. But we are digressing, perhaps this could be continued in an issue reported to the StyledStrings.jl repo.