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
020package org.crsh.telnet.term;
021
022import org.crsh.text.ScreenContext;
023
024import java.io.Closeable;
025import java.io.IOException;
026
027public interface Term extends Closeable, ScreenContext {
028
029  /**
030   * Retrieves the value of a property specified by this Term
031   *
032   * @param name name of the term property
033   * @return value of the term property
034   */
035  String getProperty(String name);
036
037  /**
038   * Take control of the alternate buffer. When the alternate buffer is already used
039   * nothing happens. The buffer switch should occur when then {@link #flush()} method
040   * is invoked.
041   *
042   * @return true if the alternate buffer is shown
043   */
044  boolean takeAlternateBuffer() throws IOException;
045
046  /**
047   * Release control of the alternate buffer. When the normal buffer is already used
048   * nothing happens. The buffer switch should occur when then {@link #flush()} method
049   * is invoked.
050   *
051   * @return true if the usual buffer is shown
052   */
053  boolean releaseAlternateBuffer() throws IOException;
054
055  /**
056   * Set the echo mode on the term.
057   *
058   * @param echo the echo mode
059   */
060  void setEcho(boolean echo);
061
062  /**
063   * Read the next term event. This operation is a blocking operation that blocks until data is available or until
064   * term is closed.
065   *
066   * @return the next term event
067   * @throws IOException any io exception
068   */
069  TermEvent read() throws IOException;
070
071  /**
072   * Returns the direct buffer, any char appended in the returned appendable will translate into an
073   * insertion in the buffer.
074   *
075   * @return the insert buffer.
076   */
077  Appendable getDirectBuffer();
078
079  /**
080   * Returns the current buffer content to the cursor;
081   *
082   * @return the buffer
083   */
084  CharSequence getBuffer();
085
086  /**
087   * Append a line to the term history.
088   *
089   * @param line the history line to append
090   */
091  void addToHistory(CharSequence line);
092
093}