Skip to content
Closed
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
11 changes: 11 additions & 0 deletions stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ function run_frontend(repl::BasicREPL, backend::REPLBackendRef)
if !isempty(line)
response = eval_with_backend(ast, backend)
print_response(repl, response, !ends_with_semicolon(line), false)
print_exit_hint(repl, line)
end
write(repl.terminal, '\n')
((!interrupted && isempty(line)) || hit_eof) && break
Expand Down Expand Up @@ -796,6 +797,7 @@ function respond(f, repl, main; pass_empty::Bool = false, suppress_on_semicolon:
end
hide_output = suppress_on_semicolon && ends_with_semicolon(line)
print_response(repl, response, !hide_output, hascolor(repl))
print_exit_hint(repl, line)
end
prepare_next(repl)
reset_state(s)
Expand Down Expand Up @@ -1224,6 +1226,7 @@ function run_frontend(repl::StreamREPL, backend::REPLBackendRef)
end
response = eval_with_backend(ast, backend)
print_response(repl, response, !ends_with_semicolon(line), have_color)
print_exit_hint(repl, line)
end
end
# Terminate Backend
Expand All @@ -1232,4 +1235,12 @@ function run_frontend(repl::StreamREPL, backend::REPLBackendRef)
nothing
end

print_exit_hint(repl::AbstractREPL, line) = print_exit_hint(outstream(repl), line)
function print_exit_hint(io::IO, line)
if lowercase(strip(line)) == "exit"
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to also print this if the input is "quit" (that's what e.g. GAP uses) ?

Anyway, I really like this PR, it fixes one of those tiny papercuts which seem irrelevant in isolation but add up.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wouldn't object to also doing this for "quit", but I'll defer to @JeffBezanson.

I'd want to keep this limited to a very small set of inputs. For example, you can exit R by typing q() and pressing enter. But I definitely wouldn't want to print a hint if someone types q in the Julia REPL.

I think it makes sense for exit because the corresponding function exit() is a function that actually exists in Julia. But we don't actually have a quit function in Julia.

Copy link
Member Author

Choose a reason for hiding this comment

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

But I don't feel strongly either way. Happy to add quit, also happy to leave it out.

Copy link
Member

Choose a reason for hiding this comment

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

Yes I think we should add it.

Copy link
Member

Choose a reason for hiding this comment

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

I like what the python repl does:

>>> quit
Use quit() or Ctrl-D (i.e. EOF) to exit
>>> quit = 2
>>> quit
2

It stops printing the message if quit is defined as a variable. Stylish! I think we should do this too.
Can be checked with Base.isbindingresolved(Main, :exit) && isdefined(Main, :exit).

Copy link
Member

Choose a reason for hiding this comment

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

In python, that's not magic, it is just literally the definition of show for that default variable:

>>> exit.__class__
<class 'site.Quitter'>
>>> quit.__class__
<class 'site.Quitter'>

The equivalent here would be:

julia> using Base: exit as quit; # @eval Base const quit = exit; @eval Base export quit;

julia> Base.show(io::IO, ::MIME"text/plain", ::typeof(exit)) = print(io, "Use exit() or Ctrl-D (i.e. EOF) to quit")

julia> repr(exit)
"exit"

julia> show(exit)
exit
julia> summary(exit)
"typeof(exit)"

julia> display(exit)
Use exit() or Ctrl-D (i.e. EOF) to quit

julia> exit
Use exit() or Ctrl-D (i.e. EOF) to quit

julia> exit()

Copy link
Member

Choose a reason for hiding this comment

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

Which would have been #21362

println(io, "\nTo exit Julia, use Ctrl-D, or type exit() and press enter.")
end
return nothing
end

end # module