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