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.console;
021
022 import org.crsh.text.Style;
023
024 import java.io.Closeable;
025 import java.io.IOException;
026
027 /**
028 * The contract between the console and the underlying stream.
029 */
030 public 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 char.
089 *
090 * @param c the char to write
091 * @throws java.io.IOException any io exception
092 */
093 void write(int c) throws IOException;
094
095 /**
096 * Write a style.
097 *
098 * @param d the data to write
099 * @throws java.io.IOException any io exception
100 */
101 void write(Style d) throws IOException;
102
103 /**
104 * Delete the char under the cursor.
105 *
106 * @throws java.io.IOException any io exception
107 */
108 void writeDel() throws IOException;
109
110 /**
111 * Write a CRLF.
112 *
113 * @throws java.io.IOException any io exception
114 */
115 void writeCRLF() throws IOException;
116
117 /**
118 * Clear screen.
119 *
120 * @throws java.io.IOException any io exception
121 */
122 void cls() throws IOException;
123
124 /**
125 * Move the cursor right.
126 *
127 * @param c the char skipped over
128 * @return true if the cursor moved.
129 * @throws java.io.IOException any io exception
130 */
131 boolean moveRight(char c) throws IOException;
132
133 /**
134 * Move the cursor left.
135 *
136 * @return true if the cursor moved
137 * @throws java.io.IOException any io exception
138 */
139 boolean moveLeft() throws IOException;
140
141 }