GUACAMOLE-610: Add console code for altering scrollback size on the fly.

Project: http://git-wip-us.apache.org/repos/asf/guacamole-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-server/commit/994cb958
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-server/tree/994cb958
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-server/diff/994cb958

Branch: refs/heads/master
Commit: 994cb95893aa1e136626b5ec4bdd4c4d22d044f5
Parents: 0e6d549
Author: Michael Jumper <mjum...@apache.org>
Authored: Mon Aug 13 00:50:05 2018 -0700
Committer: Michael Jumper <mjum...@apache.org>
Committed: Sat Aug 18 11:26:12 2018 -0700

----------------------------------------------------------------------
 bin/guacctl                               | 56 ++++++++++++++++++++++++++
 src/terminal/terminal.c                   | 15 +------
 src/terminal/terminal/terminal.h          | 15 +++++++
 src/terminal/terminal/terminal_handlers.h | 18 +++++++++
 src/terminal/terminal_handlers.c          | 37 +++++++++++++++++
 5 files changed, 127 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/994cb958/bin/guacctl
----------------------------------------------------------------------
diff --git a/bin/guacctl b/bin/guacctl
index a489830..2d6d263 100755
--- a/bin/guacctl
+++ b/bin/guacctl
@@ -91,6 +91,18 @@ send_close_pipe_stream() {
 }
 
 ##
+## Sends the Guacamole-specific console code for resizing the scrollback
+## buffer.
+##
+## @param ROWS
+##     The number of rows that the scrollback buffer should contain.
+##
+send_resize_scrollback() {
+    ROWS="$1"
+    printf "\033]482204;%s\007" "$ROWS"
+}
+
+##
 ## Prints the given error text to STDERR.
 ##
 ## @param ...
@@ -115,6 +127,8 @@ Usage: guacctl [OPTION] [FILE or NAME]...
                            name.
     -c, --close-pipe       close any existing pipe stream and redirect output
                            back to the terminal emulator.
+    -S, --scrollback       request that the scrollback buffer be limited to the
+                           given number of rows.
 END
 }
 
@@ -243,6 +257,39 @@ close_pipe_stream() {
 
 }
 
