View Javadoc

1   /*
2    * Copyright (c) 2002-2007, Marc Prud'hommeaux. All rights reserved.
3    *
4    * This software is distributable under the BSD license. See the terms of the
5    * BSD license in the documentation provided with this software.
6    */
7   package jline;
8   
9   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  
28      public boolean isEchoEnabled() {
29          return true;
30      }
31  
32  
33      public void enableEcho() {
34      }
35  
36  
37      public void disableEcho() {
38      }
39  
40  
41      /***
42       *  Always returng 80, since we can't access this info on Windows.
43       */
44      public int getTerminalWidth() {
45          return 80;
46      }
47  
48      /***
49       *  Always returng 24, since we can't access this info on Windows.
50       */
51      public int getTerminalHeight() {
52          return 80;
53      }
54  
55      public boolean isSupported() {
56          return false;
57      }
58  
59      public void beforeReadLine(final ConsoleReader reader, final String prompt,
60         final Character mask) {
61          if ((mask != null) && (maskThread == null)) {
62              final String fullPrompt = "\r" + prompt
63                  + "                 "
64                  + "                 "
65                  + "                 "
66                  + "\r" + prompt;
67  
68              maskThread = new Thread("JLine Mask Thread") {
69                  public void run() {
70                      while (!interrupted()) {
71                          try {
72                              reader.out.write(fullPrompt);
73                              reader.out.flush();
74                              sleep(3);
75                          } catch (IOException ioe) {
76                              return;
77                          } catch (InterruptedException ie) {
78                              return;
79                          }
80                      }
81                  }
82              };
83  
84              maskThread.setPriority(Thread.MAX_PRIORITY);
85              maskThread.setDaemon(true);
86              maskThread.start();
87          }
88      }
89  
90      public void afterReadLine(final ConsoleReader reader, final String prompt,
91          final Character mask) {
92          if ((maskThread != null) && maskThread.isAlive()) {
93              maskThread.interrupt();
94          }
95  
96          maskThread = null;
97      }
98  }