mike-jumper commented on code in PR #608:
URL: https://github.com/apache/guacamole-server/pull/608#discussion_r2374976749


##########
src/terminal/terminal/terminal.h:
##########
@@ -139,6 +139,24 @@ typedef enum guac_terminal_cursor_type {
 
 } guac_terminal_cursor_type;
 
+/**
+ * All possible families of codes (e.g. vt100) which can be used when you push
+ * the function and keypad keys.
+ */
+typedef enum guac_terminal_func_keys_and_keypad {
+
+    /**
+     * Not set.
+     */
+    GUAC_TERMINAL_FUNC_KEYS_AND_KEYPAD_DEFAULT,
+
+    /**
+     * VT!00+

Review Comment:
   Accidentally put an "uppercase 1" here. ;)



##########
src/terminal/terminal/terminal.h:
##########
@@ -139,6 +139,24 @@ typedef enum guac_terminal_cursor_type {
 
 } guac_terminal_cursor_type;
 
+/**
+ * All possible families of codes (e.g. vt100) which can be used when you push
+ * the function and keypad keys.
+ */
+typedef enum guac_terminal_func_keys_and_keypad {
+
+    /**
+     * Not set.
+     */
+    GUAC_TERMINAL_FUNC_KEYS_AND_KEYPAD_DEFAULT,

Review Comment:
   Rather than define this as simply the "default" mode, is there an actual 
named family of codes that is that default? Or, put another way: if VT100+ 
_were_ the default, what would this be called?
   
   We should also explicitly define and handle a parameter value for whatever 
this default happens to be called, so that it can be explicitly selected by an 
administrator that doesn't want to rely on the default staying the same.



##########
src/terminal/terminal.c:
##########
@@ -1529,7 +1537,56 @@ static int __guac_terminal_send_key(guac_terminal* term, 
int keysym, int pressed
         /* Typeable keys of number pad */
         else if (keysym >= 0xFFAA && keysym <= 0xFFB9) {
             char value = keysym - 0xFF80;
-            guac_terminal_send_data(term, &value, sizeof(value));
+            if (term->func_keys_and_keypad == 
GUAC_TERMINAL_FUNC_KEYS_AND_KEYPAD_VT100PLUS &&
+                    term->application_keypad_keys) {
+                /* https://vt100.net/docs/vt100-ug/chapter3.html */
+                switch (value) {
+                    case '0':
+                        return guac_terminal_send_string(term, "\x1BOp");
+                    case '1':
+                        return guac_terminal_send_string(term, "\x1BOq");
+                    case '2':
+                        return guac_terminal_send_string(term, "\x1BOr");
+                    case '3':
+                        return guac_terminal_send_string(term, "\x1BOs");
+                    case '4':
+                        return guac_terminal_send_string(term, "\x1BOt");
+                    case '5':
+                        return guac_terminal_send_string(term, "\x1BOu");
+                    case '6':
+                        return guac_terminal_send_string(term, "\x1BOv");
+                    case '7':
+                        return guac_terminal_send_string(term, "\x1BOw");
+                    case '8':
+                        return guac_terminal_send_string(term, "\x1BOx");
+                    case '9':
+                        return guac_terminal_send_string(term, "\x1BOy");

Review Comment:
   Perhaps this could be calculated instead of explicitly listing each mapping 
from 0-9 onto p-y?



##########
src/terminal/terminal.c:
##########
@@ -1529,7 +1537,56 @@ static int __guac_terminal_send_key(guac_terminal* term, 
int keysym, int pressed
         /* Typeable keys of number pad */
         else if (keysym >= 0xFFAA && keysym <= 0xFFB9) {
             char value = keysym - 0xFF80;
-            guac_terminal_send_data(term, &value, sizeof(value));
+            if (term->func_keys_and_keypad == 
GUAC_TERMINAL_FUNC_KEYS_AND_KEYPAD_VT100PLUS &&
+                    term->application_keypad_keys) {
+                /* https://vt100.net/docs/vt100-ug/chapter3.html */
+                switch (value) {
+                    case '0':
+                        return guac_terminal_send_string(term, "\x1BOp");
+                    case '1':
+                        return guac_terminal_send_string(term, "\x1BOq");
+                    case '2':
+                        return guac_terminal_send_string(term, "\x1BOr");
+                    case '3':
+                        return guac_terminal_send_string(term, "\x1BOs");
+                    case '4':
+                        return guac_terminal_send_string(term, "\x1BOt");
+                    case '5':
+                        return guac_terminal_send_string(term, "\x1BOu");
+                    case '6':
+                        return guac_terminal_send_string(term, "\x1BOv");
+                    case '7':
+                        return guac_terminal_send_string(term, "\x1BOw");
+                    case '8':
+                        return guac_terminal_send_string(term, "\x1BOx");
+                    case '9':
+                        return guac_terminal_send_string(term, "\x1BOy");
+                    case '-':
+                        return guac_terminal_send_string(term, "\x1BOm");
+                    case '.':
+                        return guac_terminal_send_string(term, "\x1BOn");
+                    /*
+                     * There is no comma on the regular keypad, so we use '*' 
to send
+                     * the appropriate code.
+                     */
+                    case '*':
+                        return guac_terminal_send_string(term, "\x1BOl");
+                    /*
+                     * At least in some environments JS does not differentiate 
regular
+                     * and keypad ENTER and its location property is always 0. 
So we
+                     * use '+' to send the appropriate ENTER escape code.
+                     */
+                    case '+':
+                        return guac_terminal_send_string(term, "\x1BOM");

Review Comment:
   Does VT100+ lack a `+` on the keypad, so this is safe?



##########
src/terminal/terminal.c:
##########
@@ -504,6 +505,13 @@ guac_terminal* guac_terminal_create(guac_client* client,
     /* Configure backspace */
     term->backspace = options->backspace;
 
+    /* Configure the family of codes for function keys and the keypad */
+    if (options->func_keys_and_keypad == NULL || 
options->func_keys_and_keypad[0] == 0) {
+        term->func_keys_and_keypad = 
GUAC_TERMINAL_FUNC_KEYS_AND_KEYPAD_DEFAULT;
+    } else if (strcmp(options->func_keys_and_keypad, "vt100plus") == 0) {

Review Comment:
   Any particular reason why `vt100plus` instead of `vt100+` or `vt100`? The 
value `vt100` would be in line with the familiar value accepted by `TERM`.



##########
src/terminal/terminal.c:
##########
@@ -1529,7 +1537,56 @@ static int __guac_terminal_send_key(guac_terminal* term, 
int keysym, int pressed
         /* Typeable keys of number pad */
         else if (keysym >= 0xFFAA && keysym <= 0xFFB9) {
             char value = keysym - 0xFF80;
-            guac_terminal_send_data(term, &value, sizeof(value));
+            if (term->func_keys_and_keypad == 
GUAC_TERMINAL_FUNC_KEYS_AND_KEYPAD_VT100PLUS &&
+                    term->application_keypad_keys) {
+                /* https://vt100.net/docs/vt100-ug/chapter3.html */
+                switch (value) {
+                    case '0':
+                        return guac_terminal_send_string(term, "\x1BOp");
+                    case '1':
+                        return guac_terminal_send_string(term, "\x1BOq");
+                    case '2':
+                        return guac_terminal_send_string(term, "\x1BOr");
+                    case '3':
+                        return guac_terminal_send_string(term, "\x1BOs");
+                    case '4':
+                        return guac_terminal_send_string(term, "\x1BOt");
+                    case '5':
+                        return guac_terminal_send_string(term, "\x1BOu");
+                    case '6':
+                        return guac_terminal_send_string(term, "\x1BOv");
+                    case '7':
+                        return guac_terminal_send_string(term, "\x1BOw");
+                    case '8':
+                        return guac_terminal_send_string(term, "\x1BOx");
+                    case '9':
+                        return guac_terminal_send_string(term, "\x1BOy");
+                    case '-':
+                        return guac_terminal_send_string(term, "\x1BOm");
+                    case '.':
+                        return guac_terminal_send_string(term, "\x1BOn");
+                    /*
+                     * There is no comma on the regular keypad, so we use '*' 
to send
+                     * the appropriate code.
+                     */
+                    case '*':
+                        return guac_terminal_send_string(term, "\x1BOl");

Review Comment:
   Does VT100+ lack a `*` on the keypad, so this is safe?



##########
src/terminal/terminal.c:
##########
@@ -504,6 +505,13 @@ guac_terminal* guac_terminal_create(guac_client* client,
     /* Configure backspace */
     term->backspace = options->backspace;
 
+    /* Configure the family of codes for function keys and the keypad */
+    if (options->func_keys_and_keypad == NULL || 
options->func_keys_and_keypad[0] == 0) {
+        term->func_keys_and_keypad = 
GUAC_TERMINAL_FUNC_KEYS_AND_KEYPAD_DEFAULT;
+    } else if (strcmp(options->func_keys_and_keypad, "vt100plus") == 0) {

Review Comment:
   Please don't cuddle the `else if`. See: 
https://cwiki.apache.org/confluence/display/GUAC/Contribution+and+Style+Guidelines#ContributionandStyleGuidelines-Braces



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to