+##
+## Resizes the scrollback buffer to the given number of rows.
+##
+## @param ...
+##     The number of rows that should be contained within the scrollback
+##     buffer, as provided to guacctl.
+##
+resize_scrollback() {
+
+    #
+    # Validate arguments
+    #
+
+    if [ $# -lt 1 ]; then
+        error "No row count specified."
+        return;
+    fi
+
+    if [ $# -gt 1 ]; then
+        error "Only one row count may be given."
+        return;
+    fi
+
+    #
+    # Send code for resizing scrollback
+    #
+
+    ROWS="$1"
+    send_resize_scrollback "$ROWS"
+
+}
+
+
 #
 # Get script name
 #
@@ -301,6 +348,15 @@ case "$1" in
         ;;
 
     #
+    # Resize scrollback
+    #
+
+    "--scrollback"|"-S")
+        shift
+        resize_scrollback "$@"
+        ;;
+
+    #
     # Show usage info if options are invalid
     #
 

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/994cb958/src/terminal/terminal.c
----------------------------------------------------------------------
diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c
index 1c105dc..760e128 100644
--- a/src/terminal/terminal.c
+++ b/src/terminal/terminal.c
@@ -185,20 +185,7 @@ static int 
guac_terminal_effective_buffer_length(guac_terminal* term) {
 
 }
 
-/**
- * Returns the number of rows within the buffer of the given terminal which are
- * not currently displayed on screen. Adjustments to the desired scrollback
- * size are taken into account, and rows which are within the buffer but
- * unavailable due to being outside the desired scrollback range are ignored.
- *
- * @param term
- *     The terminal whose off-screen row count should be determined.
- *
- * @return
- *     The number of rows within the buffer which are not currently displayed
- *     on screen.
- */
-static int guac_terminal_available_scroll(guac_terminal* term) {
+int guac_terminal_available_scroll(guac_terminal* term) {
     return guac_terminal_effective_buffer_length(term) - term->term_height;
 }
 

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/994cb958/src/terminal/terminal/terminal.h
----------------------------------------------------------------------
diff --git a/src/terminal/terminal/terminal.h b/src/terminal/terminal/terminal.h
index d68405b..bddf8e5 100644
--- a/src/terminal/terminal/terminal.h
+++ b/src/terminal/terminal/terminal.h
@@ -1063,5 +1063,20 @@ void guac_terminal_pipe_stream_close(guac_terminal* 
term);
 int guac_terminal_create_typescript(guac_terminal* term, const char* path,
         const char* name, int create_path);
 
+/**
+ * Returns the number of rows within the buffer of the given terminal which are
+ * not currently displayed on screen. Adjustments to the desired scrollback
+ * size are taken into account, and rows which are within the buffer but
+ * unavailable due to being outside the desired scrollback range are ignored.
+ *
+ * @param term
+ *     The terminal whose off-screen row count should be determined.
+ *
+ * @return
+ *     The number of rows within the buffer which are not currently displayed
+ *     on screen.
+ */
+int guac_terminal_available_scroll(guac_terminal* term);
+
 #endif
 

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/994cb958/src/terminal/terminal/terminal_handlers.h
----------------------------------------------------------------------
diff --git a/src/terminal/terminal/terminal_handlers.h 
b/src/terminal/terminal/terminal_handlers.h
index 6130d2c..0869b19 100644
--- a/src/terminal/terminal/terminal_handlers.h
+++ b/src/terminal/terminal/terminal_handlers.h
@@ -139,6 +139,24 @@ int guac_terminal_open_pipe_stream(guac_terminal* term, 
unsigned char c);
 int guac_terminal_close_pipe_stream(guac_terminal* term, unsigned char c);
 
 /**
+ * Parses the remainder of the OSC sequence specific to the Guacamole terminal
+ * emulator which requests that the scrollback buffer size be set to the given
+ * number of rows. The desired scrollback buffer size will immediately be set,
+ * however the manner in which that size is applied (or whether the size is
+ * applied at all) depends on (1) whether the requested size exceeds the
+ * maximum size set when the terminal emulator was created and (2) whether the
+ * size does not reduce the scrollback below the number of rows required for
+ * the current display.
+ *
+ * @param term
+ *     The terminal that received the given character of data.
+ *
+ * @param c
+ *     The character that was received by the given terminal.
+ */
+int guac_terminal_set_scrollback(guac_terminal* term, unsigned char c);
+
+/**
  * Parses the remainder of an OSC sequence setting the window title. The
  * window title is everything after the window title sequence begins, up to
  * the end of the OSC sequence itself.

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/994cb958/src/terminal/terminal_handlers.c
----------------------------------------------------------------------
diff --git a/src/terminal/terminal_handlers.c b/src/terminal/terminal_handlers.c
index a6469ac..ec258ff 100644
--- a/src/terminal/terminal_handlers.c
+++ b/src/terminal/terminal_handlers.c
@@ -1208,6 +1208,39 @@ int guac_terminal_close_pipe_stream(guac_terminal* term, 
unsigned char c) {
 
 }
 
+int guac_terminal_set_scrollback(guac_terminal* term, unsigned char c) {
+
+    static char param[16];
+    static int length = 0;
+
+    /* Open pipe on ECMA-48 ST (String Terminator) */
+    if (c == 0x9C || c == 0x5C || c == 0x07) {
+
+        /* End parameter string */
+        param[length++] = '\0';
+        length = 0;
+
+        /* Assign scrollback size */
+        term->requested_scrollback = atoi(param);
+
+        /* Update scrollbar bounds */
+        guac_terminal_scrollbar_set_bounds(term->scrollbar,
+                -guac_terminal_available_scroll(term), 0);
+
+        /* Return to echo mode */
+        term->char_handler = guac_terminal_echo;
+
+    }
+
+    /* Otherwise, store character within parameter */
+    else if (length < sizeof(param) - 1)
+        param[length++] = c;
+
+    return 0;
+
+}
+
+
 int guac_terminal_window_title(guac_terminal* term, unsigned char c) {
 
     static int position = 0;
@@ -1346,6 +1379,10 @@ int guac_terminal_osc(guac_terminal* term, unsigned char 
c) {
         else if (operation == 482203)
             term->char_handler = guac_terminal_close_pipe_stream;
 
+        /* Set scrollback size OSC */
+        else if (operation == 482204)
+            term->char_handler = guac_terminal_set_scrollback;
+
         /* Set window title OSC */
         else if (operation == 0 || operation == 2)
             term->char_handler = guac_terminal_window_title;

Reply via email to