2011-08-05 02:17:44 +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 ***** */
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2013-05-22 05:37:53 +00:00
|
|
|
#include "common.h"
|
2012-12-09 08:35:37 +00:00
|
|
|
#include "terminal.h"
|
|
|
|
#include "terminal_handlers.h"
|
2011-08-05 02:17:44 +00:00
|
|
|
|
2012-12-09 08:35:37 +00:00
|
|
|
int guac_terminal_echo(guac_terminal* term, char c) {
|
2011-08-05 02:17:44 +00:00
|
|
|
|
2013-04-15 22:24:21 +00:00
|
|
|
static int bytes_remaining = 0;
|
|
|
|
static int codepoint = 0;
|
|
|
|
|
|
|
|
/* 1-byte UTF-8 codepoint */
|
|
|
|
if ((c & 0x80) == 0x00) { /* 0xxxxxxx */
|
|
|
|
codepoint = c & 0x7F;
|
|
|
|
bytes_remaining = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 2-byte UTF-8 codepoint */
|
|
|
|
else if ((c & 0xE0) == 0xC0) { /* 110xxxxx */
|
|
|
|
codepoint = c & 0x1F;
|
|
|
|
bytes_remaining = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 3-byte UTF-8 codepoint */
|
|
|
|
else if ((c & 0xF0) == 0xE0) { /* 1110xxxx */
|
|
|
|
codepoint = c & 0x0F;
|
|
|
|
bytes_remaining = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 4-byte UTF-8 codepoint */
|
|
|
|
else if ((c & 0xF8) == 0xF0) { /* 11110xxx */
|
|
|
|
codepoint = c & 0x07;
|
|
|
|
bytes_remaining = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Continuation of UTF-8 codepoint */
|
|
|
|
else if ((c & 0xC0) == 0x80) { /* 10xxxxxx */
|
|
|
|
codepoint = (codepoint << 6) | (c & 0x3F);
|
|
|
|
bytes_remaining--;
|
|
|
|
}
|
|
|
|
|
2013-05-03 09:50:05 +00:00
|
|
|
/* Unrecognized prefix */
|
2013-04-15 22:24:21 +00:00
|
|
|
else {
|
2013-05-03 09:50:05 +00:00
|
|
|
codepoint = '?';
|
|
|
|
bytes_remaining = 0;
|
2013-04-15 22:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we need more bytes, wait for more bytes */
|
|
|
|
if (bytes_remaining != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (codepoint) {
|
2011-08-05 02:17:44 +00:00
|
|
|
|
|
|
|
/* Bell */
|
|
|
|
case 0x07:
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Backspace */
|
|
|
|
case 0x08:
|
|
|
|
if (term->cursor_col >= 1)
|
|
|
|
term->cursor_col--;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Carriage return */
|
|
|
|
case '\r':
|
|
|
|
term->cursor_col = 0;
|
|
|
|
break;
|
|
|
|
|
2013-05-21 07:55:46 +00:00
|
|
|
/* Line feed / VT / FF */
|
2011-08-05 02:17:44 +00:00
|
|
|
case '\n':
|
2013-05-21 07:57:44 +00:00
|
|
|
case 0x0B: /* VT */
|
|
|
|
case 0x0C: /* FF */
|
2011-08-05 02:17:44 +00:00
|
|
|
term->cursor_row++;
|
2011-08-05 21:46:35 +00:00
|
|
|
|
|
|
|
/* Scroll up if necessary */
|
2011-08-06 05:59:42 +00:00
|
|
|
if (term->cursor_row > term->scroll_end) {
|
|
|
|
term->cursor_row = term->scroll_end;
|
2011-08-05 21:46:35 +00:00
|
|
|
|
|
|
|
/* Scroll up by one row */
|
2013-03-24 23:56:17 +00:00
|
|
|
guac_terminal_scroll_up(term, term->scroll_start,
|
|
|
|
term->scroll_end, 1);
|
2011-08-05 21:46:35 +00:00
|
|
|
|
|
|
|
}
|
2011-08-05 02:17:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* ESC */
|
|
|
|
case 0x1B:
|
2012-12-09 08:35:37 +00:00
|
|
|
term->char_handler = guac_terminal_escape;
|
2011-08-05 02:17:44 +00:00
|
|
|
break;
|
|
|
|
|
2013-05-21 07:57:44 +00:00
|
|
|
/* CSI */
|
|
|
|
case 0x9B:
|
|
|
|
term->char_handler = guac_terminal_csi;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* DEL (ignored) */
|
|
|
|
case 0x7F:
|
|
|
|
break;
|
|
|
|
|
2011-08-05 02:17:44 +00:00
|
|
|
/* Displayable chars */
|
|
|
|
default:
|
2011-08-05 21:30:10 +00:00
|
|
|
|
2011-08-05 21:46:35 +00:00
|
|
|
/* Wrap if necessary */
|
|
|
|
if (term->cursor_col >= term->term_width) {
|
|
|
|
term->cursor_col = 0;
|
|
|
|
term->cursor_row++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Scroll up if necessary */
|
2011-08-06 05:59:42 +00:00
|
|
|
if (term->cursor_row > term->scroll_end) {
|
|
|
|
term->cursor_row = term->scroll_end;
|
2011-08-05 21:46:35 +00:00
|
|
|
|
|
|
|
/* Scroll up by one row */
|
2013-03-24 23:56:17 +00:00
|
|
|
guac_terminal_scroll_up(term, term->scroll_start,
|
|
|
|
term->scroll_end, 1);
|
2011-08-05 21:46:35 +00:00
|
|
|
|
2011-08-05 21:30:10 +00:00
|
|
|
}
|
|
|
|
|
2013-03-24 23:56:17 +00:00
|
|
|
/* Write character */
|
2012-12-09 08:35:37 +00:00
|
|
|
guac_terminal_set(term,
|
2011-08-05 02:17:44 +00:00
|
|
|
term->cursor_row,
|
|
|
|
term->cursor_col,
|
2013-05-02 21:56:20 +00:00
|
|
|
codepoint);
|
2011-08-05 02:17:44 +00:00
|
|
|
|
|
|
|
/* Advance cursor */
|
|
|
|
term->cursor_col++;
|
2011-08-05 21:46:35 +00:00
|
|
|
|
2011-08-05 02:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-09 08:35:37 +00:00
|
|
|
int guac_terminal_escape(guac_terminal* term, char c) {
|
2011-08-05 02:17:44 +00:00
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
|
|
|
|
case '(':
|
2012-12-09 08:35:37 +00:00
|
|
|
term->char_handler = guac_terminal_charset;
|
2011-08-05 02:17:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ']':
|
2012-12-09 08:35:37 +00:00
|
|
|
term->char_handler = guac_terminal_osc;
|
2011-08-05 02:17:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '[':
|
2012-12-09 08:35:37 +00:00
|
|
|
term->char_handler = guac_terminal_csi;
|
2011-08-05 02:17:44 +00:00
|
|
|
break;
|
|
|
|
|
2013-05-22 06:38:35 +00:00
|
|
|
case '#':
|
|
|
|
term->char_handler = guac_terminal_ctrl_func;
|
|
|
|
break;
|
|
|
|
|
2013-05-21 07:29:19 +00:00
|
|
|
/* Save Cursor (DECSC) */
|
|
|
|
case '7':
|
2013-05-21 07:19:53 +00:00
|
|
|
term->saved_cursor_row = term->cursor_row;
|
|
|
|
term->saved_cursor_col = term->cursor_col;
|
2013-05-21 07:29:19 +00:00
|
|
|
|
|
|
|
term->char_handler = guac_terminal_echo;
|
2013-05-21 07:19:53 +00:00
|
|
|
break;
|
|
|
|
|
2013-05-21 07:29:19 +00:00
|
|
|
/* Restore Cursor (DECRC) */
|
|
|
|
case '8':
|
2013-05-21 07:19:53 +00:00
|
|
|
|
|
|
|
term->cursor_row = term->saved_cursor_row;
|
|
|
|
if (term->cursor_row >= term->term_height)
|
|
|
|
term->cursor_row = term->term_height - 1;
|
|
|
|
|
|
|
|
term->cursor_col = term->saved_cursor_col;
|
|
|
|
if (term->cursor_col >= term->term_width)
|
|
|
|
term->cursor_col = term->term_width - 1;
|
|
|
|
|
2013-05-21 07:29:19 +00:00
|
|
|
term->char_handler = guac_terminal_echo;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Index (IND) */
|
|
|
|
case 'D':
|
|
|
|
term->cursor_row++;
|
|
|
|
|
|
|
|
/* Scroll up if necessary */
|
|
|
|
if (term->cursor_row > term->scroll_end) {
|
|
|
|
term->cursor_row = term->scroll_end;
|
|
|
|
|
|
|
|
/* Scroll up by one row */
|
|
|
|
guac_terminal_scroll_up(term, term->scroll_start,
|
|
|
|
term->scroll_end, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
term->char_handler = guac_terminal_echo;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Next Line (NEL) */
|
|
|
|
case 'E':
|
|
|
|
term->cursor_col = 0;
|
|
|
|
term->cursor_row++;
|
|
|
|
|
|
|
|
/* Scroll up if necessary */
|
|
|
|
if (term->cursor_row > term->scroll_end) {
|
|
|
|
term->cursor_row = term->scroll_end;
|
|
|
|
|
|
|
|
/* Scroll up by one row */
|
|
|
|
guac_terminal_scroll_up(term, term->scroll_start,
|
|
|
|
term->scroll_end, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
term->char_handler = guac_terminal_echo;
|
2013-05-21 07:19:53 +00:00
|
|
|
break;
|
|
|
|
|
2013-05-21 07:29:19 +00:00
|
|
|
/* Reverse Linefeed */
|
|
|
|
case 'M':
|
2013-05-03 09:50:05 +00:00
|
|
|
|
|
|
|
term->cursor_row--;
|
|
|
|
|
|
|
|
/* Scroll down if necessary */
|
|
|
|
if (term->cursor_row < term->scroll_start) {
|
|
|
|
term->cursor_row = term->scroll_start;
|
|
|
|
|
|
|
|
/* Scroll down by one row */
|
|
|
|
guac_terminal_scroll_down(term, term->scroll_start,
|
|
|
|
term->scroll_end, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
term->char_handler = guac_terminal_echo;
|
|
|
|
break;
|
|
|
|
|
2011-08-05 02:17:44 +00:00
|
|
|
default:
|
2011-11-26 23:35:45 +00:00
|
|
|
guac_client_log_info(term->client, "Unhandled ESC sequence: %c", c);
|
2012-12-09 08:35:37 +00:00
|
|
|
term->char_handler = guac_terminal_echo;
|
2011-08-05 02:17:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-09 08:35:37 +00:00
|
|
|
int guac_terminal_charset(guac_terminal* term, char c) {
|
|
|
|
term->char_handler = guac_terminal_echo;
|
2011-08-05 02:17:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-09 08:35:37 +00:00
|
|
|
int guac_terminal_csi(guac_terminal* term, char c) {
|
2011-08-05 02:17:44 +00:00
|
|
|
|
2011-08-05 02:36:04 +00:00
|
|
|
/* CSI function arguments */
|
|
|
|
static int argc = 0;
|
2011-08-05 21:39:11 +00:00
|
|
|
static int argv[16] = {0};
|
2011-08-05 02:36:04 +00:00
|
|
|
|
2013-05-22 18:38:39 +00:00
|
|
|
/* Sequence prefix, if any */
|
|
|
|
static char private_mode_character = 0;
|
2013-05-22 18:08:38 +00:00
|
|
|
|
2011-08-05 02:36:04 +00:00
|
|
|
/* Argument building counter and buffer */
|
|
|
|
static int argv_length = 0;
|
|
|
|
static char argv_buffer[256];
|
|
|
|
|
2011-08-05 02:17:44 +00:00
|
|
|
/* Digits get concatenated into argv */
|
|
|
|
if (c >= '0' && c <= '9') {
|
|
|
|
|
|
|
|
/* Concatenate digit if there is space in buffer */
|
2011-08-05 02:36:04 +00:00
|
|
|
if (argv_length < sizeof(argv_buffer)-1)
|
|
|
|
argv_buffer[argv_length++] = c;
|
2011-08-05 02:17:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-22 18:38:39 +00:00
|
|
|
/* Specific non-digits stop the parameter, and possibly the sequence */
|
|
|
|
else if ((c >= 0x40 && c <= 0x7E) || c == ';') {
|
2011-08-05 02:17:44 +00:00
|
|
|
|
2011-08-06 00:09:44 +00:00
|
|
|
int i, row, col, amount;
|
2011-08-05 19:41:21 +00:00
|
|
|
|
2011-08-05 02:17:44 +00:00
|
|
|
/* At most 16 parameters */
|
2011-08-05 02:36:04 +00:00
|
|
|
if (argc < 16) {
|
|
|
|
|
2011-08-05 02:17:44 +00:00
|
|
|
/* Finish parameter */
|
2011-08-05 02:36:04 +00:00
|
|
|
argv_buffer[argv_length] = 0;
|
|
|
|
argv[argc++] = atoi(argv_buffer);
|
2011-08-05 02:17:44 +00:00
|
|
|
|
|
|
|
/* Prepare for next parameter */
|
2011-08-05 02:36:04 +00:00
|
|
|
argv_length = 0;
|
|
|
|
|
2011-08-05 02:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle CSI functions */
|
|
|
|
switch (c) {
|
|
|
|
|
2013-05-21 07:35:18 +00:00
|
|
|
/* @: Insert characters (scroll right) */
|
|
|
|
case '@':
|
|
|
|
|
|
|
|
amount = argv[0];
|
|
|
|
if (amount == 0) amount = 1;
|
|
|
|
|
|
|
|
/* Scroll right by amount */
|
|
|
|
if (term->cursor_col + amount < term->term_width)
|
|
|
|
guac_terminal_copy_columns(term, term->cursor_row,
|
|
|
|
term->cursor_col, term->term_width - amount - 1,
|
|
|
|
amount);
|
|
|
|
|
|
|
|
/* Clear left */
|
|
|
|
guac_terminal_clear_columns(term, term->cursor_row,
|
|
|
|
term->cursor_col, term->cursor_col + amount - 1);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2011-08-06 00:09:44 +00:00
|
|
|
/* A: Move up */
|
|
|
|
case 'A':
|
|
|
|
|
|
|
|
/* Get move amount */
|
|
|
|
amount = argv[0];
|
|
|
|
if (amount == 0) amount = 1;
|
|
|
|
|
|
|
|
/* Move cursor */
|
|
|
|
term->cursor_row -= amount;
|
|
|
|
if (term->cursor_row < 0)
|
|
|
|
term->cursor_row = 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* B: Move down */
|
2013-05-22 06:27:34 +00:00
|
|
|
case 'e':
|
2011-08-06 00:09:44 +00:00
|
|
|
case 'B':
|
|
|
|
|
|
|
|
/* Get move amount */
|
|
|
|
amount = argv[0];
|
|
|
|
if (amount == 0) amount = 1;
|
|
|
|
|
|
|
|
/* Move cursor */
|
|
|
|
term->cursor_row += amount;
|
|
|
|
if (term->cursor_row >= term->term_height)
|
|
|
|
term->cursor_row = term->term_height - 1;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* C: Move right */
|
2013-05-22 06:57:55 +00:00
|
|
|
case 'a':
|
2011-08-06 00:09:44 +00:00
|
|
|
case 'C':
|
|
|
|
|
|
|
|
/* Get move amount */
|
|
|
|
amount = argv[0];
|
|
|
|
if (amount == 0) amount = 1;
|
|
|
|
|
|
|
|
/* Move cursor */
|
|
|
|
term->cursor_col += amount;
|
|
|
|
if (term->cursor_col >= term->term_width)
|
|
|
|
term->cursor_col = term->term_width - 1;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2013-05-21 07:35:18 +00:00
|
|
|
/* D: Move left */
|
|
|
|
case 'D':
|
2011-08-05 19:41:21 +00:00
|
|
|
|
2013-05-21 07:35:18 +00:00
|
|
|
/* Get move amount */
|
|
|
|
amount = argv[0];
|
|
|
|
if (amount == 0) amount = 1;
|
2011-08-05 19:41:21 +00:00
|
|
|
|
2013-05-21 07:35:18 +00:00
|
|
|
/* Move cursor */
|
|
|
|
term->cursor_col -= amount;
|
|
|
|
if (term->cursor_col < 0)
|
|
|
|
term->cursor_col = 0;
|
2011-08-05 19:41:21 +00:00
|
|
|
|
2011-08-06 05:59:42 +00:00
|
|
|
break;
|
|
|
|
|
2013-05-22 06:20:13 +00:00
|
|
|
/* E: Move cursor down given number rows, column 1 */
|
|
|
|
case 'E':
|
|
|
|
|
|
|
|
/* Get move amount */
|
|
|
|
amount = argv[0];
|
|
|
|
if (amount == 0) amount = 1;
|
|
|
|
|
|
|
|
/* Move cursor */
|
|
|
|
term->cursor_row += amount;
|
|
|
|
if (term->cursor_row >= term->term_height)
|
|
|
|
term->cursor_row = term->term_height - 1;
|
|
|
|
|
|
|
|
/* Reset to column 1 */
|
|
|
|
term->cursor_col = 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* F: Move cursor up given number rows, column 1 */
|
|
|
|
case 'F':
|
|
|
|
|
|
|
|
/* Get move amount */
|
|
|
|
amount = argv[0];
|
|
|
|
if (amount == 0) amount = 1;
|
|
|
|
|
|
|
|
/* Move cursor */
|
|
|
|
term->cursor_row -= amount;
|
|
|
|
if (term->cursor_row < 0)
|
|
|
|
term->cursor_row = 0;
|
|
|
|
|
|
|
|
/* Reset to column 1 */
|
|
|
|
term->cursor_col = 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2013-05-21 07:47:55 +00:00
|
|
|
/* G: Move cursor, current row */
|
|
|
|
case 'G':
|
|
|
|
col = argv[0]; if (col != 0) col--;
|
|
|
|
term->cursor_col = col;
|
|
|
|
break;
|
|
|
|
|
2011-08-05 02:17:44 +00:00
|
|
|
/* H: Move cursor */
|
2013-05-22 06:27:34 +00:00
|
|
|
case 'f':
|
2011-08-05 02:17:44 +00:00
|
|
|
case 'H':
|
2011-08-05 21:39:11 +00:00
|
|
|
|
|
|
|
row = argv[0]; if (row != 0) row--;
|
|
|
|
col = argv[1]; if (col != 0) col--;
|
|
|
|
|
|
|
|
term->cursor_row = row;
|
|
|
|
term->cursor_col = col;
|
2011-08-05 02:17:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* J: Erase display */
|
|
|
|
case 'J':
|
2011-08-05 07:20:09 +00:00
|
|
|
|
2011-08-05 02:17:44 +00:00
|
|
|
/* Erase from cursor to end of display */
|
2011-08-05 07:20:09 +00:00
|
|
|
if (argv[0] == 0)
|
2012-12-09 08:35:37 +00:00
|
|
|
guac_terminal_clear_range(term,
|
2011-08-05 07:20:09 +00:00
|
|
|
term->cursor_row, term->cursor_col,
|
2013-03-29 09:51:31 +00:00
|
|
|
term->term_height-1, term->term_width-1);
|
2011-08-05 02:17:44 +00:00
|
|
|
|
|
|
|
/* Erase from start to cursor */
|
2011-08-05 07:20:09 +00:00
|
|
|
else if (argv[0] == 1)
|
2012-12-09 08:35:37 +00:00
|
|
|
guac_terminal_clear_range(term,
|
2011-08-05 07:20:09 +00:00
|
|
|
0, 0,
|
2013-03-29 09:51:31 +00:00
|
|
|
term->cursor_row, term->cursor_col);
|
2011-08-05 02:17:44 +00:00
|
|
|
|
|
|
|
/* Entire screen */
|
2011-08-05 07:20:09 +00:00
|
|
|
else if (argv[0] == 2)
|
2013-04-26 08:53:19 +00:00
|
|
|
guac_terminal_clear_range(term,
|
|
|
|
0, 0, term->term_height - 1, term->term_width - 1);
|
2011-08-05 02:17:44 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* K: Erase line */
|
|
|
|
case 'K':
|
|
|
|
|
|
|
|
/* Erase from cursor to end of line */
|
2011-08-05 07:20:09 +00:00
|
|
|
if (argv[0] == 0)
|
2013-04-26 08:53:19 +00:00
|
|
|
guac_terminal_clear_columns(term, term->cursor_row,
|
|
|
|
term->cursor_col, term->term_width - 1);
|
2011-08-05 02:17:44 +00:00
|
|
|
|
|
|
|
/* Erase from start to cursor */
|
2011-08-05 07:20:09 +00:00
|
|
|
else if (argv[0] == 1)
|
2013-04-26 08:53:19 +00:00
|
|
|
guac_terminal_clear_columns(term, term->cursor_row,
|
|
|
|
0, term->cursor_col);
|
2011-08-05 02:17:44 +00:00
|
|
|
|
|
|
|
/* Erase line */
|
2011-08-05 07:20:09 +00:00
|
|
|
else if (argv[0] == 2)
|
2013-04-26 08:53:19 +00:00
|
|
|
guac_terminal_clear_columns(term, term->cursor_row,
|
|
|
|
0, term->term_width - 1);
|
2011-08-05 02:17:44 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2011-08-10 01:32:54 +00:00
|
|
|
/* L: Insert blank lines (scroll down) */
|
|
|
|
case 'L':
|
|
|
|
|
|
|
|
amount = argv[0];
|
|
|
|
if (amount == 0) amount = 1;
|
|
|
|
|
2012-12-09 08:35:37 +00:00
|
|
|
guac_terminal_scroll_down(term,
|
2011-08-10 01:32:54 +00:00
|
|
|
term->cursor_row, term->scroll_end, amount);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2011-08-10 16:31:12 +00:00
|
|
|
/* M: Delete lines (scroll up) */
|
2011-08-10 07:16:50 +00:00
|
|
|
case 'M':
|
|
|
|
|
|
|
|
amount = argv[0];
|
|
|
|
if (amount == 0) amount = 1;
|
|
|
|
|
2012-12-09 08:35:37 +00:00
|
|
|
guac_terminal_scroll_up(term,
|
2011-08-10 07:16:50 +00:00
|
|
|
term->cursor_row, term->scroll_end, amount);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2011-08-10 16:31:12 +00:00
|
|
|
/* P: Delete characters (scroll left) */
|
|
|
|
case 'P':
|
|
|
|
|
|
|
|
amount = argv[0];
|
|
|
|
if (amount == 0) amount = 1;
|
|
|
|
|
|
|
|
/* Scroll left by amount */
|
|
|
|
if (term->cursor_col + amount < term->term_width)
|
2013-04-26 08:53:19 +00:00
|
|
|
guac_terminal_copy_columns(term, term->cursor_row,
|
|
|
|
term->cursor_col + amount, term->term_width - 1,
|
|
|
|
-amount);
|
2011-08-10 16:31:12 +00:00
|
|
|
|
|
|
|
/* Clear right */
|
2013-04-26 08:53:19 +00:00
|
|
|
guac_terminal_clear_columns(term, term->cursor_row,
|
|
|
|
term->term_width - amount, term->term_width - 1);
|
2011-08-10 16:31:12 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2013-04-08 09:14:58 +00:00
|
|
|
/* X: Erase characters (no scroll) */
|
|
|
|
case 'X':
|
|
|
|
|
|
|
|
amount = argv[0];
|
|
|
|
if (amount == 0) amount = 1;
|
|
|
|
|
|
|
|
/* Clear characters */
|
2013-04-26 08:53:19 +00:00
|
|
|
guac_terminal_clear_columns(term, term->cursor_row,
|
|
|
|
term->cursor_col, term->cursor_col + amount - 1);
|
2013-04-08 09:14:58 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2013-05-22 05:37:53 +00:00
|
|
|
/* c: Identify */
|
|
|
|
case 'c':
|
|
|
|
guac_terminal_write_all(term->stdin_pipe_fd[1], "\x1B[?6c", 5);
|
|
|
|
break;
|
2011-08-10 18:03:38 +00:00
|
|
|
|
2013-05-21 07:35:18 +00:00
|
|
|
/* d: Move cursor, current col */
|
|
|
|
case 'd':
|
|
|
|
row = argv[0]; if (row != 0) row--;
|
|
|
|
term->cursor_row = row;
|
|
|
|
break;
|
2011-08-10 18:03:38 +00:00
|
|
|
|
2013-05-22 18:08:38 +00:00
|
|
|
/* h: Set Mode */
|
|
|
|
case 'h':
|
|
|
|
|
|
|
|
/* DECCKM */
|
2013-05-22 18:38:39 +00:00
|
|
|
if (argv[0] == 1 && private_mode_character == '?')
|
2013-05-22 18:08:38 +00:00
|
|
|
term->application_cursor_keys = true;
|
|
|
|
|
|
|
|
else
|
|
|
|
guac_client_log_info(term->client,
|
2013-05-22 18:38:39 +00:00
|
|
|
"Unhandled mode set: mode=%i, private_mode_character=0x%0x",
|
|
|
|
argv[0], private_mode_character);
|
2013-05-22 18:08:38 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* l: Reset Mode */
|
|
|
|
case 'l':
|
|
|
|
|
|
|
|
/* DECCKM */
|
2013-05-22 18:38:39 +00:00
|
|
|
if (argv[0] == 1 && private_mode_character == '?')
|
2013-05-22 18:08:38 +00:00
|
|
|
term->application_cursor_keys = false;
|
|
|
|
|
|
|
|
else
|
|
|
|
guac_client_log_info(term->client,
|
2013-05-22 18:38:39 +00:00
|
|
|
"Unhandled mode reset: mode=%i, private_mode_character=0x%0x",
|
|
|
|
argv[0], private_mode_character);
|
2013-05-22 18:08:38 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2013-05-21 07:35:18 +00:00
|
|
|
/* m: Set graphics rendition */
|
|
|
|
case 'm':
|
2011-08-10 18:03:38 +00:00
|
|
|
|
2013-05-21 07:35:18 +00:00
|
|
|
for (i=0; i<argc; i++) {
|
|
|
|
|
|
|
|
int value = argv[i];
|
|
|
|
|
|
|
|
/* Reset attributes */
|
|
|
|
if (value == 0)
|
|
|
|
term->current_attributes = term->default_char.attributes;
|
|
|
|
|
|
|
|
/* Bold */
|
|
|
|
else if (value == 1)
|
|
|
|
term->current_attributes.bold = true;
|
|
|
|
|
|
|
|
/* Underscore on */
|
|
|
|
else if (value == 4)
|
|
|
|
term->current_attributes.underscore = true;
|
|
|
|
|
|
|
|
/* Foreground */
|
|
|
|
else if (value >= 30 && value <= 37)
|
|
|
|
term->current_attributes.foreground = value - 30;
|
|
|
|
|
|
|
|
/* Background */
|
|
|
|
else if (value >= 40 && value <= 47)
|
|
|
|
term->current_attributes.background = value - 40;
|
|
|
|
|
|
|
|
/* Underscore on, default foreground */
|
|
|
|
else if (value == 38) {
|
|
|
|
term->current_attributes.underscore = true;
|
|
|
|
term->current_attributes.foreground =
|
|
|
|
term->default_char.attributes.foreground;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Underscore off, default foreground */
|
|
|
|
else if (value == 39) {
|
|
|
|
term->current_attributes.underscore = false;
|
|
|
|
term->current_attributes.foreground =
|
|
|
|
term->default_char.attributes.foreground;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset background */
|
|
|
|
else if (value == 49)
|
|
|
|
term->current_attributes.background =
|
|
|
|
term->default_char.attributes.background;
|
|
|
|
|
|
|
|
/* Reverse video */
|
|
|
|
else if (value == 7)
|
|
|
|
term->current_attributes.reverse = true;
|
|
|
|
|
|
|
|
/* Reset underscore */
|
|
|
|
else if (value == 24)
|
|
|
|
term->current_attributes.underscore = false;
|
|
|
|
|
|
|
|
/* Reset reverse video */
|
|
|
|
else if (value == 27)
|
|
|
|
term->current_attributes.reverse = false;
|
2011-08-10 18:03:38 +00:00
|
|
|
|
2013-05-21 07:35:18 +00:00
|
|
|
else
|
|
|
|
guac_client_log_info(term->client,
|
|
|
|
"Unhandled graphics rendition: %i", value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* r: Set scrolling region */
|
|
|
|
case 'r':
|
2013-05-22 05:37:53 +00:00
|
|
|
|
|
|
|
/* If parameters given, set region */
|
|
|
|
if (argc == 2) {
|
|
|
|
term->scroll_start = argv[0]-1;
|
|
|
|
term->scroll_end = argv[1]-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise, reset scrolling region */
|
|
|
|
else {
|
|
|
|
term->scroll_start = 0;
|
|
|
|
term->scroll_end = term->term_height - 1;
|
|
|
|
}
|
|
|
|
|
2011-08-10 18:03:38 +00:00
|
|
|
break;
|
|
|
|
|
2011-08-05 02:17:44 +00:00
|
|
|
/* Warn of unhandled codes */
|
|
|
|
default:
|
2013-04-08 09:14:58 +00:00
|
|
|
if (c != ';') {
|
|
|
|
|
|
|
|
guac_client_log_info(term->client,
|
|
|
|
"Unhandled CSI sequence: %c", c);
|
|
|
|
|
|
|
|
for (i=0; i<argc; i++)
|
|
|
|
guac_client_log_info(term->client,
|
|
|
|
" -> argv[%i] = %i", i, argv[i]);
|
|
|
|
|
|
|
|
}
|
2011-08-05 02:17:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If not a semicolon, end of CSI sequence */
|
2011-08-05 02:36:04 +00:00
|
|
|
if (c != ';') {
|
2012-12-09 08:35:37 +00:00
|
|
|
term->char_handler = guac_terminal_echo;
|
2011-08-05 02:36:04 +00:00
|
|
|
|
2011-08-05 21:39:11 +00:00
|
|
|
/* Reset parameters */
|
|
|
|
for (i=0; i<argc; i++)
|
|
|
|
argv[i] = 0;
|
|
|
|
|
2013-05-22 18:38:39 +00:00
|
|
|
/* Reset private mode character */
|
|
|
|
private_mode_character = 0;
|
2013-05-22 18:08:38 +00:00
|
|
|
|
2011-08-05 02:36:04 +00:00
|
|
|
/* Reset argument counters */
|
|
|
|
argc = 0;
|
|
|
|
argv_length = 0;
|
|
|
|
}
|
2011-08-05 02:17:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-22 18:38:39 +00:00
|
|
|
/* Set private mode character if given and unset */
|
|
|
|
else if (c >= 0x3A && c <= 0x3F && private_mode_character == 0)
|
|
|
|
private_mode_character = c;
|
|
|
|
|
2011-08-05 02:17:44 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-09 08:35:37 +00:00
|
|
|
int guac_terminal_osc(guac_terminal* term, char c) {
|
2011-08-05 02:17:44 +00:00
|
|
|
/* TODO: Implement OSC */
|
|
|
|
if (c == 0x9C || c == 0x5C || c == 0x07) /* ECMA-48 ST (String Terminator */
|
2012-12-09 08:35:37 +00:00
|
|
|
term->char_handler = guac_terminal_echo;
|
2011-08-05 02:17:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-22 06:38:35 +00:00
|
|
|
int guac_terminal_ctrl_func(guac_terminal* term, char c) {
|
|
|
|
|
|
|
|
int row;
|
|
|
|
|
|
|
|
/* Build character with current attributes */
|
|
|
|
guac_terminal_char guac_char;
|
|
|
|
guac_char.value = 'E';
|
|
|
|
guac_char.attributes = term->current_attributes;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
|
|
|
|
/* Alignment test (fill screen with E's) */
|
|
|
|
case '8':
|
|
|
|
|
|
|
|
for (row=0; row<term->term_height; row++)
|
|
|
|
guac_terminal_set_columns(term, row, 0, term->term_width-1, &guac_char);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
term->char_handler = guac_terminal_echo;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|