Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <stdio.h>
0003 #include <stdlib.h>
0004 #include <string.h>
0005 #include <pthread.h>
0006 #include <linux/kernel.h>
0007 #include <linux/string.h>
0008 
0009 #include "../helpline.h"
0010 #include "../ui.h"
0011 #include "../libslang.h"
0012 
0013 char ui_helpline__last_msg[1024];
0014 bool tui_helpline__set;
0015 
0016 static void tui_helpline__pop(void)
0017 {
0018 }
0019 
0020 static void tui_helpline__push(const char *msg)
0021 {
0022     const size_t sz = sizeof(ui_helpline__current);
0023 
0024     SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
0025     SLsmg_set_color(0);
0026     SLsmg_write_nstring((char *)msg, SLtt_Screen_Cols);
0027     SLsmg_refresh();
0028     strlcpy(ui_helpline__current, msg, sz);
0029 }
0030 
0031 static int tui_helpline__show(const char *format, va_list ap)
0032 {
0033     int ret;
0034     static int backlog;
0035 
0036     pthread_mutex_lock(&ui__lock);
0037     ret = vscnprintf(ui_helpline__last_msg + backlog,
0038             sizeof(ui_helpline__last_msg) - backlog, format, ap);
0039     backlog += ret;
0040 
0041     tui_helpline__set = true;
0042 
0043     if (ui_helpline__last_msg[backlog - 1] == '\n') {
0044         ui_helpline__puts(ui_helpline__last_msg);
0045         SLsmg_refresh();
0046         backlog = 0;
0047     }
0048     pthread_mutex_unlock(&ui__lock);
0049 
0050     return ret;
0051 }
0052 
0053 struct ui_helpline tui_helpline_fns = {
0054     .pop    = tui_helpline__pop,
0055     .push   = tui_helpline__push,
0056     .show   = tui_helpline__show,
0057 };
0058 
0059 void ui_helpline__init(void)
0060 {
0061     helpline_fns = &tui_helpline_fns;
0062     ui_helpline__puts(" ");
0063 }