01: /*
02: * Copyright (c) 2002-2007, Marc Prud'hommeaux. All rights reserved.
03: *
04: * This software is distributable under the BSD license. See the terms of the
05: * BSD license in the documentation provided with this software.
06: */
07: package jline;
08:
09: import java.io.IOException;
10:
11: /**
12: * A no-op unsupported terminal.
13: *
14: * @author <a href="mailto:mwp1@cornell.edu">Marc Prud'hommeaux</a>
15: */
16: public class UnsupportedTerminal extends Terminal {
17: private Thread maskThread = null;
18:
19: public void initializeTerminal() {
20: // nothing we need to do (or can do) for windows.
21: }
22:
23: public boolean getEcho() {
24: return true;
25: }
26:
27: public boolean isEchoEnabled() {
28: return true;
29: }
30:
31: public void enableEcho() {
32: }
33:
34: public void disableEcho() {
35: }
36:
37: /**
38: * Always returng 80, since we can't access this info on Windows.
39: */
40: public int getTerminalWidth() {
41: return 80;
42: }
43:
44: /**
45: * Always returng 24, since we can't access this info on Windows.
46: */
47: public int getTerminalHeight() {
48: return 80;
49: }
50:
51: public boolean isSupported() {
52: return false;
53: }
54:
55: public void beforeReadLine(final ConsoleReader reader,
56: final String prompt, final Character mask) {
57: if ((mask != null) && (maskThread == null)) {
58: final String fullPrompt = "\r" + prompt
59: + " " + " "
60: + " " + "\r" + prompt;
61:
62: maskThread = new Thread("JLine Mask Thread") {
63: public void run() {
64: while (!interrupted()) {
65: try {
66: reader.out.write(fullPrompt);
67: reader.out.flush();
68: sleep(3);
69: } catch (IOException ioe) {
70: return;
71: } catch (InterruptedException ie) {
72: return;
73: }
74: }
75: }
76: };
77:
78: maskThread.setPriority(Thread.MAX_PRIORITY);
79: maskThread.setDaemon(true);
80: maskThread.start();
81: }
82: }
83:
84: public void afterReadLine(final ConsoleReader reader,
85: final String prompt, final Character mask) {
86: if ((maskThread != null) && maskThread.isAlive()) {
87: maskThread.interrupt();
88: }
89:
90: maskThread = null;
91: }
92: }
|