Permalink
Browse files

Use OpenSSH escape sequences, suggested by @pimlott in #215.

  • Loading branch information...
1 parent 54f57ff commit f8208e406ffe79243885a61167e9acb05eef8a3b @saurik committed Apr 18, 2012
Showing with 34 additions and 20 deletions.
  1. +24 −14 src/frontend/stmclient.cc
  2. +7 −3 src/frontend/stmclient.h
  3. +3 −3 src/frontend/terminaloverlay.cc
View
@@ -228,31 +228,41 @@ bool STMClient::process_user_input( int fd )
overlays.get_prediction_engine().new_user_byte( the_byte, *local_framebuffer );
- if ( quit_sequence_started ) {
- if ( the_byte == '.' ) { /* Quit sequence is Ctrl-^ . */
+ if ( quit_sequence_state == 2 ) {
+ quit_sequence_state = 0;
+
+ switch ( the_byte ) {
+ case '.':
if ( network->has_remote_addr() && (!network->shutdown_in_progress()) ) {
overlays.get_notification_engine().set_notification_string( wstring( L"Exiting on user request..." ), true );
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 ) );
+ break;
+
+ default:
+ if ( the_byte != quit_sequence_char ) {
+ network->get_current_state().push_back( Parser::UserByte( '~' ) );
+ }
+ break;
}
+ }
- quit_sequence_started = false;
- continue;
+ if ( quit_sequence_state == 1 ) {
+ if ( the_byte == quit_sequence_char ) {
+ quit_sequence_state = 2;
+ continue;
+ } else {
+ quit_sequence_state = 0;
+ }
}
- quit_sequence_started = (the_byte == 0x1E);
- if ( quit_sequence_started ) {
- continue;
+ if ( quit_sequence_state == 0 ) {
+ if ( the_byte == '\n' || the_byte == '\r' ) {
+ quit_sequence_state = 1;
+ }
}
if ( the_byte == 0x0C ) { /* Ctrl-L */
View
@@ -45,9 +45,12 @@ class STMClient {
Terminal::Display display;
std::wstring connecting_notification;
- bool repaint_requested, quit_sequence_started;
+ bool repaint_requested;
bool clean_shutdown;
+ int quit_sequence_state;
+ char quit_sequence_char;
+
void main_init( void );
bool process_network_input( void );
bool process_user_input( int fd );
@@ -74,8 +77,9 @@ class STMClient {
display( true ), /* use TERM environment var to initialize display */
connecting_notification(),
repaint_requested( false ),
- quit_sequence_started( false ),
- clean_shutdown( false )
+ clean_shutdown( false ),
+ quit_sequence_state( 0 ),
+ quit_sequence_char( '~' )
{
if ( predict_mode ) {
if ( !strcmp( predict_mode, "always" ) ) {
@@ -191,11 +191,11 @@ void NotificationEngine::apply( Framebuffer &fb ) const
if ( message.empty() && (!time_expired) ) {
return;
} else if ( message.empty() && time_expired ) {
- swprintf( tmp, 128, L"mosh: Last contact %.0f seconds ago. [To quit: Ctrl-^ .]", (double)(now - last_word_from_server) / 1000.0 );
+ swprintf( tmp, 128, L"mosh: Last contact %.0f seconds ago. [To quit: <enter> ~ .]", (double)(now - last_word_from_server) / 1000.0 );
} else if ( (!message.empty()) && (!time_expired) ) {
- swprintf( tmp, 128, L"mosh: %ls [To quit: Ctrl-^ .]", message.c_str() );
+ swprintf( tmp, 128, L"mosh: %ls [To quit: <enter> ~ .]", message.c_str() );
} else {
- swprintf( tmp, 128, L"mosh: %ls (%.0f s without contact.) [To quit: Ctrl-^ .]", message.c_str(),
+ swprintf( tmp, 128, L"mosh: %ls (%.0f s without contact.) [To quit: <enter> ~ .]", message.c_str(),
(double)(now - last_word_from_server) / 1000.0 );
}

0 comments on commit f8208e4

Please sign in to comment.