001 /* 002 * Copyright (C) 2012 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 import org.crsh.text.Style; 024 025 import java.io.Closeable; 026 import java.io.IOException; 027 028 public interface TermIO extends Closeable { 029 030 /** 031 * Reads an input value. 032 * 033 * @return the value read 034 * @throws IOException any io exception 035 */ 036 int read() throws IOException; 037 038 /** 039 * Returns the term width in chars. When the value is not positive it means the value could not be determined. 040 * 041 * @return the term width 042 */ 043 int getWidth(); 044 045 /** 046 * Returns the term height in chars. When the value is not positive it means the value could not be determined. 047 * 048 * @return the term height 049 */ 050 int getHeight(); 051 052 /** 053 * Retrieves the value of a property specified by this TermIO 054 * 055 * @param name the name of the property 056 * @return value of the property 057 */ 058 String getProperty(String name); 059 060 /** 061 * Take control of the alternate buffer. When the alternate buffer is already used 062 * nothing happens. The buffer switch should occur when then {@link #flush()} method 063 * is invoked. 064 * 065 * @return true if the alternate buffer is shown 066 */ 067 boolean takeAlternateBuffer() throws IOException; 068 069 /** 070 * Release control of the alternate buffer. When the normal buffer is already used 071 * nothing happens. The buffer switch should occur when then {@link #flush()} method 072 * is invoked. 073 * 074 * @return true if the usual buffer is shown 075 */ 076 boolean releaseAlternateBuffer() throws IOException; 077 078 /** 079 * Decode the intput value. 080 * 081 * @param code the code 082 * @return the input value type 083 */ 084 CodeType decode(int code); 085 086 /** 087 * Flush output. 088 * 089 * @throws IOException any io exception 090 */ 091 void flush() throws IOException; 092 093 /** 094 * Write a string. 095 * 096 * @param s the string to write 097 * @throws IOException any io exception 098 */ 099 void write(CharSequence s) throws IOException; 100 101 /** 102 * Write a char. 103 * 104 * @param c the char to write 105 * @throws IOException any io exception 106 */ 107 void write(char c) throws IOException; 108 109 /** 110 * Write a style. 111 * 112 * @param d the data to write 113 * @throws IOException any io exception 114 */ 115 void write(Style d) throws IOException; 116 117 /** 118 * Delete the char under the cursor. 119 * 120 * @throws IOException any io exception 121 */ 122 void writeDel() throws IOException; 123 124 /** 125 * Write a CRLF. 126 * 127 * @throws IOException any io exception 128 */ 129 void writeCRLF() throws IOException; 130 131 /** 132 * Clear screen. 133 * 134 * @throws IOException any io exception 135 */ 136 void cls() throws IOException; 137 138 /** 139 * Move the cursor right. 140 * 141 * @param c the char skipped over 142 * @return true if the cursor moved. 143 * @throws IOException any io exception 144 */ 145 boolean moveRight(char c) throws IOException; 146 147 /** 148 * Move the cursor left. 149 * 150 * @return true if the cursor moved 151 * @throws IOException any io exception 152 */ 153 boolean moveLeft() throws IOException; 154 }