Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010 SAP AG All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: Lazar Kirchev, SAP AG - initial API and implementation /
 
 
 package org.eclipse.equinox.console.common;
 
 import java.io.File;
 import java.util.Map;
 
A common superclass for content processor for the telnet protocol and for command line editing (processing delete, backspace, arrows, command history, etc.).
 
 public abstract class Scanner {
 
 	private byte BACKSPACE;
 	private byte DEL;
     protected static final byte BS = 8;  
     protected static final byte LF = 10;
     protected static final byte CR = 13;
     protected static final byte ESC = 27;
     protected static final byte SPACE = 32;
     protected static final byte MAX_CHAR = 127;
     protected static final String DEFAULT_TTYPE = . == '/' ? "XTERM" : "ANSI";
     // shows if user input should be echoed to the console
     private boolean isEchoEnabled = true;
 
     protected OutputStream toTelnet;
     protected ConsoleInputStream toShell;
     protected Map<StringKEYScurrentEscapesToKey;
     protected String[] escapes;
     
     public Scanner(ConsoleInputStream toShellOutputStream toTelnet) {
         this. = toShell;
         this. = toTelnet;
         .put("ANSI"new ANSITerminalTypeMappings());
         .put("VT100"new VT100TerminalTypeMappings());
         VT220TerminalTypeMappings vtMappings = new VT220TerminalTypeMappings();
         .put("VT220"vtMappings);
         .put("XTERM"vtMappings);
         .put("VT320"new VT320TerminalTypeMappings());
         .put("SCO"new SCOTerminalTypeMappings());
     }
 
     public abstract void scan(int bthrows IOException;
 
     public void toggleEchoEnabled(boolean isEnabled) {
     	 = isEnabled;
     }
     
     protected void echo(int bthrows IOException {
     	if () {
     		.write(b);
     	}
     }
 
     protected void flush() throws IOException {
         .flush();
     }
 
     protected KEYS checkEscape(String possibleEsc) {
         if (.get(possibleEsc) != null) {
             return .get(possibleEsc);
         }
 
         for (String escape : ) {
             if (escape.startsWith(possibleEsc)) {
                 return .;
             }
         }
         return .;
     }
 
     protected String esc;
     protected boolean isEsc = false;
 
     protected void startEsc() {
          = true;
          = "";
     }
    protected abstract void scanEsc(final int bthrows IOException;
	public byte getBackspace() {
		return ;
	}
	public void setBackspace(byte backspace) {
		 = backspace;
	}
	public byte getDel() {
		return ;
	}
	public void setDel(byte del) {
		 = del;
	}
	}
	public void setCurrentEscapesToKey(Map<StringKEYScurrentEscapesToKey) {
		this. = currentEscapesToKey;
	}
	public String[] getEscapes() {
        if ( != null) {
        	String[] copy = new String[.];
        	System.arraycopy(, 0, copy, 0, .);
        	return copy;
        } else {
            return null;
        }
	}
	public void setEscapes(String[] escapes) {
        if (escapes != null) {
            this. = new String[escapes.length];
        	System.arraycopy(escapes, 0, this., 0, escapes.length);
        } else {
            this. = null;
        }
	}
New to GrepCode? Check out our FAQ X