Skip to content

Commit

Permalink
add docstring examples
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Apr 14, 2021
1 parent e091aa6 commit 94aa3c6
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,27 @@ is encountered or EOF (^D) character is entered on a blank line. If a `default`
then the user can enter just a newline character to select the `default`. A `timeout` in seconds
greater than 0 can be provided, after which the default will be returned.
For instance, the user enters a value and hits `return`:
```julia
julia> Base.prompt("Proceed? y/n"; default="n", timeout=5)
Proceed? y/n [n] timeout 5 seconds: y
"y"
```
The user hits `return` alone to select the default:
```julia
julia> Base.prompt("Proceed? y/n"; default="n", timeout=5)
Proceed? y/n [n] timeout 5 seconds:
"n"
```
The user doesn't input and hit `return` before the timeout, so default returns:
```julia
julia> Base.prompt("Proceed? y/n"; default="n", timeout=5)
Proceed? y/n [n] timeout 5 seconds: timed out
"n"
```
See also `Base.getpass` and `Base.winprompt` for secure entry of passwords.
"""
function prompt(input::IO, output::IO, message::AbstractString; default::AbstractString="", timeout::Union{Nothing, Real} = nothing)
Expand All @@ -303,7 +324,6 @@ function prompt(input::IO, output::IO, message::AbstractString; default::Abstrac
end
else
msg = !isempty(default) ? "$message [$default]: " : "$message: "
timeout_timer = nothing
end
print(output, msg)
uinput = readline(input, keep=true)
Expand Down

0 comments on commit 94aa3c6

Please sign in to comment.