001 /* 002 * Copyright (c) 2002-2006, Marc Prud'hommeaux. All rights reserved. 003 * 004 * This software is distributable under the BSD license. See the terms of the 005 * BSD license in the documentation provided with this software. 006 */ 007 package jline; 008 009 import java.io.IOException; 010 011 /** 012 * A no-op unsupported terminal. 013 * 014 * @author <a href="mailto:mwp1@cornell.edu">Marc Prud'hommeaux</a> 015 */ 016 public class UnsupportedTerminal extends Terminal { 017 private Thread maskThread = null; 018 019 public void initializeTerminal() { 020 // nothing we need to do (or can do) for windows. 021 } 022 023 public boolean getEcho() { 024 return true; 025 } 026 027 /** 028 * Always returng 80, since we can't access this info on Windows. 029 */ 030 public int getTerminalWidth() { 031 return 80; 032 } 033 034 /** 035 * Always returng 24, since we can't access this info on Windows. 036 */ 037 public int getTerminalHeight() { 038 return 80; 039 } 040 041 public boolean isSupported() { 042 return false; 043 } 044 045 public void beforeReadLine(final ConsoleReader reader, final String prompt, 046 final Character mask) { 047 if ((mask != null) && (maskThread == null)) { 048 final String fullPrompt = "\r" + prompt 049 + " " 050 + " " 051 + " " 052 + "\r" + prompt; 053 054 maskThread = new Thread("JLine Mask Thread") { 055 public void run() { 056 while (!interrupted()) { 057 try { 058 reader.out.write(fullPrompt); 059 reader.out.flush(); 060 sleep(3); 061 } catch (IOException ioe) { 062 return; 063 } catch (InterruptedException ie) { 064 return; 065 } 066 } 067 } 068 }; 069 } 070 071 maskThread.setPriority(Thread.MAX_PRIORITY); 072 maskThread.setDaemon(true); 073 074 maskThread.start(); 075 } 076 077 public void afterReadLine(final ConsoleReader reader, final String prompt, 078 final Character mask) { 079 if ((maskThread != null) && maskThread.isAlive()) { 080 maskThread.interrupt(); 081 } 082 083 maskThread = null; 084 } 085 }