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

Conversation

ShahabSL
Copy link
Contributor

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

@mcabbott
Copy link
Contributor

mcabbott commented Apr 21, 2025

Seems like a good idea. But if I load it by @eval REPL function show_repl(io::IO, ..., it doesn't seem to be called -- should that work? (Edit, on 1.11. Works on master.)

I wanted to check whether collect("αβγ") would also take this path. (It does not, which is a pity?)

@ShahabSL
Copy link
Contributor Author

Thanks for the feedback! I tested the @eval approach on my build to understand the behavior.

After running using REPL first, I was able to successfully define a modified show_repl method using @eval REPL function.... When I then displayed a character like 'α', the output confirmed that the dynamically defined method was called (it printed a debug message I added and changed the output format as expected):

julia> using REPL

julia> @eval REPL function show_repl(io::IO, mime::MIME"text/plain", c::AbstractChar)
           println(stderr, ">>> Debug: Entering the @eval'd show_repl method!") # Added for testing
           show(io, mime, c)
           latex = REPL.symbol_latex(string(c))
           if !isempty(latex)
               print(io, ", === Alias from @eval'd method: ") # Changed text/color
               printstyled(io, latex, color=:yellow)
           end
       end
show_repl (generic function with 4 methods)

julia> 'α'
>>> Debug: Entering the @eval'd show_repl method!
'α': Unicode U+03B1 (category Ll: Letter, lowercase), === Alias from @eval'd method: \alpha

So it seems dynamic definition does work for this call path at runtime, although I understand rebuilding is the standard way to test source changes incorporated during the build process.

Regarding collect("αβγ"), you are correct that it produces a Vector{Char} and wouldn't hit this AbstractChar-specific method due to dispatch.

@ararslan ararslan added REPL Julia's REPL (Read Eval Print Loop) unicode Related to unicode characters and encodings labels Apr 30, 2025
Copy link
Member

@ararslan ararslan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome, and thanks for the contribution! This seems like a good addition to me. It would be great if you could add tests for this method that exercise the different possible code paths.

@ararslan ararslan added the needs tests Unit tests are required for this change label Apr 30, 2025
    - Adds the LaTeX/emoji input alias to the REPL display for Char.
    - Addresses feedback from PR review (include <tab>, remove comment).
    - Includes tests covering chars with/without aliases and color output.
@ShahabSL
Copy link
Contributor Author

ShahabSL commented May 1, 2025

Thanks so much for the welcome and the helpful feedback, @ararslan! I really appreciate you taking the time to review.

I've pushed commits addressing the suggestions:

  • Added <tab> to the alias output to match help mode, as suggested.
  • Removed the # new method comment.
  • Added tests in stdlib/REPL/test/repl.jl covering the different code paths (characters with and without aliases, handling color output).

The local tests for stdlib/REPL/test/repl.jl are passing on my end. Hopefully, this looks good now. Ready for another look when you get a chance!

@ShahabSL ShahabSL requested a review from ararslan May 5, 2025 23:18
This change addresses reviewer feedback on PR JuliaLang#58158.

The test cases for `REPL.show_repl` with `AbstractChar` in
`stdlib/REPL/test/repl.jl` have been updated to use `sprint`
for capturing output. This makes the tests more concise and
idiomatic by replacing the previous `IOBuffer` and `IOContext`
setup.
@ShahabSL ShahabSL requested a review from ararslan May 7, 2025 23:25
@ararslan ararslan removed the needs tests Unit tests are required for this change label May 8, 2025
@ararslan
Copy link
Member

ararslan commented May 8, 2025

The implementation looks great to me, nice work! It occurred to me that since this is a new feature, a NEW.md entry could also be worthwhile, for example:

--- a/NEWS.md
+++ b/NEWS.md
@@ -49,6 +49,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]).

    Documents the new feature where the REPL display of AbstractChar
    now includes LaTeX/emoji input aliases, as per reviewer suggestion
    on PR JuliaLang#58181.
@ShahabSL ShahabSL requested review from a team and StefanKarpinski and removed request for a team May 8, 2025 18:01
@ShahabSL
Copy link
Contributor Author

ShahabSL commented May 8, 2025

Thanks so much for all the guidance, @ararslan! I've added the NEWS.md entry as requested and pushed the change.

As this was my first issue, I really appreciate you taking the time for the detailed reviews and helpful suggestions throughout this process. It's been a great learning experience!

Ready for another look when you get a chance.

@LilithHafner LilithHafner added merge me PR is reviewed. Merge when all tests are passing feature Indicates new feature / enhancement requests labels May 20, 2025
@LilithHafner LilithHafner changed the title feat(REPL): Show input alias (e.g., \\:cat:) for Char display REPL: Show input alias (e.g., \\:cat:) for Char display May 21, 2025
@LilithHafner LilithHafner merged commit 4c00176 into JuliaLang:master May 21, 2025
10 checks passed
@LilithHafner LilithHafner added 😃🍕 and other emoji display and printing Aesthetics and correctness of printed representations of objects. and removed merge me PR is reviewed. Merge when all tests are passing labels May 21, 2025
@LilithHafner
Copy link
Member

Thanks for contributing, @ShahabSL! This is a nice usability feature that some folks might come to depend on in some edge cases. Sorry it took so long to get back to you this time with another round of feedback. Everything looked good to me so I went ahead and merged it :)

@ShahabSL
Copy link
Contributor Author

Hi @LilithHafner, that's fantastic to hear! Thank you so much for merging this and for your kind words. I'm really glad you see it as a nice usability feature. Absolutely no worries at all about any delay, I truly appreciate you taking the time for the final review and getting it merged. It's wonderful to see it in! I'm especially thrilled as this was my first feature contribution, and it's been such a positive learning experience. 😊

@ararslan
Copy link
Member

Yes, apologies for the delayed response, I've been slammed with work lately and haven't had time to keep up with open source notifications. Thanks for merging, @LilithHafner, and thanks again for the contribution, @ShahabSL!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
😃🍕 and other emoji display and printing Aesthetics and correctness of printed representations of objects. feature Indicates new feature / enhancement requests REPL Julia's REPL (Read Eval Print Loop) unicode Related to unicode characters and encodings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Translate emojis back to their name?
4 participants