001 /* 002 * Copyright (C) 2010 eXo Platform SAS. 003 * 004 * This is free software; you can redistribute it and/or modify it 005 * under the terms of the GNU Lesser General Public License as 006 * published by the Free Software Foundation; either version 2.1 of 007 * the License, or (at your option) any later version. 008 * 009 * This software is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * You should have received a copy of the GNU Lesser General Public 015 * License along with this software; if not, write to the Free 016 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 017 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 018 */ 019 020 package org.crsh.term.spi; 021 022 import org.crsh.term.CodeType; 023 024 import java.io.Closeable; 025 import java.io.IOException; 026 027 /** 028 * The input/output of a term. 029 * 030 * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a> 031 * @version $Revision$ 032 */ 033 public interface TermIO extends Closeable { 034 035 /** 036 * Reads an input value. 037 * 038 * @return the value read 039 * @throws IOException any io exception 040 */ 041 int read() throws IOException; 042 043 /** 044 * Returns the term width in chars. When the value is not positive it means the value could not be determined. 045 * 046 * @return the term width 047 */ 048 int getWidth(); 049 050 /** 051 * Retrieves the value of a property specified by this TermIO 052 * 053 * @param name the name of the property 054 * @return value of the property 055 */ 056 String getProperty(String name); 057 058 /** 059 * Decode the intput value. 060 * 061 * @param code the code 062 * @return the input value type 063 */ 064 CodeType decode(int code); 065 066 /** 067 * Flush output. 068 * 069 * @throws IOException any io exception 070 */ 071 void flush() throws IOException; 072 073 /** 074 * Write a string. 075 * 076 * @param s the string to write 077 * @throws IOException any io exception 078 */ 079 void write(String s) throws IOException; 080 081 /** 082 * Write a char. 083 * 084 * @param c the char to write 085 * @throws IOException any io exception 086 */ 087 void write(char c) throws IOException; 088 089 /** 090 * Delete the char under the cursor. 091 * 092 * @throws IOException any io exception 093 */ 094 void writeDel() throws IOException; 095 096 /** 097 * Write a CRLF. 098 * 099 * @throws IOException any io exception 100 */ 101 void writeCRLF() throws IOException; 102 103 /** 104 * Move the cursor right. 105 * 106 * @param c the char skipped over 107 * @return true if the cursor moved. 108 * @throws IOException any io exception 109 */ 110 boolean moveRight(char c) throws IOException; 111 112 /** 113 * Move the cursor left. 114 * 115 * @return true if the cursor moved 116 * @throws IOException any io exception 117 */ 118 boolean moveLeft() throws IOException; 119 }