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