]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - tools/thermal/tmon/tui.c
36e1f86c84529208be7e1ba8ed8984902320c7af
[karo-tx-linux.git] / tools / thermal / tmon / tui.c
1 /*
2  * tui.c ncurses text user interface for TMON program
3  *
4  * Copyright (C) 2013 Intel Corporation. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License version
8  * 2 or later as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * Author: Jacob Pan <jacob.jun.pan@linux.intel.com>
16  *
17  */
18
19 #include <unistd.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <stdint.h>
24 #include <ncurses.h>
25 #include <time.h>
26 #include <syslog.h>
27 #include <panel.h>
28 #include <pthread.h>
29 #include <signal.h>
30
31 #include "tmon.h"
32
33 #define min(x, y) ({                            \
34         typeof(x) _min1 = (x);                  \
35         typeof(y) _min2 = (y);                  \
36         (void) (&_min1 == &_min2);              \
37         _min1 < _min2 ? _min1 : _min2; })
38
39 #define max(x, y) ({                            \
40         typeof(x) _max1 = (x);                  \
41         typeof(y) _max2 = (y);                  \
42         (void) (&_max1 == &_max2);              \
43         _max1 > _max2 ? _max1 : _max2; })
44
45 static PANEL *data_panel;
46 static PANEL *dialogue_panel;
47 static PANEL *top;
48
49 static WINDOW *title_bar_window;
50 static WINDOW *tz_sensor_window;
51 static WINDOW *cooling_device_window;
52 static WINDOW *control_window;
53 static WINDOW *status_bar_window;
54 static WINDOW *thermal_data_window;
55 static WINDOW *dialogue_window;
56
57 char status_bar_slots[10][40];
58 static void draw_hbar(WINDOW *win, int y, int start, int len,
59                 unsigned long pattern, bool end);
60
61 static int maxx, maxy;
62 static int maxwidth = 200;
63
64 #define TITLE_BAR_HIGHT 1
65 #define SENSOR_WIN_HIGHT 4 /* one row for tz name, one for trip points */
66
67
68 /* daemon mode flag (set by startup parameter -d) */
69 static int  tui_disabled;
70
71 static void close_panel(PANEL *p)
72 {
73         if (p) {
74                 del_panel(p);
75                 p = NULL;
76         }
77 }
78
79 static void close_window(WINDOW *win)
80 {
81         if (win) {
82                 delwin(win);
83                 win = NULL;
84         }
85 }
86
87 void close_windows(void)
88 {
89         if (tui_disabled)
90                 return;
91         /* must delete panels before their attached windows */
92         if (dialogue_window)
93                 close_panel(dialogue_panel);
94         if (cooling_device_window)
95                 close_panel(data_panel);
96
97         close_window(title_bar_window);
98         close_window(tz_sensor_window);
99         close_window(status_bar_window);
100         close_window(cooling_device_window);
101         close_window(control_window);
102         close_window(thermal_data_window);
103         close_window(dialogue_window);
104
105 }
106
107 void write_status_bar(int x, char *line)
108 {
109         mvwprintw(status_bar_window, 0, x, "%s", line);
110         wrefresh(status_bar_window);
111 }
112
113 /* wrap at 5 */
114 #define DIAG_DEV_ROWS  5
115 /*
116  * list cooling devices + "set temp" entry; wraps after 5 rows, if they fit
117  */
118 static int diag_dev_rows(void)
119 {
120         int entries = ptdata.nr_cooling_dev + 1;
121         int rows = max(DIAG_DEV_ROWS, (entries + 1) / 2);
122         return min(rows, entries);
123 }
124
125 void setup_windows(void)
126 {
127         int y_begin = 1;
128
129         if (tui_disabled)
130                 return;
131
132         getmaxyx(stdscr, maxy, maxx);
133         resizeterm(maxy, maxx);
134
135         title_bar_window = subwin(stdscr, TITLE_BAR_HIGHT, maxx, 0, 0);
136         y_begin += TITLE_BAR_HIGHT;
137
138         tz_sensor_window = subwin(stdscr, SENSOR_WIN_HIGHT, maxx, y_begin, 0);
139         y_begin += SENSOR_WIN_HIGHT;
140
141         cooling_device_window = subwin(stdscr, ptdata.nr_cooling_dev + 3, maxx,
142                                 y_begin, 0);
143         y_begin += ptdata.nr_cooling_dev + 3; /* 2 lines for border */
144         /* two lines to show borders, one line per tz show trip point position
145          * and value.
146          * dialogue window is a pop-up, when needed it lays on top of cdev win
147          */
148
149         dialogue_window = subwin(stdscr, diag_dev_rows() + 5, maxx-50,
150                                 DIAG_Y, DIAG_X);
151
152         thermal_data_window = subwin(stdscr, ptdata.nr_tz_sensor *
153                                 NR_LINES_TZDATA + 3, maxx, y_begin, 0);
154         y_begin += ptdata.nr_tz_sensor * NR_LINES_TZDATA + 3;
155         control_window = subwin(stdscr, 4, maxx, y_begin, 0);
156
157         scrollok(cooling_device_window, TRUE);
158         maxwidth = maxx - 18;
159         status_bar_window = subwin(stdscr, 1, maxx, maxy-1, 0);
160
161         strcpy(status_bar_slots[0], " Ctrl-c - Quit ");
162         strcpy(status_bar_slots[1], " TAB - Tuning ");
163         wmove(status_bar_window, 1, 30);
164
165         /* prepare panels for dialogue, if panel already created then we must
166          * be doing resizing, so just replace windows with new ones, old ones
167          * should have been deleted by close_window
168          */
169         data_panel = new_panel(cooling_device_window);
170         if (!data_panel)
171                 syslog(LOG_DEBUG, "No data panel\n");
172         else {
173                 if (dialogue_window) {
174                         dialogue_panel = new_panel(dialogue_window);
175                         if (!dialogue_panel)
176                                 syslog(LOG_DEBUG, "No dialogue panel\n");
177                         else {
178                                 /* Set up the user pointer to the next panel*/
179                                 set_panel_userptr(data_panel, dialogue_panel);
180                                 set_panel_userptr(dialogue_panel, data_panel);
181                                 top = data_panel;
182                         }
183                 } else
184                         syslog(LOG_INFO, "no dialogue win, term too small\n");
185         }
186         doupdate();
187         werase(stdscr);
188         refresh();
189 }
190
191 void resize_handler(int sig)
192 {
193         /* start over when term gets resized, but first we clean up */
194         close_windows();
195         endwin();
196         refresh();
197         clear();
198         getmaxyx(stdscr, maxy, maxx);  /* get the new screen size */
199         setup_windows();
200         /* rate limit */
201         sleep(1);
202         syslog(LOG_DEBUG, "SIG %d, term resized to %d x %d\n",
203                 sig, maxy, maxx);
204         signal(SIGWINCH, resize_handler);
205 }
206
207 const char cdev_title[] = " COOLING DEVICES ";
208 void show_cooling_device(void)
209 {
210         int i, j, x, y = 0;
211
212         if (tui_disabled || !cooling_device_window)
213                 return;
214
215         werase(cooling_device_window);
216         wattron(cooling_device_window, A_BOLD);
217         mvwprintw(cooling_device_window,  1, 1,
218                 "ID  Cooling Dev   Cur    Max   Thermal Zone Binding");
219         wattroff(cooling_device_window, A_BOLD);
220         for (j = 0; j < ptdata.nr_cooling_dev; j++) {
221                 /* draw cooling device list on the left in the order of
222                  * cooling device instances. skip unused idr.
223                  */
224                 mvwprintw(cooling_device_window, j + 2, 1,
225                         "%02d %12.12s%6d %6d",
226                         ptdata.cdi[j].instance,
227                         ptdata.cdi[j].type,
228                         ptdata.cdi[j].cur_state,
229                         ptdata.cdi[j].max_state);
230         }
231
232         /* show cdev binding, y is the global cooling device instance */
233         for (i = 0; i < ptdata.nr_tz_sensor; i++) {
234                 int tz_inst = ptdata.tzi[i].instance;
235                 for (j = 0; j < ptdata.nr_cooling_dev; j++) {
236                         int cdev_inst;
237                         y = j;
238                         x = tz_inst * TZONE_RECORD_SIZE + TZ_LEFT_ALIGN;
239
240                         draw_hbar(cooling_device_window, y+2, x,
241                                 TZONE_RECORD_SIZE-1, ACS_VLINE, false);
242
243                         /* draw a column of spaces to separate thermal zones */
244                         mvwprintw(cooling_device_window, y+2, x-1, " ");
245                         if (ptdata.tzi[i].cdev_binding) {
246                                 cdev_inst = ptdata.cdi[j].instance;
247                                 unsigned long trip_binding =
248                                         ptdata.tzi[i].trip_binding[cdev_inst];
249                                 int k = 0; /* per zone trip point id that
250                                             * binded to this cdev, one to
251                                             * many possible based on the
252                                             * binding bitmask.
253                                             */
254                                 syslog(LOG_DEBUG,
255                                         "bind tz%d cdev%d tp%lx %d cdev%lx\n",
256                                         i, j, trip_binding, y,
257                                         ptdata.tzi[i].cdev_binding);
258                                 /* draw each trip binding for the cdev */
259                                 while (trip_binding >>= 1) {
260                                         k++;
261                                         if (!(trip_binding & 1))
262                                                 continue;
263                                         /* draw '*' to show binding */
264                                         mvwprintw(cooling_device_window,
265                                                 y + 2,
266                                                 x + ptdata.tzi[i].nr_trip_pts -
267                                                 k - 1, "*");
268                                 }
269                         }
270                 }
271         }
272         /* draw border after data so that border will not be messed up
273          * even there is not enough space for all the data to be shown
274          */
275         wborder(cooling_device_window, 0, 0, 0, 0, 0, 0, 0, 0);
276         wattron(cooling_device_window, A_BOLD);
277         mvwprintw(cooling_device_window, 0, maxx/2 - sizeof(cdev_title),
278                 cdev_title);
279         wattroff(cooling_device_window, A_BOLD);
280
281         wrefresh(cooling_device_window);
282 }
283
284 const char DIAG_TITLE[] = "[ TUNABLES ]";
285 void show_dialogue(void)
286 {
287         int j, x = 0, y = 0;
288         int rows, cols;
289         WINDOW *w = dialogue_window;
290
291         if (tui_disabled || !w)
292                 return;
293
294         getmaxyx(w, rows, cols);
295
296         werase(w);
297         box(w, 0, 0);
298         mvwprintw(w, 0, maxx/4, DIAG_TITLE);
299         /* list all the available tunables */
300         for (j = 0; j <= ptdata.nr_cooling_dev; j++) {
301                 y = j % diag_dev_rows();
302                 if (y == 0 && j != 0)
303                         x += 20;
304                 if (j == ptdata.nr_cooling_dev)
305                         /* save last choice for target temp */
306                         mvwprintw(w, y+1, x+1, "%C-%.12s", 'A'+j, "Set Temp");
307                 else
308                         mvwprintw(w, y+1, x+1, "%C-%.10s-%2d", 'A'+j,
309                                 ptdata.cdi[j].type, ptdata.cdi[j].instance);
310         }
311         wattron(w, A_BOLD);
312         mvwprintw(w, diag_dev_rows()+1, 1, "Enter Choice [A-Z]?");
313         wattroff(w, A_BOLD);
314         /* print legend at the bottom line */
315         mvwprintw(w, rows - 2, 1,
316                 "Legend: A=Active, P=Passive, C=Critical");
317
318         wrefresh(dialogue_window);
319 }
320
321 void write_dialogue_win(char *buf, int y, int x)
322 {
323         WINDOW *w = dialogue_window;
324
325         mvwprintw(w, y, x, "%s", buf);
326 }
327
328 const char control_title[] = " CONTROLS ";
329 void show_control_w(void)
330 {
331         unsigned long state;
332
333         get_ctrl_state(&state);
334
335         if (tui_disabled || !control_window)
336                 return;
337
338         werase(control_window);
339         mvwprintw(control_window, 1, 1,
340                 "PID gain: kp=%2.2f ki=%2.2f kd=%2.2f Output %2.2f",
341                 p_param.kp, p_param.ki, p_param.kd, p_param.y_k);
342
343         mvwprintw(control_window, 2, 1,
344                 "Target Temp: %2.1fC, Zone: %d, Control Device: %.12s",
345                 p_param.t_target, target_thermal_zone, ctrl_cdev);
346
347         /* draw border last such that everything is within boundary */
348         wborder(control_window, 0, 0, 0, 0, 0, 0, 0, 0);
349         wattron(control_window, A_BOLD);
350         mvwprintw(control_window, 0, maxx/2 - sizeof(control_title),
351                 control_title);
352         wattroff(control_window, A_BOLD);
353
354         wrefresh(control_window);
355 }
356
357 void initialize_curses(void)
358 {
359         if (tui_disabled)
360                 return;
361
362         initscr();
363         start_color();
364         keypad(stdscr, TRUE);   /* enable keyboard mapping */
365         nonl();                 /* tell curses not to do NL->CR/NL on output */
366         cbreak();               /* take input chars one at a time */
367         noecho();               /* dont echo input */
368         curs_set(0);            /* turn off cursor */
369         use_default_colors();
370
371         init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK);
372         init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_WHITE);
373         init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED);
374         init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED);
375         init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW);
376         init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN);
377         init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE);
378         init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK);
379
380 }
381
382 void show_title_bar(void)
383 {
384         int i;
385         int x = 0;
386
387         if (tui_disabled || !title_bar_window)
388                 return;
389
390         wattrset(title_bar_window, COLOR_PAIR(PT_COLOR_HEADER_BAR));
391         wbkgd(title_bar_window, COLOR_PAIR(PT_COLOR_HEADER_BAR));
392         werase(title_bar_window);
393
394         mvwprintw(title_bar_window, 0, 0,
395                 "     TMON v%s", VERSION);
396
397         wrefresh(title_bar_window);
398
399         werase(status_bar_window);
400
401         for (i = 0; i < 10; i++) {
402                 if (strlen(status_bar_slots[i]) == 0)
403                         continue;
404                 wattron(status_bar_window, A_REVERSE);
405                 mvwprintw(status_bar_window, 0, x, "%s", status_bar_slots[i]);
406                 wattroff(status_bar_window, A_REVERSE);
407                 x += strlen(status_bar_slots[i]) + 1;
408         }
409         wrefresh(status_bar_window);
410 }
411
412 static void handle_input_val(int ch)
413 {
414         char buf[32];
415         int val;
416         char path[256];
417         WINDOW *w = dialogue_window;
418
419         echo();
420         keypad(w, TRUE);
421         wgetnstr(w, buf, 31);
422         val = atoi(buf);
423
424         if (ch == ptdata.nr_cooling_dev) {
425                 snprintf(buf, 31, "Invalid Temp %d! %d-%d", val,
426                         MIN_CTRL_TEMP, MAX_CTRL_TEMP);
427                 if (val < MIN_CTRL_TEMP || val > MAX_CTRL_TEMP)
428                         write_status_bar(40, buf);
429                 else {
430                         p_param.t_target = val;
431                         snprintf(buf, 31, "Set New Target Temp %d", val);
432                         write_status_bar(40, buf);
433                 }
434         } else {
435                 snprintf(path, 256, "%s/%s%d", THERMAL_SYSFS,
436                         CDEV, ptdata.cdi[ch].instance);
437                 sysfs_set_ulong(path, "cur_state", val);
438         }
439         noecho();
440         dialogue_on = 0;
441         show_data_w();
442         show_control_w();
443
444         top = (PANEL *)panel_userptr(top);
445         top_panel(top);
446 }
447
448 static void handle_input_choice(int ch)
449 {
450         char buf[48];
451         int base = 0;
452         int cdev_id = 0;
453
454         if ((ch >= 'A' && ch <= 'A' + ptdata.nr_cooling_dev) ||
455                 (ch >= 'a' && ch <= 'a' + ptdata.nr_cooling_dev)) {
456                 base = (ch < 'a') ? 'A' : 'a';
457                 cdev_id = ch - base;
458                 if (ptdata.nr_cooling_dev == cdev_id)
459                         snprintf(buf, sizeof(buf), "New Target Temp:");
460                 else
461                         snprintf(buf, sizeof(buf), "New Value for %.10s-%2d: ",
462                                 ptdata.cdi[cdev_id].type,
463                                 ptdata.cdi[cdev_id].instance);
464                 write_dialogue_win(buf, diag_dev_rows() + 2, 2);
465                 handle_input_val(cdev_id);
466         } else {
467                 snprintf(buf, sizeof(buf), "Invalid selection %d", ch);
468                 write_dialogue_win(buf, 8, 2);
469         }
470 }
471
472 void *handle_tui_events(void *arg)
473 {
474         int ch;
475
476         keypad(cooling_device_window, TRUE);
477         while ((ch = wgetch(cooling_device_window)) != EOF) {
478                 if (tmon_exit)
479                         break;
480                 /* when term size is too small, no dialogue panels are set.
481                  * we need to filter out such cases.
482                  */
483                 if (!data_panel || !dialogue_panel ||
484                         !cooling_device_window ||
485                         !dialogue_window) {
486
487                         continue;
488                 }
489                 pthread_mutex_lock(&input_lock);
490                 if (dialogue_on) {
491                         handle_input_choice(ch);
492                         /* top panel filter */
493                         if (ch == 'q' || ch == 'Q')
494                                 ch = 0;
495                 }
496                 switch (ch) {
497                 case KEY_LEFT:
498                         box(cooling_device_window, 10, 0);
499                         break;
500                 case 9: /* TAB */
501                         top = (PANEL *)panel_userptr(top);
502                         top_panel(top);
503                         if (top == dialogue_panel) {
504                                 dialogue_on = 1;
505                                 show_dialogue();
506                         } else {
507                                 dialogue_on = 0;
508                                 /* force refresh */
509                                 show_data_w();
510                                 show_control_w();
511                         }
512                         break;
513                 case 'q':
514                 case 'Q':
515                         tmon_exit = 1;
516                         break;
517                 }
518                 update_panels();
519                 doupdate();
520                 pthread_mutex_unlock(&input_lock);
521         }
522
523         if (arg)
524                 *(int *)arg = 0; /* make gcc happy */
525
526         return NULL;
527 }
528
529 /* draw a horizontal bar in given pattern */
530 static void draw_hbar(WINDOW *win, int y, int start, int len, unsigned long ptn,
531                 bool end)
532 {
533         mvwaddch(win, y, start, ptn);
534         whline(win, ptn, len);
535         if (end)
536                 mvwaddch(win, y, MAX_DISP_TEMP+TDATA_LEFT, ']');
537 }
538
539 static char trip_type_to_char(int type)
540 {
541         switch (type) {
542         case THERMAL_TRIP_CRITICAL: return 'C';
543         case THERMAL_TRIP_HOT: return 'H';
544         case THERMAL_TRIP_PASSIVE: return 'P';
545         case THERMAL_TRIP_ACTIVE: return 'A';
546         default:
547                 return '?';
548         }
549 }
550
551 /* fill a string with trip point type and value in one line
552  * e.g.      P(56)    C(106)
553  * maintain the distance one degree per char
554  */
555 static void draw_tp_line(int tz, int y)
556 {
557         int j;
558         int x;
559
560         for (j = 0; j < ptdata.tzi[tz].nr_trip_pts; j++) {
561                 x = ptdata.tzi[tz].tp[j].temp / 1000;
562                 mvwprintw(thermal_data_window, y + 0, x + TDATA_LEFT,
563                         "%c%d", trip_type_to_char(ptdata.tzi[tz].tp[j].type),
564                         x);
565                 syslog(LOG_INFO, "%s:tz %d tp %d temp = %lu\n", __func__,
566                         tz, j, ptdata.tzi[tz].tp[j].temp);
567         }
568 }
569
570 const char data_win_title[] = " THERMAL DATA ";
571 void show_data_w(void)
572 {
573         int i;
574
575
576         if (tui_disabled || !thermal_data_window)
577                 return;
578
579         werase(thermal_data_window);
580         wattron(thermal_data_window, A_BOLD);
581         mvwprintw(thermal_data_window, 0, maxx/2 - sizeof(data_win_title),
582                 data_win_title);
583         wattroff(thermal_data_window, A_BOLD);
584         /* draw a line as ruler */
585         for (i = 10; i < MAX_DISP_TEMP; i += 10)
586                 mvwprintw(thermal_data_window, 1, i+TDATA_LEFT, "%2d", i);
587
588         for (i = 0; i < ptdata.nr_tz_sensor; i++) {
589                 int temp = trec[cur_thermal_record].temp[i] / 1000;
590                 int y = 0;
591
592                 y = i * NR_LINES_TZDATA + 2;
593                 /* y at tz temp data line */
594                 mvwprintw(thermal_data_window, y, 1, "%6.6s%2d:[%3d][",
595                         ptdata.tzi[i].type,
596                         ptdata.tzi[i].instance, temp);
597                 draw_hbar(thermal_data_window, y, TDATA_LEFT, temp, ACS_RARROW,
598                         true);
599                 draw_tp_line(i, y);
600         }
601         wborder(thermal_data_window, 0, 0, 0, 0, 0, 0, 0, 0);
602         wrefresh(thermal_data_window);
603 }
604
605 const char tz_title[] = "THERMAL ZONES(SENSORS)";
606
607 void show_sensors_w(void)
608 {
609         int i, j;
610         char buffer[512];
611
612         if (tui_disabled || !tz_sensor_window)
613                 return;
614
615         werase(tz_sensor_window);
616
617         memset(buffer, 0, sizeof(buffer));
618         wattron(tz_sensor_window, A_BOLD);
619         mvwprintw(tz_sensor_window, 1, 1, "Thermal Zones:");
620         wattroff(tz_sensor_window, A_BOLD);
621
622         mvwprintw(tz_sensor_window, 1, TZ_LEFT_ALIGN, "%s", buffer);
623         /* fill trip points for each tzone */
624         wattron(tz_sensor_window, A_BOLD);
625         mvwprintw(tz_sensor_window, 2, 1, "Trip Points:");
626         wattroff(tz_sensor_window, A_BOLD);
627
628         /* draw trip point from low to high for each tz */
629         for (i = 0; i < ptdata.nr_tz_sensor; i++) {
630                 int inst = ptdata.tzi[i].instance;
631
632                 mvwprintw(tz_sensor_window, 1,
633                         TZ_LEFT_ALIGN+TZONE_RECORD_SIZE * inst, "%.9s%02d",
634                         ptdata.tzi[i].type, ptdata.tzi[i].instance);
635                 for (j = ptdata.tzi[i].nr_trip_pts - 1; j >= 0; j--) {
636                         /* loop through all trip points */
637                         char type;
638                         int tp_pos;
639                         /* reverse the order here since trips are sorted
640                          * in ascending order in terms of temperature.
641                          */
642                         tp_pos = ptdata.tzi[i].nr_trip_pts - j - 1;
643
644                         type = trip_type_to_char(ptdata.tzi[i].tp[j].type);
645                         mvwaddch(tz_sensor_window, 2,
646                                 inst * TZONE_RECORD_SIZE + TZ_LEFT_ALIGN +
647                                 tp_pos, type);
648                         syslog(LOG_DEBUG, "draw tz %d tp %d ch:%c\n",
649                                 inst, j, type);
650                 }
651         }
652         wborder(tz_sensor_window, 0, 0, 0, 0, 0, 0, 0, 0);
653         wattron(tz_sensor_window, A_BOLD);
654         mvwprintw(tz_sensor_window, 0, maxx/2 - sizeof(tz_title), tz_title);
655         wattroff(tz_sensor_window, A_BOLD);
656         wrefresh(tz_sensor_window);
657 }
658
659 void disable_tui(void)
660 {
661         tui_disabled = 1;
662 }