guacamole-spice-protocol/protocols/ssh/include/terminal.h

357 lines
10 KiB
C
Raw Normal View History

/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is libguac-client-ssh.
*
* The Initial Developer of the Original Code is
* Michael Jumper.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef _SSH_GUAC_TERMINAL_H
#define _SSH_GUAC_TERMINAL_H
#include <stdbool.h>
#include <pthread.h>
#include <guacamole/client.h>
#include "types.h"
2013-04-25 18:55:50 +00:00
#include "display.h"
#include "buffer.h"
#define GUAC_SSH_WHEEL_SCROLL_AMOUNT 3
typedef struct guac_terminal guac_terminal;
2011-08-09 19:31:03 +00:00
/**
* Handler for characters printed to the terminal. When a character is printed,
* the current char handler for the terminal is called and given that
* character.
*/
typedef int guac_terminal_char_handler(guac_terminal* term, char c);
2011-08-09 19:31:03 +00:00
/**
* Represents a terminal emulator which uses a given Guacamole client to
* render itself.
*/
struct guac_terminal {
2011-08-09 19:31:03 +00:00
/**
* The Guacamole client this terminal emulator will use for rendering.
*/
guac_client* client;
/**
* Lock which restricts simultaneous access to this terminal via the root
* guac_terminal_* functions.
*/
pthread_mutex_t lock;
2013-05-22 05:02:11 +00:00
/**
* Pipe which should be written to (and read from) to provide output to
* this terminal. Another thread should read from this pipe when writing
* data to the terminal. It would make sense for the terminal to provide
* this thread, but for simplicity, that logic is left to the guac
* message handler (to give the message handler something to block with).
*/
int stdout_pipe_fd[2];
/**
* Pipe which will be the source of user input. When a terminal code
* generates synthesized user input, that data will be written to
* this pipe.
*/
int stdin_pipe_fd[2];
/**
* The relative offset of the display. A positive value indicates that
* many rows have been scrolled into view, zero indicates that no
* scrolling has occurred. Negative values are illegal.
*/
int scroll_offset;
2011-08-09 19:31:03 +00:00
/**
* The width of the terminal, in characters.
*/
int term_width;
2011-08-09 19:31:03 +00:00
/**
* The height of the terminal, in characters.
*/
int term_height;
2011-08-09 19:31:03 +00:00
/**
* The index of the first row in the scrolling region.
*/
2011-08-06 05:59:42 +00:00
int scroll_start;
2011-08-09 19:31:03 +00:00
/**
* The index of the last row in the scrolling region.
*/
2011-08-06 05:59:42 +00:00
int scroll_end;
2011-08-09 19:31:03 +00:00
/**
* The current row location of the cursor.
*/
int cursor_row;
2011-08-09 19:31:03 +00:00
/**
* The current column location of the cursor.
*/
int cursor_col;
/**
* The row of the rendered cursor.
*/
int visible_cursor_row;
/**
* The column of the rendered cursor.
*/
int visible_cursor_col;
2013-05-21 07:19:53 +00:00
/**
* The row of the saved cursor (ESC 7).
*/
int saved_cursor_row;
/**
* The column of the saved cursor (ESC 7).
*/
int saved_cursor_col;
/**
* The attributes which will be applied to future characters.
*/
guac_terminal_attributes current_attributes;
2011-08-05 19:14:15 +00:00
/**
2013-04-26 08:53:19 +00:00
* The character whose attributes dictate the default attributes
* of all characters. When new screen space is allocated, this
* character fills the gaps.
*/
2013-04-26 08:53:19 +00:00
guac_terminal_char default_char;
2011-08-05 19:14:15 +00:00
/**
* Handler which will receive all printed characters, updating the terminal
* accordingly.
*/
guac_terminal_char_handler* char_handler;
2013-03-24 00:43:35 +00:00
/**
* The difference between the currently-rendered screen and the current
* state of the terminal.
2013-03-24 00:43:35 +00:00
*/
2013-04-25 18:55:50 +00:00
guac_terminal_display* display;
2013-03-24 00:43:35 +00:00
/**
* Current terminal display state. All characters present on the screen
2013-04-25 18:55:50 +00:00
* are within this buffer. This has nothing to do with the display, which
* facilitates transfer of a set of changes to the remote display.
*/
guac_terminal_buffer* buffer;
/**
* Array of arrays of mapped characters, where the character N is located at the N-32
* position within the array. Each element in a contained array is the corresponding Unicode
* codepoint. If NULL, a direct mapping from Unicode is used. The entries of the main array
* correspond to the character set in use (G0, G1, etc.)
*/
const int* char_mapping[2];
/**
* The active character set. For example, 0 for G0, 1 for G1, etc.
*/
int active_char_set;
/**
* Whether text is being selected.
*/
bool text_selected;
/**
* The row that the selection starts at.
*/
int selection_start_row;
/**
* The column that the selection starts at.
*/
int selection_start_column;
/**
* The row that the selection ends at.
*/
int selection_end_row;
/**
* The column that the selection ends at.
*/
int selection_end_column;
/**
* Whether the cursor (arrow) keys should send cursor sequences
* or application sequences (DECCKM).
*/
bool application_cursor_keys;
2013-05-24 20:33:32 +00:00
/**
* Whether a CR should automatically follow a LF, VT, or FF.
*/
bool automatic_carriage_return;
};
/**
* Creates a new guac_terminal, having the given width and height, and
* rendering to the given client.
*/
guac_terminal* guac_terminal_create(guac_client* client,
2012-10-23 08:38:10 +00:00
int width, int height);
/**
* Resets the state of the given terminal, as if it were just allocated.
*/
void guac_terminal_reset(guac_terminal* term);
/**
* Frees all resources associated with the given terminal.
*/
void guac_terminal_free(guac_terminal* term);
/**
* Writes the given string of characters to the terminal.
*/
int guac_terminal_write(guac_terminal* term, const char* c, int size);
2011-08-09 19:31:03 +00:00
/**
* Sets the character at the given row and column to the specified value.
*/
2013-05-02 21:56:20 +00:00
int guac_terminal_set(guac_terminal* term, int row, int col, int codepoint);
/**
2013-04-26 08:53:19 +00:00
* Clears the given region within a single row.
*/
2013-04-26 08:53:19 +00:00
int guac_terminal_clear_columns(guac_terminal* term,
int row, int start_col, int end_col);
/**
* Clears the given region from right-to-left, top-to-bottom, replacing
* all characters with the current background color and attributes.
*/
int guac_terminal_clear_range(guac_terminal* term,
int start_row, int start_col,
int end_row, int end_col);
/**
* Scrolls the terminal's current scroll region up by one row.
*/
int guac_terminal_scroll_up(guac_terminal* term,
int start_row, int end_row, int amount);
/**
* Scrolls the terminal's current scroll region down by one row.
*/
int guac_terminal_scroll_down(guac_terminal* term,
int start_row, int end_row, int amount);
/**
* Commits the current cursor location, updating the visible cursor
* on the screen.
*/
void guac_terminal_commit_cursor(guac_terminal* term);
/**
* Scroll down the display by the given amount, replacing the new space with
* data from the buffer. If not enough data is available, the maximum
* amount will be scrolled.
*/
void guac_terminal_scroll_display_down(guac_terminal* terminal, int amount);
/**
* Scroll up the display by the given amount, replacing the new space with data
* from either the buffer or the terminal buffer. If not enough data is
* available, the maximum amount will be scrolled.
*/
void guac_terminal_scroll_display_up(guac_terminal* terminal, int amount);
/**
* Marks the start of text selection at the given row and column.
*/
void guac_terminal_select_start(guac_terminal* terminal, int row, int column);
/**
* Updates the end of text selection at the given row and column.
*/
void guac_terminal_select_update(guac_terminal* terminal, int row, int column);
2013-04-05 18:31:46 +00:00
/**
* Ends text selection, removing any highlight. Character data is stored in the
* string buffer provided.
2013-04-05 18:31:46 +00:00
*/
void guac_terminal_select_end(guac_terminal* terminal, char* string);
2013-04-05 18:31:46 +00:00
/* LOW-LEVEL TERMINAL OPERATIONS */
/**
* Copies the given range of columns to a new location, offset from
* the original by the given number of columns.
*/
void guac_terminal_copy_columns(guac_terminal* terminal, int row,
int start_column, int end_column, int offset);
/**
* Copies the given range of rows to a new location, offset from the
* original by the given number of rows.
*/
2013-04-26 08:53:19 +00:00
void guac_terminal_copy_rows(guac_terminal* terminal,
int start_row, int end_row, int offset);
/**
* Sets the given range of columns within the given row to the given
* character.
*/
void guac_terminal_set_columns(guac_terminal* terminal, int row,
int start_column, int end_column, guac_terminal_char* character);
/**
* Resize the terminal to the given dimensions.
*/
void guac_terminal_resize(guac_terminal* term, int width, int height);
/**
* Flushes all pending operations within the given guac_terminal.
*/
void guac_terminal_flush(guac_terminal* terminal);
#endif