From 49eb22916baa29a4a470a71889bebada5ada7a63 Mon Sep 17 00:00:00 2001 From: vvaltman Date: Mon, 25 Aug 2014 04:11:41 +0400 Subject: [PATCH] interface updates --- interface.c | 3 +++ loop.c | 9 ++++++++ main.c | 63 +++++++++++++++++++++++++++++++++++------------------ 3 files changed, 54 insertions(+), 21 deletions(-) diff --git a/interface.c b/interface.c index 86ac33a..f18e249 100644 --- a/interface.c +++ b/interface.c @@ -69,6 +69,7 @@ char *default_prompt = "> "; int msg_num_mode; +int disable_colors; int alert_sound; extern int binlog_read; @@ -1629,12 +1630,14 @@ int color_stack_pos; const char *color_stack[10]; void push_color (const char *color) { + if (disable_colors) { return; } assert (color_stack_pos < 10); color_stack[color_stack_pos ++] = color; printf ("%s", color); } void pop_color (void) { + if (disable_colors) { return; } assert (color_stack_pos > 0); color_stack_pos --; if (color_stack_pos >= 1) { diff --git a/loop.c b/loop.c index 4cb0212..dba6fb5 100644 --- a/loop.c +++ b/loop.c @@ -394,6 +394,10 @@ void read_auth_file (void) { close (auth_file_fd); } +void dlist_cb (void *callback_extra, int success, int size, tgl_peer_id_t peers[], int last_msg_id[], int unread_count[]) { + d_got_ok = 1; +} + int loop (void) { //on_start (); tgl_set_callback (&upd_cb); @@ -544,6 +548,11 @@ int loop (void) { tgl_do_get_difference (sync_from_start, get_difference_callback, 0); net_loop (0, dgot); assert (!(tgl_state.locks & TGL_LOCK_DIFF)); + if (wait_dialog_list) { + d_got_ok = 0; + tgl_do_get_dialog_list (dlist_cb, 0); + net_loop (0, dgot); + } #ifdef USE_LUA lua_diff_end (); #endif diff --git a/main.c b/main.c index c2dcae0..0b4404e 100644 --- a/main.c +++ b/main.c @@ -92,6 +92,7 @@ extern int log_level; int sync_from_start; int allow_weak_random; char *lua_file; +int disable_colors; void set_default_username (const char *s) { if (default_username) { @@ -374,23 +375,25 @@ void inner_main (void) { void usage (void) { printf ("%s Usage\n", PROGNAME); - - printf (" -h this help list\n"); - printf (" -u username specify username\n"); - printf (" -k public-key specify server public key\n"); - printf (" -v verbose\n"); - printf (" -l [1-3] log level\n"); - printf (" -L log-file log net file\n"); - printf (" -N message num mode\n"); - printf (" -c config-file specify config file\n"); - printf (" -p prefix specify prefix\n"); - printf (" -f sync from start\n"); - printf (" -B enable binlog\n"); - printf (" -E disable auto accept\n"); - printf (" -w allow weak random\n"); - printf (" -s specify lua script\n"); - printf (" -W wait dialog list\n"); - printf ("\n"); + + printf (" -u specify username (would not be asked during authorization)\n"); + printf (" -k specify location of public key (possible multiple entries)\n"); + printf (" -v increase verbosity (0-ERROR 1-WARNIN 2-NOTICE 3+-DEBUG-levels)\n"); + printf (" -N message num mode\n"); + #ifdef HAVE_LIBCONFIG + printf (" -c config file name\n"); + printf (" -p use specified profile\n"); + #else + printf (" -B enable binlog\n"); + #endif + printf (" -l log level\n"); + printf (" -f during authorization fetch all messages since registration\n"); + printf (" -E diable auto accept of encrypted chats\n"); + #ifdef USE_LUA + printf (" -s lua script file\n"); + #endif + printf (" -W send dialog_list query and wait for answer before reading input\n"); + printf (" -C disable color output\n"); exit (1); } @@ -408,7 +411,17 @@ int wait_dialog_list; void args_parse (int argc, char **argv) { int opt = 0; - while ((opt = getopt (argc, argv, "u:hk:vn:Nc:p:l:fBEs:wW")) != -1) { + while ((opt = getopt (argc, argv, "u:hk:vNl:fEwWC" +#ifdef HAVE_LIBCONFIG + "c:p:" +#else + "B" +#endif +#ifdef USE_LUA + "c" +#endif + + )) != -1) { switch (opt) { case 'u': set_default_username (optarg); @@ -424,6 +437,7 @@ void args_parse (int argc, char **argv) { case 'N': msg_num_mode ++; break; +#ifdef HAVE_LIBCONFIG case 'c': config_filename = tstrdup (optarg); break; @@ -431,6 +445,11 @@ void args_parse (int argc, char **argv) { prefix = tstrdup (optarg); assert (strlen (prefix) <= 100); break; +#else + case 'B': + binlog_enabled = 1; + break; +#endif case 'l': log_level = atoi (optarg); break; @@ -440,9 +459,6 @@ void args_parse (int argc, char **argv) { case 'f': sync_from_start = 1; break; - case 'B': - binlog_enabled = 1; - break; //case 'L': // if (log_net_file) { // usage (); @@ -457,12 +473,17 @@ void args_parse (int argc, char **argv) { case 'w': allow_weak_random = 1; break; +#ifdef USE_LUA case 's': lua_file = tstrdup (optarg); break; +#endif case 'W': wait_dialog_list = 1; break; + case 'C': + disable_colors ++; + break; case 'h': default: usage ();