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