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       * Retrieves the value of a property specified by this TermIO
051       *
052       * @param name the name of the property
053       * @return value of the property
054       */
055      String getProperty(String name);
056    
057      /**
058       * Decode the intput value.
059       *
060       * @param code the code
061       * @return the input value type
062       */
063      CodeType decode(int code);
064    
065      /**
066       * Close the input/output.
067       */
068      void close();
069    
070      /**
071       * Flush output.
072       *
073       * @throws IOException any io exception
074       */
075      void flush() throws IOException;
076    
077      /**
078       * Write a string.
079       *
080       * @param s the string to write
081       * @throws IOException any io exception
082       */
083      void write(String s) throws IOException;
084    
085      /**
086       * Write a char.
087       *
088       * @param c the char to write
089       * @throws IOException any io exception
090       */
091      void write(char c) throws IOException;
092    
093      /**
094       * Delete the char under the cursor.
095       *
096       * @throws IOException any io exception
097       */
098      void writeDel() throws IOException;
099    
100      /**
101       * Write a CRLF.
102       *
103       * @throws IOException any io exception
104       */
105      void writeCRLF() throws IOException;
106    
107      /**
108       * Move the cursor right.
109       *
110       * @param c the char skipped over
111       * @return true if the cursor moved.
112       * @throws IOException any io exception
113       */
114      boolean moveRight(char c) throws IOException;
115    
116      /**
117       * Move the cursor left.
118       *
119       * @return true if the cursor moved
120       * @throws IOException any io exception
121       */
122      boolean moveLeft() throws IOException;
123    }