diff --git a/NEWS.md b/NEWS.md index fcf94b340ad66..2e4da039d3cd0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -62,6 +62,8 @@ Standard library changes #### REPL +* The display of `AbstractChar`s in the main REPL mode now includes LaTeX input information like what is shown in help mode ([#58181]). + #### Test * Test failures when using the `@test` macro now show evaluated arguments for all function calls ([#57825], [#57839]). diff --git a/stdlib/REPL/src/REPL.jl b/stdlib/REPL/src/REPL.jl index 169b6a71858ef..5772b481eb151 100644 --- a/stdlib/REPL/src/REPL.jl +++ b/stdlib/REPL/src/REPL.jl @@ -555,6 +555,16 @@ display(d::REPLDisplay, x) = display(d, MIME("text/plain"), x) show_repl(io::IO, mime::MIME"text/plain", x) = show(io, mime, x) +function show_repl(io::IO, mime::MIME"text/plain", c::AbstractChar) + show(io, mime, c) # Call the original Base.show + # Check for LaTeX/emoji alias and print if found and using symbol_latex which is used in help?> mode + latex = symbol_latex(string(c)) + if !isempty(latex) + print(io, ", input as ") + printstyled(io, latex, ""; color=:cyan) + end +end + show_repl(io::IO, ::MIME"text/plain", ex::Expr) = print(io, JuliaSyntaxHighlighting.highlight( sprint(show, ex, context=IOContext(io, :color => false)))) diff --git a/stdlib/REPL/test/repl.jl b/stdlib/REPL/test/repl.jl index b2ddbefd0c25a..a04ade2a5e78f 100644 --- a/stdlib/REPL/test/repl.jl +++ b/stdlib/REPL/test/repl.jl @@ -1999,3 +1999,32 @@ end write(proj_file, "name = \"Bar\"\n") @test get_prompt("--project=$proj_file") == "(Bar) pkg> " end + +# Issue #58158 add alias for Char display in REPL +@testset "REPL show_repl Char alias" begin + # Test character with a known emoji alias + output = sprint(REPL.show_repl, MIME("text/plain"), '😼'; context=(:color => true)) + # Check for base info and the specific alias + @test occursin("'😼': Unicode U+1F63C (category So: Symbol, other)", output) + @test occursin(", input as ", output) # Check for the prefix text + @test occursin("\\:smirk_cat:", output) # Check for the alias text (may be colored) + + # Test character with a known LaTeX alias + output = sprint(REPL.show_repl, MIME("text/plain"), 'α'; context=(:color => true)) + # Check for base info and the specific alias + @test occursin("'α': Unicode U+03B1 (category Ll: Letter, lowercase)", output) + @test occursin(", input as ", output) # Check for the prefix text + @test occursin("\\alpha", output) # Check for the alias text (may be colored) + + # Test character without an alias + output = sprint(REPL.show_repl, MIME("text/plain"), 'X'; context=(:color => true)) + # Check for base info only + @test occursin("'X': ASCII/Unicode U+0058 (category Lu: Letter, uppercase)", output) + # Ensure alias part is *not* printed + @test !occursin(", input as ", output) + + # Test another character without an alias (symbol) + output = sprint(REPL.show_repl, MIME("text/plain"), '+'; context=(:color => true)) + @test occursin("'+': ASCII/Unicode U+002B (category Sm: Symbol, math)", output) + @test !occursin(", input as ", output) +end