corentin-soriano commented on code in PR #525: URL: https://github.com/apache/guacamole-server/pull/525#discussion_r1778574792
########## src/terminal/terminal-handlers.c: ########## @@ -918,31 +1012,87 @@ int guac_terminal_csi(guac_terminal* term, unsigned char c) { break; - /* h: Set Mode */ + /* h: Set Mode (DECSET) */ case 'h': - - /* Look up flag and set */ + + /* Save cursor for later restoration */ + if (argv[0] == GUAC_TERMINAL_DECSET_SAVE_CURSOR + || argv[0] == GUAC_TERMINAL_DECSET_USE_ALT_BUFFER_AND_SAVE_CURSOR_AND_CLEAR) { + term->saved_cursor_row = term->cursor_row; + term->saved_cursor_col = term->cursor_col; + } + + if (term->current_buffer != term->alternate_buffer) { + + /* Switch to alternate buffer */ + if (argv[0] == GUAC_TERMINAL_DECSET_USE_ALT_BUFFER + || argv[0] == GUAC_TERMINAL_DECSET_USE_ALT_BUFFER_AND_CLEAR + || argv[0] == GUAC_TERMINAL_DECSET_USE_ALT_BUFFER_AND_SAVE_CURSOR_AND_CLEAR) { + + term->current_buffer = term->alternate_buffer; + + /* Update scrollbar bounds (the different buffers have differing levels of scrollback) */ + guac_terminal_scrollbar_set_bounds(term->scrollbar, + -guac_terminal_get_available_scroll(term), 0); + + } + + /* Clear alternate buffer only if we were previously using + * the normal buffer */ + if (argv[0] == GUAC_TERMINAL_DECSET_USE_ALT_BUFFER_AND_CLEAR + || argv[0] == GUAC_TERMINAL_DECSET_USE_ALT_BUFFER_AND_SAVE_CURSOR_AND_CLEAR) { + guac_terminal_clear_range(term, + 0, 0, term->term_height - 1, term->term_width - 1); + } + + } + + /* Look up flag and set */ flag = __guac_terminal_get_flag(term, argv[0], private_mode_character); if (flag != NULL) *flag = true; - /* Open alternate screen buffer */ - if (argv[0] == GUAC_TERMINAL_ALT_BUFFER) - guac_terminal_switch_buffers(term, true); - break; - /* l: Reset Mode */ + /* l: Reset Mode (DECRST) */ case 'l': - - /* Look up flag and clear */ + + if (term->current_buffer != term->normal_buffer) { + + /* Switch back to normal buffer */ + if (argv[0] == GUAC_TERMINAL_DECRST_USE_NORMAL_BUFFER + || argv[0] == GUAC_TERMINAL_DECRST_USE_NORMAL_BUFFER_AND_CLEAR + || argv[0] == GUAC_TERMINAL_DECRST_USE_NORMAL_BUFFER_AND_RESTORE_CURSOR) { + + term->current_buffer = term->normal_buffer; + + /* Update scrollbar bounds (the different buffers have differing levels of scrollback) */ + guac_terminal_scrollbar_set_bounds(term->scrollbar, + -guac_terminal_get_available_scroll(term), 0); + + } + + /* Clear normal buffer only if we were previously using + * the alternate buffer */ + if (argv[0] == GUAC_TERMINAL_DECRST_USE_NORMAL_BUFFER_AND_CLEAR) { + guac_terminal_clear_range(term, + 0, 0, term->term_height - 1, term->term_width - 1); + } Review Comment: Actually, when closing vi (or other), only the line with the cursor is updated and the text file content stay on screen. I think we should check if we receive the code `GUAC_TERMINAL_DECRST_USE_NORMAL_BUFFER_AND_RESTORE_CURSOR`. However `guac_terminal_clear_range` completely clears the screen instead of restoring the contents of the normal buffer so we have a black screen with only the cursor row shown. -- 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: dev-unsubscr...@guacamole.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org