2011-08-04 18:46:21 +00:00
|
|
|
|
|
|
|
/* ***** 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
|
|
|
|
|
2013-03-20 05:48:43 +00:00
|
|
|
#include <stdbool.h>
|
2013-04-07 23:55:06 +00:00
|
|
|
#include <pthread.h>
|
2013-03-20 05:48:43 +00:00
|
|
|
|
2011-08-04 18:46:21 +00:00
|
|
|
#include <guacamole/client.h>
|
|
|
|
|
2013-04-25 18:54:00 +00:00
|
|
|
#include "types.h"
|
2013-04-25 18:55:50 +00:00
|
|
|
#include "display.h"
|
2013-04-25 18:54:00 +00:00
|
|
|
#include "buffer.h"
|
|
|
|
|
2013-04-08 07:47:08 +00:00
|
|
|
#define GUAC_SSH_WHEEL_SCROLL_AMOUNT 3
|
|
|
|
|
2012-12-09 08:35:37 +00:00
|
|
|
typedef struct guac_terminal guac_terminal;
|
2011-08-04 18:46:21 +00:00
|
|
|
|
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.
|
|
|
|
*/
|
2012-12-09 08:35:37 +00:00
|
|
|
typedef int guac_terminal_char_handler(guac_terminal* term, char c);
|
2011-08-05 02:17:44 +00:00
|
|
|
|
2011-08-09 19:31:03 +00:00
|
|
|
/**
|
|
|
|
* Represents a terminal emulator which uses a given Guacamole client to
|
|
|
|
* render itself.
|
|
|
|
*/
|
2012-12-09 08:35:37 +00:00
|
|
|
struct guac_terminal {
|
2011-08-04 18:46:21 +00:00
|
|
|
|
2011-08-09 19:31:03 +00:00
|
|
|
/**
|
|
|
|
* The Guacamole client this terminal emulator will use for rendering.
|
|
|
|
*/
|
2011-08-04 18:46:21 +00:00
|
|
|
guac_client* client;
|
2011-08-05 02:36:04 +00:00
|
|
|
|
2013-04-07 23:55:06 +00:00
|
|
|
/**
|
|
|
|
* Lock which restricts simultaneous access to this terminal via the root
|
|
|
|
* guac_terminal_* functions.
|
|
|
|
*/
|
|
|
|
pthread_mutex_t lock;
|
|
|
|
|
2013-04-05 08:32:33 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-08-04 18:46:21 +00:00
|
|
|
int term_width;
|
2011-08-09 19:31:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The height of the terminal, in characters.
|
|
|
|
*/
|
2011-08-04 18:46:21 +00:00
|
|
|
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.
|
|
|
|
*/
|
2011-08-04 18:46:21 +00:00
|
|
|
int cursor_row;
|
2011-08-09 19:31:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The current column location of the cursor.
|
|
|
|
*/
|
2011-08-04 18:46:21 +00:00
|
|
|
int cursor_col;
|
|
|
|
|
2013-03-20 05:48:43 +00:00
|
|
|
/**
|
|
|
|
* The attributes which will be applied to future characters.
|
|
|
|
*/
|
|
|
|
guac_terminal_attributes current_attributes;
|
2011-08-05 19:14:15 +00:00
|
|
|
|
2013-03-20 05:48:43 +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-03-20 05:48:43 +00:00
|
|
|
*/
|
2013-04-26 08:53:19 +00:00
|
|
|
guac_terminal_char default_char;
|
2011-08-05 19:14:15 +00:00
|
|
|
|
2013-03-20 05:48:43 +00:00
|
|
|
/**
|
|
|
|
* Handler which will receive all printed characters, updating the terminal
|
|
|
|
* accordingly.
|
|
|
|
*/
|
2012-12-09 08:35:37 +00:00
|
|
|
guac_terminal_char_handler* char_handler;
|
2011-08-05 02:36:04 +00:00
|
|
|
|
2013-03-24 00:43:35 +00:00
|
|
|
/**
|
2013-03-27 19:44:40 +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
|
|
|
|
2013-03-29 08:56:27 +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
|
2013-03-29 08:56:27 +00:00
|
|
|
* facilitates transfer of a set of changes to the remote display.
|
|
|
|
*/
|
|
|
|
guac_terminal_buffer* buffer;
|
|
|
|
|
2013-04-15 08:22:05 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2011-08-05 02:17:44 +00:00
|
|
|
};
|
2011-08-04 18:46:21 +00:00
|
|
|
|
2013-03-20 05:48:43 +00:00
|
|
|
/**
|
|
|
|
* Creates a new guac_terminal, having the given width and height, and
|
|
|
|
* rendering to the given client.
|
|
|
|
*/
|
2012-12-09 08:35:37 +00:00
|
|
|
guac_terminal* guac_terminal_create(guac_client* client,
|
2012-10-23 08:38:10 +00:00
|
|
|
int width, int height);
|
|
|
|
|
2013-03-20 05:48:43 +00:00
|
|
|
/**
|
|
|
|
* Frees all resources associated with the given terminal.
|
|
|
|
*/
|
2012-12-09 08:35:37 +00:00
|
|
|
void guac_terminal_free(guac_terminal* term);
|
2011-08-04 18:46:21 +00:00
|
|
|
|
2013-03-20 05:48:43 +00:00
|
|
|
/**
|
|
|
|
* Writes the given string of characters to the terminal.
|
|
|
|
*/
|
2012-12-09 08:35:37 +00:00
|
|
|
int guac_terminal_write(guac_terminal* term, const char* c, int size);
|
2011-08-09 19:31:03 +00:00
|
|
|
|
2013-03-24 23:56:17 +00:00
|
|
|
/**
|
|
|
|
* Sets the character at the given row and column to the specified value.
|
|
|
|
*/
|
2012-12-09 08:35:37 +00:00
|
|
|
int guac_terminal_set(guac_terminal* term, int row, int col, char c);
|
2011-08-04 18:46:21 +00:00
|
|
|
|
2013-03-24 23:56:17 +00:00
|
|
|
/**
|
2013-04-26 08:53:19 +00:00
|
|
|
* Clears the given region within a single row.
|
2013-03-24 23:56:17 +00:00
|
|
|
*/
|
2013-04-26 08:53:19 +00:00
|
|
|
int guac_terminal_clear_columns(guac_terminal* term,
|
|
|
|
int row, int start_col, int end_col);
|
2011-08-05 07:20:09 +00:00
|
|
|
|
2013-03-24 23:56:17 +00:00
|
|
|
/**
|
|
|
|
* Clears the given region from right-to-left, top-to-bottom, replacing
|
2013-03-29 09:51:31 +00:00
|
|
|
* all characters with the current background color and attributes.
|
2013-03-24 23:56:17 +00:00
|
|
|
*/
|
|
|
|
int guac_terminal_clear_range(guac_terminal* term,
|
|
|
|
int start_row, int start_col,
|
2013-03-29 09:51:31 +00:00
|
|
|
int end_row, int end_col);
|
2013-03-24 23:56:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Scrolls the terminal's current scroll region up by one row.
|
|
|
|
*/
|
2012-12-09 08:35:37 +00:00
|
|
|
int guac_terminal_scroll_up(guac_terminal* term,
|
2011-08-05 07:20:09 +00:00
|
|
|
int start_row, int end_row, int amount);
|
|
|
|
|
2013-03-24 23:56:17 +00:00
|
|
|
/**
|
|
|
|
* Scrolls the terminal's current scroll region down by one row.
|
|
|
|
*/
|
2012-12-09 08:35:37 +00:00
|
|
|
int guac_terminal_scroll_down(guac_terminal* term,
|
2011-08-10 01:32:54 +00:00
|
|
|
int start_row, int end_row, int amount);
|
2011-08-05 07:20:09 +00:00
|
|
|
|
2013-03-29 09:51:31 +00:00
|
|
|
/**
|
|
|
|
* Toggles the reverse attribute of the character at the given location.
|
|
|
|
*/
|
|
|
|
int guac_terminal_toggle_reverse(guac_terminal* term, int row, int col);
|
|
|
|
|
2013-03-24 00:06:02 +00:00
|
|
|
/**
|
2013-04-25 18:54:00 +00:00
|
|
|
* 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.
|
2013-03-29 08:56:27 +00:00
|
|
|
*/
|
2013-04-25 18:54:00 +00:00
|
|
|
void guac_terminal_scroll_display_down(guac_terminal* terminal, int amount);
|
2013-03-29 08:56:27 +00:00
|
|
|
|
2013-04-05 08:32:33 +00:00
|
|
|
/**
|
2013-04-25 18:54:00 +00:00
|
|
|
* 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.
|
2013-04-05 08:32:33 +00:00
|
|
|
*/
|
2013-04-25 18:54:00 +00:00
|
|
|
void guac_terminal_scroll_display_up(guac_terminal* terminal, int amount);
|
2013-04-05 08:32:33 +00:00
|
|
|
|
|
|
|
/**
|
2013-04-25 18:54:00 +00:00
|
|
|
* Marks the start of text selection at the given row and column.
|
2013-04-05 08:32:33 +00:00
|
|
|
*/
|
2013-04-25 18:54:00 +00:00
|
|
|
void guac_terminal_select_start(guac_terminal* terminal, int row, int column);
|
2013-04-05 08:32:33 +00:00
|
|
|
|
|
|
|
/**
|
2013-04-25 18:54:00 +00:00
|
|
|
* Updates the end of text selection at the given row and column.
|
2013-04-05 08:32:33 +00:00
|
|
|
*/
|
2013-04-25 18:54:00 +00:00
|
|
|
void guac_terminal_select_update(guac_terminal* terminal, int row, int column);
|
2013-04-05 08:32:33 +00:00
|
|
|
|
2013-04-05 18:31:46 +00:00
|
|
|
/**
|
2013-04-25 18:54:00 +00:00
|
|
|
* Ends text selection, removing any highlight.
|
2013-04-05 18:31:46 +00:00
|
|
|
*/
|
2013-04-25 18:54:00 +00:00
|
|
|
void guac_terminal_select_end(guac_terminal* terminal);
|
2013-04-05 18:31:46 +00:00
|
|
|
|
2013-04-25 18:54:00 +00:00
|
|
|
/* LOW-LEVEL TERMINAL OPERATIONS */
|
2013-04-05 08:32:33 +00:00
|
|
|
|
|
|
|
/**
|
2013-04-25 18:54:00 +00:00
|
|
|
* Copies the given range of columns to a new location, offset from
|
|
|
|
* the original by the given number of columns.
|
2013-04-05 08:32:33 +00:00
|
|
|
*/
|
2013-04-25 18:54:00 +00:00
|
|
|
void guac_terminal_copy_columns(guac_terminal* terminal, int row,
|
|
|
|
int start_column, int end_column, int offset);
|
2013-04-05 08:32:33 +00:00
|
|
|
|
2013-04-15 08:22:05 +00:00
|
|
|
/**
|
2013-04-25 18:54:00 +00:00
|
|
|
* Copies the given range of rows to a new location, offset from the
|
|
|
|
* original by the given number of rows.
|
2013-04-15 08:22:05 +00:00
|
|
|
*/
|
2013-04-26 08:53:19 +00:00
|
|
|
void guac_terminal_copy_rows(guac_terminal* terminal,
|
2013-04-25 18:54:00 +00:00
|
|
|
int start_row, int end_row, int offset);
|
2013-04-15 08:22:05 +00:00
|
|
|
|
|
|
|
/**
|
2013-04-25 18:54:00 +00:00
|
|
|
* Sets the given range of columns within the given row to the given
|
|
|
|
* character.
|
2013-04-15 08:22:05 +00:00
|
|
|
*/
|
2013-04-25 18:54:00 +00:00
|
|
|
void guac_terminal_set_columns(guac_terminal* terminal, int row,
|
|
|
|
int start_column, int end_column, guac_terminal_char* character);
|
2013-04-15 08:22:05 +00:00
|
|
|
|
|
|
|
/**
|
2013-04-25 18:54:00 +00:00
|
|
|
* Resize the terminal to the given dimensions.
|
2013-04-15 08:22:05 +00:00
|
|
|
*/
|
2013-04-26 21:14:19 +00:00
|
|
|
void guac_terminal_resize(guac_terminal* term, int width, int height);
|
2013-04-15 08:22:05 +00:00
|
|
|
|
|
|
|
/**
|
2013-04-25 18:54:00 +00:00
|
|
|
* Flushes all pending operations within the given guac_terminal.
|
2013-04-15 08:22:05 +00:00
|
|
|
*/
|
2013-04-25 18:54:00 +00:00
|
|
|
void guac_terminal_flush(guac_terminal* terminal);
|
2013-04-15 08:22:05 +00:00
|
|
|
|
2011-08-04 18:46:21 +00:00
|
|
|
#endif
|
|
|
|
|