GUACAMOLE-148: Scroll automatically only when cursor is within scrolling region.
This commit is contained in:
parent
ea6b094e24
commit
073fbe684d
@ -47,6 +47,48 @@
|
|||||||
*/
|
*/
|
||||||
#define GUAC_TERMINAL_OK "\x1B[0n"
|
#define GUAC_TERMINAL_OK "\x1B[0n"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Advances the cursor to the next row, scrolling if the cursor would otherwise
|
||||||
|
* leave the scrolling region. If the cursor is already outside the scrolling
|
||||||
|
* region, the cursor is prevented from leaving the terminal bounds.
|
||||||
|
*
|
||||||
|
* @param term
|
||||||
|
* The guac_terminal whose cursor should be advanced to the next row.
|
||||||
|
*/
|
||||||
|
static void guac_terminal_linefeed(guac_terminal* term) {
|
||||||
|
|
||||||
|
/* Scroll up if necessary */
|
||||||
|
if (term->cursor_row == term->scroll_end)
|
||||||
|
guac_terminal_scroll_up(term, term->scroll_start,
|
||||||
|
term->scroll_end, 1);
|
||||||
|
|
||||||
|
/* Otherwise, just advance to next row if space remains */
|
||||||
|
else if (term->cursor_row < term->term_height - 1)
|
||||||
|
term->cursor_row++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves the cursor backward to the previous row, scrolling if the cursor would
|
||||||
|
* otherwise leave the scrolling region. If the cursor is already outside the
|
||||||
|
* scrolling region, the cursor is prevented from leaving the terminal bounds.
|
||||||
|
*
|
||||||
|
* @param term
|
||||||
|
* The guac_terminal whose cursor should be moved backward by one row.
|
||||||
|
*/
|
||||||
|
static void guac_terminal_reverse_linefeed(guac_terminal* term) {
|
||||||
|
|
||||||
|
/* Scroll down if necessary */
|
||||||
|
if (term->cursor_row == term->scroll_start)
|
||||||
|
guac_terminal_scroll_down(term, term->scroll_start,
|
||||||
|
term->scroll_end, 1);
|
||||||
|
|
||||||
|
/* Otherwise, move back one row if space remains */
|
||||||
|
else if (term->cursor_row > 0)
|
||||||
|
term->cursor_row--;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int guac_terminal_echo(guac_terminal* term, unsigned char c) {
|
int guac_terminal_echo(guac_terminal* term, unsigned char c) {
|
||||||
|
|
||||||
int width;
|
int width;
|
||||||
@ -134,17 +176,9 @@ int guac_terminal_echo(guac_terminal* term, unsigned char c) {
|
|||||||
case '\n':
|
case '\n':
|
||||||
case 0x0B: /* VT */
|
case 0x0B: /* VT */
|
||||||
case 0x0C: /* FF */
|
case 0x0C: /* FF */
|
||||||
term->cursor_row++;
|
|
||||||
|
|
||||||
/* Scroll up if necessary */
|
/* Advance to next row */
|
||||||
if (term->cursor_row > term->scroll_end) {
|
guac_terminal_linefeed(term);
|
||||||
term->cursor_row = term->scroll_end;
|
|
||||||
|
|
||||||
/* Scroll up by one row */
|
|
||||||
guac_terminal_scroll_up(term, term->scroll_start,
|
|
||||||
term->scroll_end, 1);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If automatic carriage return, fall through to CR handler */
|
/* If automatic carriage return, fall through to CR handler */
|
||||||
if (!term->automatic_carriage_return)
|
if (!term->automatic_carriage_return)
|
||||||
@ -193,17 +227,7 @@ int guac_terminal_echo(guac_terminal* term, unsigned char c) {
|
|||||||
/* Wrap if necessary */
|
/* Wrap if necessary */
|
||||||
if (term->cursor_col >= term->term_width) {
|
if (term->cursor_col >= term->term_width) {
|
||||||
term->cursor_col = 0;
|
term->cursor_col = 0;
|
||||||
term->cursor_row++;
|
guac_terminal_linefeed(term);
|
||||||
}
|
|
||||||
|
|
||||||
/* 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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If insert mode, shift other characters right by 1 */
|
/* If insert mode, shift other characters right by 1 */
|
||||||
@ -278,36 +302,14 @@ int guac_terminal_escape(guac_terminal* term, unsigned char c) {
|
|||||||
|
|
||||||
/* Index (IND) */
|
/* Index (IND) */
|
||||||
case 'D':
|
case 'D':
|
||||||
term->cursor_row++;
|
guac_terminal_linefeed(term);
|
||||||
|
|
||||||
/* 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;
|
term->char_handler = guac_terminal_echo;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Next Line (NEL) */
|
/* Next Line (NEL) */
|
||||||
case 'E':
|
case 'E':
|
||||||
term->cursor_col = 0;
|
term->cursor_col = 0;
|
||||||
term->cursor_row++;
|
guac_terminal_linefeed(term);
|
||||||
|
|
||||||
/* 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;
|
term->char_handler = guac_terminal_echo;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -319,19 +321,7 @@ int guac_terminal_escape(guac_terminal* term, unsigned char c) {
|
|||||||
|
|
||||||
/* Reverse Linefeed */
|
/* Reverse Linefeed */
|
||||||
case 'M':
|
case 'M':
|
||||||
|
guac_terminal_reverse_linefeed(term);
|
||||||
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;
|
term->char_handler = guac_terminal_echo;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user