diff options
author | Andreas Eversberg <jolly@eversberg.eu> | 2016-07-24 09:12:54 +0200 |
---|---|---|
committer | Andreas Eversberg <jolly@eversberg.eu> | 2016-07-24 12:31:08 +0200 |
commit | c273bbc5ff8c6e35ec7a0b1524e509e0a6520d98 (patch) | |
tree | 7cd127ca1b4b1f133fbd556ee4c2fea4ea9ab5f3 /src/common | |
parent | 123979a0f366120155cc043fe8f8743340bdf85d (diff) |
Remove console line before printing debugging and on exit
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/call.c | 30 | ||||
-rw-r--r-- | src/common/call.h | 1 | ||||
-rw-r--r-- | src/common/debug.c | 2 | ||||
-rw-r--r-- | src/common/main_common.c | 2 |
4 files changed, 29 insertions, 6 deletions
diff --git a/src/common/call.c b/src/common/call.c index 0b0ab17..0abb7f6 100644 --- a/src/common/call.c +++ b/src/common/call.c @@ -472,6 +472,10 @@ void call_cleanup(void) } } +static char console_text[256]; +static char console_clear[256]; +static int console_len = 0; + static void process_ui(int c) { switch (call.state) { @@ -501,7 +505,7 @@ dial_after_hangup: } } } - printf("on-hook: %s%s (enter 0..9 or d=dial)\r", call.station_id, "..............." + 15 - call.dial_digits + strlen(call.station_id)); + sprintf(console_text, "on-hook: %s%s (enter 0..9 or d=dial)\r", call.station_id, "..............." + 15 - call.dial_digits + strlen(call.station_id)); break; case CALL_SETUP_MO: case CALL_SETUP_MT: @@ -521,22 +525,36 @@ dial_after_hangup: } } if (call.state == CALL_SETUP_MT) - printf("call setup: %s (enter h=hangup)\r", call.station_id); + sprintf(console_text, "call setup: %s (enter h=hangup)\r", call.station_id); if (call.state == CALL_ALERTING) - printf("call ringing: %s (enter h=hangup)\r", call.station_id); + sprintf(console_text, "call ringing: %s (enter h=hangup)\r", call.station_id); if (call.state == CALL_CONNECT) { if (call.dialing[0]) - printf("call active: %s->%s (enter h=hangup)\r", call.station_id, call.dialing); + sprintf(console_text, "call active: %s->%s (enter h=hangup)\r", call.station_id, call.dialing); else - printf("call active: %s (enter h=hangup)\r", call.station_id); + sprintf(console_text, "call active: %s (enter h=hangup)\r", call.station_id); } if (call.state == CALL_DISCONNECTED) - printf("call disconnected: %s (enter h=hangup)\r", cause_name(call.disc_cause)); + sprintf(console_text, "call disconnected: %s (enter h=hangup)\r", cause_name(call.disc_cause)); break; } + console_len = strlen(console_text); + memset(console_clear, ' ', console_len - 1); + console_clear[console_len - 1] = '\r'; + fwrite(console_text, console_len, 1, stdout); fflush(stdout); } +void clear_console_text(void) +{ + if (!console_len) + return; + + fwrite(console_clear, console_len, 1, stdout); + // note: fflused by user of this function +} + + /* get keys from keyboad to control call via console * returns 1 on exit (ctrl+c) */ void process_call(int c) diff --git a/src/common/call.h b/src/common/call.h index a540aac..0ee3003 100644 --- a/src/common/call.h +++ b/src/common/call.h @@ -12,6 +12,7 @@ enum number_type { int call_init(const char *station_id, const char *sounddev, int samplerate, int latency, int dial_digits, int loopback); void call_cleanup(void); void process_call(int c); +void clear_console_text(void); /* received messages */ int call_in_setup(int callref, const char *callerid, const char *dialing); diff --git a/src/common/debug.c b/src/common/debug.c index 2130ac5..c075f13 100644 --- a/src/common/debug.c +++ b/src/common/debug.c @@ -24,6 +24,7 @@ #include <stdint.h> #include <errno.h> #include "debug.h" +#include "call.h" const char *debug_level[] = { "debug ", @@ -78,6 +79,7 @@ void _printdebug(const char *file, const char *function, int line, int cat, int while ((p = strchr(file, '/'))) file = p + 1; + clear_console_text(); // printf("%s%s:%d %s() %s: %s\033[0;39m", debug_cat[cat].color, file, line, function, debug_level[level], buffer); printf("%s%s:%d %s: %s\033[0;39m", debug_cat[cat].color, file, line, debug_level[level], buffer); fflush(stdout); diff --git a/src/common/main_common.c b/src/common/main_common.c index e104c56..4bd9e94 100644 --- a/src/common/main_common.c +++ b/src/common/main_common.c @@ -341,6 +341,8 @@ next_char: usleep(interval * 1000); } + clear_console_text(); + /* reset terminal */ tcsetattr(0, TCSANOW, &term_orig); } |