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