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;
021
022 import java.io.IOException;
023
024 /**
025 * An high level term abstraction.
026 *
027 * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
028 * @version $Revision$
029 */
030 public interface Term {
031
032
033 /**
034 * Returns the term width in chars. When the value is not positive it means the value could not be determined.
035 *
036 * @return the term width
037 */
038 int getWidth();
039
040 /**
041 * Set the echo mode on the term.
042 *
043 * @param echo the echo mode
044 */
045 void setEcho(boolean echo);
046
047 /**
048 * Read the next term event. This operation is a blocking operation that blocks until data is available or until
049 * term is closed.
050 *
051 * @return the next term event
052 * @throws IOException any io exception
053 */
054 TermEvent read() throws IOException;
055
056 /**
057 * Write a message on the console, the text will be appended.
058 *
059 *
060 * @param msg the message to write
061 * @throws IOException any io exception
062 */
063 void write(CharSequence msg) throws IOException;
064
065 /**
066 * Insert a message on the console just after the cursor.
067 *
068 *
069 * @param msg the message to insert
070 * @throws IOException any io exception
071 */
072 void bufferInsert(CharSequence msg) throws IOException;
073
074 /**
075 * Returns the current buffer;
076 *
077 * @return the buffer
078 */
079 CharSequence getBuffer();
080
081 /**
082 * Append a line to the term history.
083 *
084 * @param line the history line to append
085 */
086 void addToHistory(CharSequence line);
087
088 /**
089 * Close the term. If threads are blocked in the {@link #read()} operation, those thread should be unblocked.
090 */
091 void close();
092
093 }