Class Prompt
java.lang.Object
fc.io.Prompt
-
Constructor Summary
ConstructorsConstructorDescriptionPrompt()
Constructs a fallback object, using System.in, System.out for the input, output and error streams.Prompt
(InputStream in, PrintStream out, PrintStream err) Constructs the object using the specified input and output streams.Prompt
(Reader in, PrintWriter out, PrintWriter err) Constructs the object using the specified input and output writers. -
Method Summary
Modifier and TypeMethodDescriptionCallsask(java.lang.String,boolean)
so that a newline is not shown after the question shown to the user.Shows the specified string to the user shows the input prompt to the user (to indicate the user's input is expected).Callsask(java.lang.String,java.lang.String,boolean)
so that a newline is not shown after the question shown to the user.Shows the specified string to the user shows the input prompt to the user (to indicate the user's input is expected).Gets the latest input line that has been read.static void
void
setError
(PrintStream err) void
setError
(PrintWriter err) void
setInput
(InputStream in) void
void
setOutput
(PrintStream out) void
setOutput
(PrintWriter out) void
Immediately writes a string to the output.void
Immediately writes the specified string as a new line, to the output.
-
Constructor Details
-
Prompt
Constructs the object using the specified input and output writers.- Parameters:
in
- the BufferedReader to use for inputout
- the PrintWriter to use for outputerr
- the PrintWriter to use for errors
-
Prompt
Constructs the object using the specified input and output streams.- Parameters:
in
- the BufferedReader to use for inputout
- the PrintWriter to use for outputerr
- the PrintWriter to use for errors
-
Prompt
public Prompt()Constructs a fallback object, using System.in, System.out for the input, output and error streams.
-
-
Method Details
-
ask
Shows the specified string to the user shows the input prompt to the user (to indicate the user's input is expected). Keeps looping and asking the same question until a non-empty response has been typed by the user, then returns that response.- Parameters:
str
- the string to show to the usernewline
- whether to print a newline after the string
-
ask
Callsask(java.lang.String,boolean)
so that a newline is not shown after the question shown to the user. -
ask
Shows the specified string to the user shows the input prompt to the user (to indicate the user's input is expected). Returns the fallback string if a empty response has been typed by the user, else returns the user response.- Parameters:
str
- the string to show to the userfallback
- response to return if the user types in an empty response (typically by simply hitting a newline)newline
- whether to print a newline after showing the specified string to the user
-
ask
Callsask(java.lang.String,java.lang.String,boolean)
so that a newline is not shown after the question shown to the user. -
write
-
writeln
-
getLastLine
Gets the latest input line that has been read. Can return the same line multiple times if no new lines have been read since the last time this method was called. Returns null if no line has been read so far. -
setInput
-
setInput
-
setOutput
-
setOutput
-
setError
-
setError
-
main
-