Namhyung Kim | e6e9046 | 2012-08-16 17:14:50 +0900 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | #include <pthread.h> |
| 5 | |
| 6 | #include "../../util/debug.h" |
| 7 | #include "../helpline.h" |
| 8 | #include "../ui.h" |
| 9 | #include "../libslang.h" |
| 10 | |
Namhyung Kim | b56e533 | 2012-11-15 01:47:41 +0900 | [diff] [blame] | 11 | char ui_helpline__last_msg[1024]; |
Namhyung Kim | 4397bd2 | 2015-01-20 15:40:50 +0900 | [diff] [blame] | 12 | bool tui_helpline__set; |
Namhyung Kim | b56e533 | 2012-11-15 01:47:41 +0900 | [diff] [blame] | 13 | |
Namhyung Kim | e6e9046 | 2012-08-16 17:14:50 +0900 | [diff] [blame] | 14 | static void tui_helpline__pop(void) |
| 15 | { |
| 16 | } |
| 17 | |
| 18 | static void tui_helpline__push(const char *msg) |
| 19 | { |
| 20 | const size_t sz = sizeof(ui_helpline__current); |
| 21 | |
| 22 | SLsmg_gotorc(SLtt_Screen_Rows - 1, 0); |
| 23 | SLsmg_set_color(0); |
| 24 | SLsmg_write_nstring((char *)msg, SLtt_Screen_Cols); |
| 25 | SLsmg_refresh(); |
| 26 | strncpy(ui_helpline__current, msg, sz)[sz - 1] = '\0'; |
| 27 | } |
| 28 | |
Namhyung Kim | b56e533 | 2012-11-15 01:47:41 +0900 | [diff] [blame] | 29 | static int tui_helpline__show(const char *format, va_list ap) |
Namhyung Kim | e6e9046 | 2012-08-16 17:14:50 +0900 | [diff] [blame] | 30 | { |
| 31 | int ret; |
| 32 | static int backlog; |
| 33 | |
| 34 | pthread_mutex_lock(&ui__lock); |
| 35 | ret = vscnprintf(ui_helpline__last_msg + backlog, |
| 36 | sizeof(ui_helpline__last_msg) - backlog, format, ap); |
| 37 | backlog += ret; |
| 38 | |
Namhyung Kim | 4397bd2 | 2015-01-20 15:40:50 +0900 | [diff] [blame] | 39 | tui_helpline__set = true; |
| 40 | |
Namhyung Kim | e6e9046 | 2012-08-16 17:14:50 +0900 | [diff] [blame] | 41 | if (ui_helpline__last_msg[backlog - 1] == '\n') { |
| 42 | ui_helpline__puts(ui_helpline__last_msg); |
| 43 | SLsmg_refresh(); |
| 44 | backlog = 0; |
| 45 | } |
| 46 | pthread_mutex_unlock(&ui__lock); |
| 47 | |
| 48 | return ret; |
| 49 | } |
Namhyung Kim | b56e533 | 2012-11-15 01:47:41 +0900 | [diff] [blame] | 50 | |
| 51 | struct ui_helpline tui_helpline_fns = { |
| 52 | .pop = tui_helpline__pop, |
| 53 | .push = tui_helpline__push, |
| 54 | .show = tui_helpline__show, |
| 55 | }; |
| 56 | |
| 57 | void ui_helpline__init(void) |
| 58 | { |
| 59 | helpline_fns = &tui_helpline_fns; |
| 60 | ui_helpline__puts(" "); |
| 61 | } |