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.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    /**
029     * The input/output of a term.
030     *
031     * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
032     * @version $Revision$
033     */
034    public interface TermIO extends Closeable {
035    
036      /**
037       * Reads an input value.
038       *
039       * @return the value read
040       * @throws IOException any io exception
041       */
042      int read() throws IOException;
043    
044      /**
045       * Returns the term width in chars. When the value is not positive it means the value could not be determined.
046       *
047       * @return the term width
048       */
049      int getWidth();
050    
051      /**
052       * Retrieves the value of a property specified by this TermIO
053       *
054       * @param name the name of the property
055       * @return value of the property
056       */
057      String getProperty(String name);
058    
059      /**
060       * Decode the intput value.
061       *
062       * @param code the code
063       * @return the input value type
064       */
065      CodeType decode(int code);
066    
067      /**
068       * Flush output.
069       *
070       * @throws IOException any io exception
071       */
072      void flush() throws IOException;
073    
074      /**
075       * Write a string.
076       *
077       * @param s the string to write
078       * @throws IOException any io exception
079       */
080      void write(String s) throws IOException;
081    
082      /**
083       * Write a char.
084       *
085       * @param c the char to write
086       * @throws IOException any io exception
087       */
088      void write(char c) throws IOException;
089    
090      /**
091       * Write a style.
092       *
093       * @param d the data to write
094       * @throws IOException any io exception
095       */
096      void write(Style d) throws IOException;
097    
098      /**
099       * Delete the char under the cursor.
100       *
101       * @throws IOException any io exception
102       */
103      void writeDel() throws IOException;
104    
105      /**
106       * Write a CRLF.
107       *
108       * @throws IOException any io exception
109       */
110      void writeCRLF() throws IOException;
111    
112      /**
113       * Move the cursor right.
114       *
115       * @param c the char skipped over
116       * @return true if the cursor moved.
117       * @throws IOException any io exception
118       */
119      boolean moveRight(char c) throws IOException;
120    
121      /**
122       * Move the cursor left.
123       *
124       * @return true if the cursor moved
125       * @throws IOException any io exception
126       */
127      boolean moveLeft() throws IOException;
128    }