summaryrefslogtreecommitdiff
path: root/src/biruda.c
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2014-11-15 09:42:53 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2014-11-15 09:42:53 +0100
commit75df5abae42888bd5bf01fc4a8bd1215413cab67 (patch)
tree0784bd39b43b301632751d2f68f093240f437990 /src/biruda.c
parent8f772dc3aa8df1ed52aeb83757136b508084e32d (diff)
downloadbiruda-75df5abae42888bd5bf01fc4a8bd1215413cab67.tar.gz
biruda-75df5abae42888bd5bf01fc4a8bd1215413cab67.tar.bz2
updated and fixed linenoise
history now gets read from file started to document the protocol of biruda
Diffstat (limited to 'src/biruda.c')
-rw-r--r--src/biruda.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/src/biruda.c b/src/biruda.c
index 6bbcafe..3543d86 100644
--- a/src/biruda.c
+++ b/src/biruda.c
@@ -215,10 +215,10 @@ static void terminate_foreground_func( int sig )
#ifndef _WIN32
-#define HISTORY_FILE ".biruda.history"
+#define HISTORY_FILE ".biruda_history"
static char *commands[] = {
- "help", "quit", NULL
+ "help", "quit", "status", NULL
};
static void completion_func( const char *buf, linenoiseCompletions *lc )
@@ -240,22 +240,33 @@ static void print_help( )
puts( "\n"
" help - show this help page\n"
" quit - quit the client\n"
+ " status - status of the biruda network\n"
);
}
-static int start_interactive( )
+static void print_status( )
+{
+ puts( "\nStatus\n" );
+}
+
+static void print_error( const char *error, bool colors )
+{
+ if( colors ) {
+ printf( "%c[9%dmERROR: %s%c[0m\n", 27, 1, error, 27 );
+ } else {
+ puts( error );
+ }
+}
+
+static int start_interactive( bool colors )
{
char history_filename[1024];
char *home = getenv( "HOME" );
if( home != NULL ) {
snprintf( history_filename, sizeof( history_filename ), "%s/%s", home, HISTORY_FILE );
- FILE *history_file = fopen( history_filename, "w+" );
- if( history_file != NULL ) {
- fclose( history_file );
- linenoiseHistoryLoad( HISTORY_FILE );
- linenoiseSetCompletionCallback( completion_func );
- }
+ linenoiseHistoryLoad( history_filename );
+ linenoiseSetCompletionCallback( completion_func );
}
char *context = "biruda";
@@ -279,8 +290,12 @@ static int start_interactive( )
if( strncasecmp( line, "quit", 4 ) == 0 ) {
linenoiseHistorySave( history_filename );
return EXIT_SUCCESS;
- } else if( strncasecmp( line, "help", 4 ) == 0 ){
+ } else if( strncasecmp( line, "help", 4 ) == 0 ) {
print_help( );
+ } else if( strncasecmp( line, "status", 6 ) == 0 ) {
+ print_status( );
+ } else {
+ print_error( "Bad command.", colors );
}
}
@@ -318,7 +333,7 @@ int main( int argc, char *argv[] )
}
if( args_info.cli_given ) {
- return start_interactive( );
+ return start_interactive( !args_info.no_colors_given );
}
unsigned int has_master = cfg_size( cfg, "master" );