01: package org.codehaus.groovy.sandbox.ui;
02:
03: import java.io.BufferedReader;
04: import java.io.IOException;
05: import java.io.InputStreamReader;
06: import java.io.InputStream;
07: import java.io.PrintStream;
08:
09: /**
10: * Pure Java prompt using just System.in.
11: */
12: public class JavaPrompt implements Prompt {
13: private String prompt;
14: private BufferedReader input;
15: private final PrintStream out;
16: private final PrintStream err;
17:
18: public JavaPrompt(InputStream in, PrintStream out, PrintStream err) {
19: this .out = out;
20: this .err = err;
21: this .input = new BufferedReader(new InputStreamReader(in));
22: }
23:
24: public JavaPrompt() {
25: this (System.in, System.out, System.err);
26: }
27:
28: public String readLine() throws IOException {
29: out.print(prompt);
30: out.flush();
31: return input.readLine();
32: }
33:
34: public String getPrompt() {
35: return prompt;
36: }
37:
38: public void setPrompt(String prompt) {
39: this .prompt = prompt;
40: }
41:
42: public void setCompleter(Completer completer) {
43: // completer not supported
44: }
45:
46: public void close() {
47: try {
48: input.close();
49: } catch (IOException e) {
50: e.printStackTrace(err);
51: }
52: }
53: }
|