From 80f34faadd29ad84a52312c761537256e2cea677 Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Thu, 13 Oct 2011 01:16:55 -0400 Subject: [PATCH] User sequences to repaint and quit --- parseraction.cpp | 5 ----- stmclient.cpp | 38 ++++++++++++++++++++++++++++++++++++-- stmclient.hpp | 6 +++++- terminaloverlay.cpp | 4 ++-- terminaluserinput.hpp | 2 +- 5 files changed, 44 insertions(+), 11 deletions(-) diff --git a/parseraction.cpp b/parseraction.cpp index b5425df..ccf128b 100644 --- a/parseraction.cpp +++ b/parseraction.cpp @@ -70,11 +70,6 @@ void UserByte::act_on_terminal( Terminal::Emulator *emu ) const { emu->dispatch.terminal_to_host.append( emu->user.input( this, emu->fb.ds.application_mode_cursor_keys ) ); - /* - if ( c == 0x0c ) { // Ctrl-L - emu->display.invalidate(); - } - */ } void Resize::act_on_terminal( Terminal::Emulator *emu ) const diff --git a/stmclient.cpp b/stmclient.cpp index afd2a4f..0afd735 100644 --- a/stmclient.cpp +++ b/stmclient.cpp @@ -128,11 +128,13 @@ void STMClient::output_new_frame( void ) overlays.apply( new_state ); /* calculate minimal difference from where we are */ - string diff = Terminal::Display::new_frame( true, + string diff = Terminal::Display::new_frame( !repaint_requested, *local_framebuffer, new_state ); swrite( STDOUT_FILENO, diff.data(), diff.size() ); *local_framebuffer = new_state; + + repaint_requested = false; } bool STMClient::process_network_input( void ) @@ -161,7 +163,39 @@ bool STMClient::process_user_input( int fd ) if ( !network->shutdown_in_progress() ) { for ( int i = 0; i < bytes_read; i++ ) { char the_byte = buf[ i ]; - network->get_current_state().push_back( Parser::UserByte( the_byte ) ); + + if ( quit_sequence_started ) { + if ( the_byte == '.' ) { /* Quit sequence is Ctrl-^ . */ + if ( network->attached() && (!network->shutdown_in_progress()) ) { + overlays.get_notification_engine().set_notification_string( wstring( L"Exiting on user request..." ) ); + network->start_shutdown(); + return true; + } else { + return false; + } + } else if ( the_byte == '^' ) { + /* Emulation sequence to type Ctrl-^ is Ctrl-^ ^ */ + network->get_current_state().push_back( Parser::UserByte( 0x1E ) ); + } else { + /* Ctrl-^ followed by anything other than . and ^ gets sent literally */ + network->get_current_state().push_back( Parser::UserByte( 0x1E ) ); + network->get_current_state().push_back( Parser::UserByte( the_byte ) ); + } + + quit_sequence_started = false; + continue; + } + + quit_sequence_started = (the_byte == 0x1E); + if ( quit_sequence_started ) { + continue; + } + + if ( the_byte == 0x0C ) { /* Ctrl-L */ + repaint_requested = true; + } + + network->get_current_state().push_back( Parser::UserByte( the_byte ) ); } } diff --git a/stmclient.hpp b/stmclient.hpp index 741f183..5d85f1c 100644 --- a/stmclient.hpp +++ b/stmclient.hpp @@ -26,6 +26,8 @@ private: Network::Transport< Network::UserStream, Terminal::Complete > *network; uint64_t last_remote_num; + bool repaint_requested, quit_sequence_started; + void main_init( void ); bool process_network_input( void ); bool process_user_input( int fd ); @@ -42,7 +44,9 @@ public: local_framebuffer( NULL ), overlays(), network( NULL ), - last_remote_num( -1 ) + last_remote_num( -1 ), + repaint_requested( false ), + quit_sequence_started( false ) {} void init( void ); diff --git a/terminaloverlay.cpp b/terminaloverlay.cpp index f1a3483..2e912c1 100644 --- a/terminaloverlay.cpp +++ b/terminaloverlay.cpp @@ -140,11 +140,11 @@ void NotificationEngine::render_notification( void ) if ( message.empty() && (!time_expired) ) { return; } else if ( message.empty() && time_expired ) { - swprintf( tmp, 128, L"[stm] No contact for %.0f seconds.", (double)(now - last_word) / 1000.0 ); + swprintf( tmp, 128, L"[stm] No contact for %.0f seconds. [To quit: Ctrl-^ .]", (double)(now - last_word) / 1000.0 ); } else if ( (!message.empty()) && (!time_expired) ) { swprintf( tmp, 128, L"[stm] %ls", message.c_str() ); } else { - swprintf( tmp, 128, L"[stm] %ls (No contact for %.0f seconds.)", message.c_str(), + swprintf( tmp, 128, L"[stm] %ls [To quit: Ctrl-^ .] (No contact for %.0f seconds.)", message.c_str(), (double)(now - last_word) / 1000.0 ); } diff --git a/terminaluserinput.hpp b/terminaluserinput.hpp index 7ad8702..1052a87 100644 --- a/terminaluserinput.hpp +++ b/terminaluserinput.hpp @@ -7,7 +7,7 @@ namespace Terminal { class UserInput { private: - short last_byte; + wchar_t last_byte; public: UserInput()