Skip to content

Conversation

DilumAluthge
Copy link
Member

@DilumAluthge DilumAluthge commented Feb 14, 2022

This implements the suggestion from triage in #42011 (comment) and #42011 (comment).

@DilumAluthge
Copy link
Member Author

cc: @mkitti

@DilumAluthge DilumAluthge added display and printing Aesthetics and correctness of printed representations of objects. REPL Julia's REPL (Read Eval Print Loop) labels Feb 14, 2022
Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

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

Seems okay, but feels a little odd that display will have this text in all cases, not just the REPL. I think this might be better:

diff --git a/stdlib/REPL/src/REPL.jl b/stdlib/REPL/src/REPL.jl
index 3308760046..cb7163aeab 100644
--- a/stdlib/REPL/src/REPL.jl
+++ b/stdlib/REPL/src/REPL.jl
@@ -301,6 +301,9 @@ function print_response(errio::IO, response, show_value::Bool, have_color::Bool,
                         println(errio, "Error showing value of type ", typeof(val), ":")
                         rethrow()
                     end
+                    if response === exit
+                        println("Hint: To exit Julia, use Ctrl-D or type exit() and press enter.")
+                    end
                 end
             end
             break

@mkitti
Copy link
Contributor

mkitti commented Feb 14, 2022

To review, we've explored a few ways of doing this, and come full circle:

  1. add exit/quit hint #21362
    Similar to this PR
  2. REPL-only: Print a hint if the user types exit in the REPL #38307
    Modified display(d::REPLDisplay, mime::MIME"text/plain", x)
  3. REPL-only: Print a hint if the user types exit in the REPL #38522
    Added a print_exit_help method called after print_response
  4. REPL-only: Print a hint if the user types exit in the REPL using an AST transform #42011
    Used an AST transform in the REPL
julia> function Base.show(io::IO, m::MIME"text/plain", fn::typeof(exit))
           TT = Tuple{IO, MIME"text/plain", Function}
           invoke(show, TT, io, m, fn)
           println(io)
           print(io, "Hint: To exit Julia, use Ctrl-D or type exit() and press enter.")
           return nothing
       end

julia> exit
exit (generic function with 2 methods)
Hint: To exit Julia, use Ctrl-D or type exit() and press enter.

julia> (exit, exit)
(exit, exit)

julia> [exit]
1-element Vector{typeof(exit)}:
 exit

julia> ans[1]
exit (generic function with 2 methods)
Hint: To exit Julia, use Ctrl-D or type exit() and press enter.

@mkitti
Copy link
Contributor

mkitti commented Feb 14, 2022

Would making it conditional on Base.isinteractive() help?

@mkitti
Copy link
Contributor

mkitti commented Feb 15, 2022

Thinking of the bigger picture here, why doesn't the REPL have it's own MIME type? text/vnd.juliarepl perhaps. The fallback would be to text/plain.

@oscardssmith oscardssmith added the triage This should be discussed on a triage call label Feb 17, 2022
@JeffBezanson
Copy link
Member

Was I on that triage call? This is absolutely not the right way to implement this. You don't want to change what the exit function looks like, you just want to hook into the exact repl input exit. For example what if I write Fs = [exit] followed by Fs[1].

@JeffBezanson
Copy link
Member

Same thing I posted in 2017 btw.

@vtjnash
Copy link
Member

vtjnash commented Feb 17, 2022

So #42011?

@JeffBezanson
Copy link
Member

That's not ideal either; a string operation like how we handle ; seems like the best way. But I don't think this is necessary at all.

@mkitti
Copy link
Contributor

mkitti commented Feb 17, 2022

That's not ideal either; a string operation like how we handle ; seems like the best way. But I don't think this is necessary at all.

https://github.com/JuliaLang/julia/pull/38522/files

@JeffBezanson
Copy link
Member

While we're at it, we can fix quit too, which does weird things:

julia> f() = quit
f (generic function with 1 method)

julia> f()
ERROR: UndefVarError: quit not defined
suggestion: To exit Julia, use Ctrl-D, or type exit() and press enter.

@mkitti
Copy link
Contributor

mkitti commented Feb 17, 2022

@DilumAluthge , Jeff, leading triage, says to go back to #38522 , with the binding resolved enhancement he suggested.

@JeffBezanson
Copy link
Member

Same thing for help.

@oscardssmith oscardssmith removed the triage This should be discussed on a triage call label Feb 17, 2022
@DilumAluthge DilumAluthge marked this pull request as draft February 17, 2022 21:26
@DilumAluthge DilumAluthge deleted the dpa/repl-exit-hint branch October 8, 2022 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display and printing Aesthetics and correctness of printed representations of objects. REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants