Skip to content

Commit 4c00176

Browse files
authored
REPL: Show input alias (e.g., \\:cat:) for Char display (#58181)
This PR enhances the REPL display for Char types. It adds the LaTeX/emoji input alias after the standard Unicode information, making it consistent with the help?> mode behavior. For example, `'😼'` will now display as: `'😼': Unicode U+1F63C (category So: Symbol, other), input as \:smirk_cat:` **(Self-contained paragraph explaining the choice):** Considered modifying `Base.show` directly, but opted for adding a `REPL.show_repl` method instead to avoid introducing a dependency from `Base` on the `REPL` module's symbol mapping (`symbol_latex`). This approach keeps the REPL-specific display logic contained within the REPL module. Closes #58158
1 parent 720d0f5 commit 4c00176

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ Standard library changes
6262

6363
#### REPL
6464

65+
* The display of `AbstractChar`s in the main REPL mode now includes LaTeX input information like what is shown in help mode ([#58181]).
66+
6567
#### Test
6668

6769
* Test failures when using the `@test` macro now show evaluated arguments for all function calls ([#57825], [#57839]).

stdlib/REPL/src/REPL.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,16 @@ display(d::REPLDisplay, x) = display(d, MIME("text/plain"), x)
555555

556556
show_repl(io::IO, mime::MIME"text/plain", x) = show(io, mime, x)
557557

558+
function show_repl(io::IO, mime::MIME"text/plain", c::AbstractChar)
559+
show(io, mime, c) # Call the original Base.show
560+
# Check for LaTeX/emoji alias and print if found and using symbol_latex which is used in help?> mode
561+
latex = symbol_latex(string(c))
562+
if !isempty(latex)
563+
print(io, ", input as ")
564+
printstyled(io, latex, "<tab>"; color=:cyan)
565+
end
566+
end
567+
558568
show_repl(io::IO, ::MIME"text/plain", ex::Expr) =
559569
print(io, JuliaSyntaxHighlighting.highlight(
560570
sprint(show, ex, context=IOContext(io, :color => false))))

stdlib/REPL/test/repl.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,3 +1999,32 @@ end
19991999
write(proj_file, "name = \"Bar\"\n")
20002000
@test get_prompt("--project=$proj_file") == "(Bar) pkg> "
20012001
end
2002+
2003+
# Issue #58158 add alias for Char display in REPL
2004+
@testset "REPL show_repl Char alias" begin
2005+
# Test character with a known emoji alias
2006+
output = sprint(REPL.show_repl, MIME("text/plain"), '😼'; context=(:color => true))
2007+
# Check for base info and the specific alias
2008+
@test occursin("'😼': Unicode U+1F63C (category So: Symbol, other)", output)
2009+
@test occursin(", input as ", output) # Check for the prefix text
2010+
@test occursin("\\:smirk_cat:<tab>", output) # Check for the alias text (may be colored)
2011+
2012+
# Test character with a known LaTeX alias
2013+
output = sprint(REPL.show_repl, MIME("text/plain"), 'α'; context=(:color => true))
2014+
# Check for base info and the specific alias
2015+
@test occursin("'α': Unicode U+03B1 (category Ll: Letter, lowercase)", output)
2016+
@test occursin(", input as ", output) # Check for the prefix text
2017+
@test occursin("\\alpha<tab>", output) # Check for the alias text (may be colored)
2018+
2019+
# Test character without an alias
2020+
output = sprint(REPL.show_repl, MIME("text/plain"), 'X'; context=(:color => true))
2021+
# Check for base info only
2022+
@test occursin("'X': ASCII/Unicode U+0058 (category Lu: Letter, uppercase)", output)
2023+
# Ensure alias part is *not* printed
2024+
@test !occursin(", input as ", output)
2025+
2026+
# Test another character without an alias (symbol)
2027+
output = sprint(REPL.show_repl, MIME("text/plain"), '+'; context=(:color => true))
2028+
@test occursin("'+': ASCII/Unicode U+002B (category Sm: Symbol, math)", output)
2029+
@test !occursin(", input as ", output)
2030+
end

0 commit comments

Comments
 (0)