Give mosh-client option to print number of colors
This commit is contained in:
@@ -21,6 +21,8 @@ mosh-client \- client-side helper for mosh
|
|||||||
MOSH_KEY=KEY
|
MOSH_KEY=KEY
|
||||||
.B mosh-client
|
.B mosh-client
|
||||||
IP PORT
|
IP PORT
|
||||||
|
.B mosh-client
|
||||||
|
-c
|
||||||
.br
|
.br
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
\fBmosh-client\fP is a helper program for the
|
\fBmosh-client\fP is a helper program for the
|
||||||
@@ -43,6 +45,9 @@ For constructing new setup wrappers for remote execution facilities
|
|||||||
other than SSH, it may be necessary to invoke \fBmosh-client\fP
|
other than SSH, it may be necessary to invoke \fBmosh-client\fP
|
||||||
directly.
|
directly.
|
||||||
|
|
||||||
|
With the -c option, \fBmosh-client\fP instead prints the number of colors
|
||||||
|
of the terminal given by the TERM environment variable.
|
||||||
|
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
.BR mosh (1),
|
.BR mosh (1),
|
||||||
.BR mosh-server (1).
|
.BR mosh-server (1).
|
||||||
|
|||||||
@@ -20,31 +20,65 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
|
||||||
#include "stmclient.h"
|
#include "stmclient.h"
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
|
||||||
|
/* these need to be included last because of conflicting defines */
|
||||||
|
#include <curses.h>
|
||||||
|
#include <term.h>
|
||||||
|
|
||||||
void usage( const char *argv0 ) {
|
void usage( const char *argv0 ) {
|
||||||
fprintf( stderr, "mosh-client (%s)\n", PACKAGE_STRING );
|
fprintf( stderr, "mosh-client (%s)\n", PACKAGE_STRING );
|
||||||
fprintf( stderr, "Copyright 2012 Keith Winstein <mosh-devel@mit.edu>\n" );
|
fprintf( stderr, "Copyright 2012 Keith Winstein <mosh-devel@mit.edu>\n" );
|
||||||
fprintf( stderr, "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.\n\n" );
|
fprintf( stderr, "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.\n\n" );
|
||||||
|
|
||||||
fprintf( stderr, "Usage: %s IP PORT\n", argv0 );
|
fprintf( stderr, "Usage: %s IP PORT\n %s -c\n", argv0, argv0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_colorcount( void )
|
||||||
|
{
|
||||||
|
/* check colors */
|
||||||
|
setupterm((char *)0, 1, (int *)0);
|
||||||
|
|
||||||
|
char colors_name[] = "colors";
|
||||||
|
int color_val = tigetnum( colors_name );
|
||||||
|
if ( color_val == -2 ) {
|
||||||
|
fprintf( stderr, "Invalid terminfo numeric capability: %s\n",
|
||||||
|
colors_name );
|
||||||
|
}
|
||||||
|
|
||||||
|
printf( "%d\n", color_val );
|
||||||
}
|
}
|
||||||
|
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
/* Get arguments */
|
/* Get arguments */
|
||||||
|
int opt;
|
||||||
|
while ( (opt = getopt( argc, argv, "c" )) != -1 ) {
|
||||||
|
switch ( opt ) {
|
||||||
|
case 'c':
|
||||||
|
print_colorcount();
|
||||||
|
exit( 0 );
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage( argv[ 0 ] );
|
||||||
|
exit( 1 );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
char *ip;
|
char *ip;
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
if ( argc != 3 ) {
|
if ( argc - optind != 2 ) {
|
||||||
usage( argv[ 0 ] );
|
usage( argv[ 0 ] );
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
ip = argv[ 1 ];
|
ip = argv[ optind ];
|
||||||
port = myatoi( argv[ 2 ] );
|
port = myatoi( argv[ optind + 1 ] );
|
||||||
|
|
||||||
/* Read key from environment */
|
/* Read key from environment */
|
||||||
char *env_key = getenv( "MOSH_KEY" );
|
char *env_key = getenv( "MOSH_KEY" );
|
||||||
|
|||||||
Reference in New Issue
Block a user