summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2014-12-04 20:33:36 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2014-12-04 20:33:36 +0100
commit9d44c565a7e9ded7eea2a8df7665518c622d02d0 (patch)
tree0a9a1c8fddc1b8ad918488f46da86e43dcf32cfc
parent5666e2ed46bc50d4176b24b1e0a77cd4b478bfc2 (diff)
downloadbiruda-9d44c565a7e9ded7eea2a8df7665518c622d02d0.tar.gz
biruda-9d44c565a7e9ded7eea2a8df7665518c622d02d0.tar.bz2
added an autodisp for status for now
-rw-r--r--src/cli.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/src/cli.c b/src/cli.c
index e21fcbd..406649d 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -30,7 +30,8 @@ typedef enum {
} command_state_t;
static char *commands[] = {
- "help", "quit", "status", "start", "stop", NULL
+ "help", "quit", "status", "start", "stop",
+ "autodisp", NULL
};
static bool print_colors = false;
@@ -43,6 +44,8 @@ static char *worker_names[MAX_WORKERS];
static int nof_worker_names = 0;
+static bool autodisp_toggle = false;
+
static void cleanup_worker_names( )
{
for( int i = 0; i < nof_worker_names; i++ ) {
@@ -124,11 +127,12 @@ static void completion_func( const char *buf, linenoiseCompletions *lc )
static void print_help( )
{
puts( "\n"
- " help - show this help page\n"
- " quit - quit the client\n"
- " status - status of the biruda network\n"
- " start - start a worker manually\n"
- " stop - stop a worker manually\n"
+ " help - show this help page\n"
+ " quit - quit the client\n"
+ " status - status of the biruda network\n"
+ " start - start a worker manually\n"
+ " stop - stop a worker manually\n"
+ " autodisp - automatically show messages (toggle)\n"
);
}
@@ -161,6 +165,14 @@ static void print_answer( const char *fmt, ... )
va_end( ap );
}
+static void print_message( const char *fmt, ... )
+{
+ va_list ap;
+ va_start( ap, fmt );
+ print_colored( fmt, 4, ap );
+ va_end( ap );
+}
+
static void print_status( )
{
char *url = "status";
@@ -216,6 +228,7 @@ int start_interactive( bool colors, FILE *in )
is_interactive = isatty( fileno( in ) );
print_colors = is_interactive ? colors : false;
+ autodisp_toggle = false;
if( is_interactive ) {
char *home = getenv( "HOME" );
@@ -243,6 +256,10 @@ int start_interactive( bool colors, FILE *in )
break;
}
+ if( autodisp_toggle ) {
+ print_status( );
+ }
+
if( is_interactive ) {
snprintf( prompt, sizeof( prompt ), "%s> ", context );
if( ( line = linenoise( prompt ) ) == NULL ) {
@@ -296,6 +313,15 @@ int start_interactive( bool colors, FILE *in )
command_state = START_WORKER;
} else if( strncasecmp( line, "stop", 5 ) == 0 ) {
command_state = STOP_WORKER;
+ } else if( strncasecmp( line, "autodisp", 8 ) == 0 ) {
+ if( is_interactive ) {
+ autodisp_toggle = !autodisp_toggle;
+ print_message( "Autodisplay toggle is %s.", autodisp_toggle ? "on" : "off" );
+ } else {
+ print_error( "'autodisp' makes sense only in interactive mode." );
+ }
+ } else if( strcmp( line, "" ) == 0 ) {
+ // skip, handy if autodisp is on to show more messages
} else {
print_error( "Bad command '%s'.", line );
}