1 package org.codehaus.groovy.sandbox.ui; 2 3 import java.io.BufferedReader ; 4 import java.io.IOException ; 5 import java.io.InputStreamReader ; 6 import java.io.InputStream ; 7 import java.io.PrintStream ; 8 9 12 public class JavaPrompt implements Prompt 13 { 14 private String prompt; 15 private BufferedReader input; 16 private final PrintStream out; 17 private final PrintStream err; 18 19 public JavaPrompt(InputStream in, PrintStream out, PrintStream err) 20 { 21 this.out = out; 22 this.err = err; 23 this.input = new BufferedReader (new InputStreamReader (in)); 24 } 25 26 public JavaPrompt() 27 { 28 this(System.in, System.out, System.err); 29 } 30 31 public String readLine() throws IOException 32 { 33 out.print(prompt); 34 out.flush(); 35 return input.readLine(); 36 } 37 38 public String getPrompt() 39 { 40 return prompt; 41 } 42 43 public void setPrompt(String prompt) 44 { 45 this.prompt = prompt; 46 } 47 48 public void setCompleter(Completer completer) 49 { 50 } 52 53 public void close() 54 { 55 try 56 { 57 input.close(); 58 } 59 catch (IOException e) 60 { 61 e.printStackTrace(err); 62 } 63 } 64 } 65 | Popular Tags |