Skip to content

REPL: Show input alias (e.g., \\:cat:) for Char display #58181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]).
Expand Down
10 changes: 10 additions & 0 deletions stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<tab>"; 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))))
Expand Down
29 changes: 29 additions & 0 deletions stdlib/REPL/test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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:<tab>", 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<tab>", 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