Update SDK build tools to 24.0.1
[termux-packages] / packages / mosh / mosh.cc
index 02b475d..8eb1b03 100644 (file)
@@ -95,6 +95,8 @@ static const char *usage_format =
 "                                (example: \"ssh -p 2222\")\n"
 "                                (default: \"ssh\")\n"
 "\n"
+"        --no-init            do not send terminal initialization string\n"
+"\n"
 "        --help               this message\n"
 "        --version            version and copyright information\n"
 "\n"
@@ -162,19 +164,20 @@ int main( int argc, char *argv[] )
   string server = "mosh-server";
   string ssh = "ssh";
   string predict, port_request, ssh_port;
-  int help=0, version=0, fake_proxy=0;
+  int help=0, version=0, fake_proxy=0, term_init=1;
 
   static struct option long_options[] =
   {
     { "client",      required_argument,  0,              'c' },
     { "server",      required_argument,  0,              's' },
+    { "no-init",     no_argument,        &term_init,      0  },
     { "predict",     required_argument,  0,              'r' },
     { "port",        required_argument,  0,              'p' },
     { "ssh-port",    required_argument,  0,              'P' },
     { "ssh",         required_argument,  0,              'S' },
     { "help",        no_argument,        &help,           1  },
     { "version",     no_argument,        &version,        1  },
-    { "fake-proxy!", no_argument,        &fake_proxy,     1  },
+    { "fake-proxy",  no_argument,        &fake_proxy,     1  },
     { 0, 0, 0, 0 }
   };
   while ( 1 ) {
@@ -339,25 +342,9 @@ int main( int argc, char *argv[] )
   char **command = &argv[optind];
   int commands = argc - optind;
 
-  string color_invocation = client + " -c";
-  FILE *color_file = popen( color_invocation.c_str(), "r" );
-  if ( !color_file ) die( "%s: popen: %d", argv[0], errno );
   char *buf = NULL;
   size_t buf_sz = 0;
   ssize_t n;
-  if ( ( n = getline( &buf, &buf_sz, color_file ) ) < 0 ) {
-    die( "%s: Can't count colors: %d", argv[0], errno );
-  }
-  // Chomp the trailing newline:
-  if ( n > 0 && buf[n - 1] == '\n' ) n--;
-  string colors = string( buf, n );
-  pclose( color_file );
-
-  if ( !colors.size() ||
-       colors.find_first_not_of( "0123456789" ) != string::npos ||
-       atoi( colors.c_str() ) < 0 ) {
-    colors = "0";
-  }
 
   int pty, pty_slave;
   struct winsize ws;
@@ -381,9 +368,9 @@ int main( int argc, char *argv[] )
 
     vector<string> server_args;
     server_args.push_back( "new" );
-    server_args.push_back( "-s" );
     server_args.push_back( "-c" );
-    server_args.push_back( colors );
+    server_args.push_back( "256" );
+    server_args.push_back( "-s" );
     if ( port_request.size() ) {
       server_args.push_back( "-p" );
       server_args.push_back( port_request );
@@ -402,8 +389,10 @@ int main( int argc, char *argv[] )
     }
 
     if ( commands ) {
+      server_args.push_back( "--" );
       server_args.insert( server_args.end(), command, command + commands );
     }
+
     string quoted_self = shell_quote_string( string( argv[0] ) );
     string quoted_server_args = shell_quote( server_args );
     fflush( stdout );
@@ -412,11 +401,12 @@ int main( int argc, char *argv[] )
     string ssh_remote_command = server + " " + quoted_server_args;
 
     vector<string> ssh_args;
+    ssh_args.push_back( "-n" );
+    ssh_args.push_back( "-tt" );
     ssh_args.push_back( "-S" );
     ssh_args.push_back( "none" );
     ssh_args.push_back( "-o" );
     ssh_args.push_back( proxy_arg );
-    ssh_args.push_back( "-t" );
     ssh_args.push_back( userhost );
     if ( ssh_port.size() ) {
       ssh_args.push_back( "-p" );
@@ -475,5 +465,6 @@ int main( int argc, char *argv[] )
 
   setenv( "MOSH_KEY", key.c_str(), 1 );
   setenv( "MOSH_PREDICTION_DISPLAY", predict.c_str(), 1 );
+  if (!term_init) setenv( "MOSH_NO_TERM_INIT", "1", 1 );
   execlp( client.c_str(), client.c_str(), ip.c_str(), port.c_str(), (char *)NULL );
 }