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

290 lines
8.1 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;
/**
* 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 attributes which will be applied to future characters.
*/
guac_terminal_attributes current_attributes;
2011-08-05 19:14:15 +00:00
/**
* The attributes which will be applied to characters by default, unless
* other attributes are explicitly specified.
*/
guac_terminal_attributes default_attributes;
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;
/**
* 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;
};
/**
* 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);
/**
* 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.
*/
int guac_terminal_set(guac_terminal* term, int row, int col, char c);
/**
* Clears a rectangular region of characters, replacing them with the
* current background color and attributes.
*/
int guac_terminal_clear(guac_terminal* term,
int row, int col, int rows, int cols);
/**
* 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);
/**
* Toggles the reverse attribute of the character at the given location.
*/
int guac_terminal_toggle_reverse(guac_terminal* term, int row, int col);
/**
* 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.
2013-04-05 18:31:46 +00:00
*/
void guac_terminal_select_end(guac_terminal* terminal);
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.
*/
void guac_terminal_copy_rows(guac_terminal* terminal, int src_row, int rows,
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 rows, int cols);
/**
* Flushes all pending operations within the given guac_terminal.
*/
void guac_terminal_flush(guac_terminal* terminal);
#endif