blob: 38596b0676e60c42c24a6d2026af01dc13832302 [file] [log] [blame]
Amit Arora39f29542010-09-14 12:03:22 +05301/*******************************************************************************
Amit Kucheriac0e17fc2011-01-17 09:35:52 +02002 * Copyright (C) 2010, Linaro Limited.
Amit Arora39f29542010-09-14 12:03:22 +05303 *
4 * This file is part of PowerDebug.
5 *
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *
11 * Contributors:
12 * Amit Arora <amit.arora@linaro.org> (IBM Corporation)
13 * - initial API and implementation
14 *******************************************************************************/
15
Daniel Lezcano15627482011-06-15 15:45:12 +020016#include <stdio.h>
17#include <string.h>
18#include <stdlib.h>
Daniel Lezcanoa12163d2011-06-21 00:57:08 +020019#include <ctype.h>
Daniel Lezcano15627482011-06-15 15:45:12 +020020#include <ncurses.h>
Daniel Lezcano5000abd2011-06-21 00:57:08 +020021#include <sys/types.h>
22#include <regex.h>
Amit Arora47fd9182010-08-24 13:26:06 +053023#include "powerdebug.h"
Daniel Lezcanodb145802011-06-21 00:57:08 +020024#include "mainloop.h"
Amit Arora17552782010-12-02 12:23:14 +053025#include "regulator.h"
Amit Aroraed3e5652010-10-27 12:02:53 +053026#include "display.h"
Amit Arora47fd9182010-08-24 13:26:06 +053027
Daniel Lezcanoeeb13762011-03-26 22:06:17 +010028enum { PT_COLOR_DEFAULT = 1,
29 PT_COLOR_HEADER_BAR,
30 PT_COLOR_ERROR,
31 PT_COLOR_RED,
32 PT_COLOR_YELLOW,
33 PT_COLOR_GREEN,
34 PT_COLOR_BRIGHT,
35 PT_COLOR_BLUE,
36};
37
Amit Arora47fd9182010-08-24 13:26:06 +053038static WINDOW *header_win;
Amit Arora47fd9182010-08-24 13:26:06 +053039static WINDOW *footer_win;
Daniel Lezcanoc196d432011-06-21 00:57:08 +020040static WINDOW *main_win;
Daniel Lezcanod96731a2011-06-15 15:45:12 +020041static int current_win;
Amit Arora47fd9182010-08-24 13:26:06 +053042
Daniel Lezcano2adc48d2011-06-08 23:30:01 +020043/* Number of lines in the virtual window */
44static const int maxrows = 1024;
45
Daniel Lezcano2adc48d2011-06-08 23:30:01 +020046struct rowdata {
47 int attr;
48 void *data;
49};
50
Daniel Lezcanob3e6e812011-06-15 15:45:12 +020051struct windata {
Daniel Lezcanof6656822011-06-15 15:45:12 +020052 WINDOW *pad;
Daniel Lezcanob301b082011-06-15 15:45:12 +020053 struct display_ops *ops;
Daniel Lezcanob3e6e812011-06-15 15:45:12 +020054 struct rowdata *rowdata;
55 char *name;
56 int nrdata;
57 int scrolling;
58 int cursor;
59};
60
Daniel Lezcano4120e262011-06-15 15:45:12 +020061/* Warning this is linked with the enum { CLOCK, REGULATOR, ... } */
Daniel Lezcano176e69d2011-06-15 15:45:12 +020062struct windata windata[] = {
Daniel Lezcano4120e262011-06-15 15:45:12 +020063 [CLOCK] = { .name = "Clocks" },
64 [REGULATOR] = { .name = "Regulators" },
65 [SENSOR] = { .name = "Sensors" },
Daniel Lezcanob3e6e812011-06-15 15:45:12 +020066};
Daniel Lezcano2adc48d2011-06-08 23:30:01 +020067
Daniel Lezcano3abd8b12011-03-26 22:06:15 +010068static void display_fini(void)
69{
70 endwin();
71}
72
Daniel Lezcano653cb4a2011-06-21 00:57:08 +020073static int display_show_header(int win)
Daniel Lezcano7b3da502011-06-15 15:45:12 +020074{
75 int i;
76 int curr_pointer = 0;
Daniel Lezcano4120e262011-06-15 15:45:12 +020077 size_t array_size = sizeof(windata) / sizeof(windata[0]);
Daniel Lezcano7b3da502011-06-15 15:45:12 +020078
79 wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
80 wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
81 werase(header_win);
82
Daniel Lezcanoc757e6d2011-06-21 00:57:08 +020083 mvwprintw(header_win, 0, curr_pointer, "PowerDebug %s", VERSION);
Daniel Lezcano7b3da502011-06-15 15:45:12 +020084 curr_pointer += 20;
85
Daniel Lezcano4120e262011-06-15 15:45:12 +020086 for (i = 0; i < array_size; i++) {
Daniel Lezcano7b3da502011-06-15 15:45:12 +020087 if (win == i)
88 wattron(header_win, A_REVERSE);
89 else
90 wattroff(header_win, A_REVERSE);
91
Daniel Lezcanoc757e6d2011-06-21 00:57:08 +020092 mvwprintw(header_win, 0, curr_pointer, " %s ", windata[i].name);
Daniel Lezcano7b3da502011-06-15 15:45:12 +020093 curr_pointer += strlen(windata[i].name) + 2;
94 }
95 wrefresh(header_win);
Daniel Lezcano7b3da502011-06-15 15:45:12 +020096
Daniel Lezcano653cb4a2011-06-21 00:57:08 +020097 return 0;
98}
99
100#define footer_label " Q (Quit) R (Refresh) Other Keys: 'Left', " \
101 "'Right' , 'Up', 'Down', 'enter', , 'Esc'"
102
Daniel Lezcano5000abd2011-06-21 00:57:08 +0200103static int display_show_footer(int win, char *string)
Daniel Lezcano653cb4a2011-06-21 00:57:08 +0200104{
105 werase(footer_win);
Daniel Lezcano7b3da502011-06-15 15:45:12 +0200106 wattron(footer_win, A_REVERSE);
Daniel Lezcano5000abd2011-06-21 00:57:08 +0200107 mvwprintw(footer_win, 0, 0, "%s", string ? string : footer_label);
Daniel Lezcano7b3da502011-06-15 15:45:12 +0200108 wattroff(footer_win, A_REVERSE);
109 wrefresh(footer_win);
110
111 return 0;
112}
113
Daniel Lezcanodb145802011-06-21 00:57:08 +0200114int display_refresh(int win)
Amit Arora47fd9182010-08-24 13:26:06 +0530115{
Daniel Lezcanodb145802011-06-21 00:57:08 +0200116 /* we are trying to refresh a window which is not showed */
117 if (win != current_win)
118 return 0;
Daniel Lezcanof6656822011-06-15 15:45:12 +0200119
Daniel Lezcanodb145802011-06-21 00:57:08 +0200120 if (windata[win].ops && windata[win].ops->display)
121 return windata[win].ops->display();
Daniel Lezcano971515a2011-06-15 15:45:12 +0200122
123 return 0;
124}
125
Daniel Lezcanob3e6e812011-06-15 15:45:12 +0200126int display_refresh_pad(int win)
Amit Arora728e0c92010-09-14 12:06:09 +0530127{
Daniel Lezcano0a8cc582011-06-21 00:57:08 +0200128 int maxx, maxy;
129
130 getmaxyx(stdscr, maxy, maxx);
131
Daniel Lezcanof6656822011-06-15 15:45:12 +0200132 return prefresh(windata[win].pad, windata[win].scrolling,
Daniel Lezcanob3e6e812011-06-15 15:45:12 +0200133 0, 2, 0, maxy - 2, maxx);
Daniel Lezcano2adc48d2011-06-08 23:30:01 +0200134}
Amit Aroraac4e8652010-11-09 11:16:53 +0530135
Daniel Lezcano28203df2011-06-15 15:45:12 +0200136static int display_show_unselection(int win, int line, bool bold)
Daniel Lezcano2adc48d2011-06-08 23:30:01 +0200137{
Daniel Lezcanof6656822011-06-15 15:45:12 +0200138 if (mvwchgat(windata[win].pad, line, 0, -1,
Daniel Lezcano2adc48d2011-06-08 23:30:01 +0200139 bold ? WA_BOLD: WA_NORMAL, 0, NULL) < 0)
140 return -1;
141
Daniel Lezcanob3e6e812011-06-15 15:45:12 +0200142 return display_refresh_pad(win);
Daniel Lezcano2adc48d2011-06-08 23:30:01 +0200143}
144
Daniel Lezcanob3e6e812011-06-15 15:45:12 +0200145void *display_get_row_data(int win)
Daniel Lezcano2adc48d2011-06-08 23:30:01 +0200146{
Daniel Lezcanob3e6e812011-06-15 15:45:12 +0200147 return windata[win].rowdata[windata[win].cursor].data;
Daniel Lezcano2adc48d2011-06-08 23:30:01 +0200148}
149
Daniel Lezcano28203df2011-06-15 15:45:12 +0200150static int display_select(void)
151{
152 if (windata[current_win].ops && windata[current_win].ops->select)
153 return windata[current_win].ops->select();
154
155 return 0;
156}
157
158static int display_next_panel(void)
159{
160 size_t array_size = sizeof(windata) / sizeof(windata[0]);
161
162 current_win++;
163 current_win %= array_size;
164
165 return current_win;
166}
167
168static int display_prev_panel(void)
169{
170 size_t array_size = sizeof(windata) / sizeof(windata[0]);
171
172 current_win--;
173 if (current_win < 0)
174 current_win = array_size - 1;
175
176 return current_win;
177}
178
179static int display_next_line(void)
180{
Daniel Lezcano0a8cc582011-06-21 00:57:08 +0200181 int maxx, maxy;
Daniel Lezcano28203df2011-06-15 15:45:12 +0200182 int cursor = windata[current_win].cursor;
183 int nrdata = windata[current_win].nrdata;
184 int scrolling = windata[current_win].scrolling;
185 struct rowdata *rowdata = windata[current_win].rowdata;
186
Daniel Lezcano0a8cc582011-06-21 00:57:08 +0200187 getmaxyx(stdscr, maxy, maxx);
188
Daniel Lezcano28203df2011-06-15 15:45:12 +0200189 if (cursor >= nrdata)
190 return cursor;
191
192 display_show_unselection(current_win, cursor, rowdata[cursor].attr);
193 if (cursor < nrdata - 1) {
194 if (cursor >= (maxy - 4 + scrolling))
195 scrolling++;
196 cursor++;
197 }
198
199 windata[current_win].scrolling = scrolling;
200 windata[current_win].cursor = cursor;
201
202 return cursor;
203}
204
205static int display_prev_line(void)
206{
207 int cursor = windata[current_win].cursor;
208 int nrdata = windata[current_win].nrdata;
209 int scrolling = windata[current_win].scrolling;
210 struct rowdata *rowdata = windata[current_win].rowdata;
211
212 if (cursor >= nrdata)
213 return cursor;
214
215 display_show_unselection(current_win, cursor, rowdata[cursor].attr);
216 if (cursor > 0) {
217 if (cursor <= scrolling)
218 scrolling--;
219 cursor--;
220 }
221
222 windata[current_win].scrolling = scrolling;
223 windata[current_win].cursor = cursor;
224
225 return cursor;
226}
227
228static int display_set_row_data(int win, int line, void *data, int attr)
Daniel Lezcano2adc48d2011-06-08 23:30:01 +0200229{
Daniel Lezcanob3e6e812011-06-15 15:45:12 +0200230 struct rowdata *rowdata = windata[win].rowdata;
231
232 if (line >= windata[win].nrdata) {
Daniel Lezcano2adc48d2011-06-08 23:30:01 +0200233 rowdata = realloc(rowdata, sizeof(struct rowdata) * (line + 1));
234 if (!rowdata)
235 return -1;
Daniel Lezcanob3e6e812011-06-15 15:45:12 +0200236 windata[win].nrdata = line + 1;
Daniel Lezcano2adc48d2011-06-08 23:30:01 +0200237 }
238
239 rowdata[line].data = data;
240 rowdata[line].attr = attr;
Daniel Lezcanob3e6e812011-06-15 15:45:12 +0200241 windata[win].rowdata = rowdata;
Daniel Lezcano2adc48d2011-06-08 23:30:01 +0200242
243 return 0;
244}
245
Daniel Lezcanof6656822011-06-15 15:45:12 +0200246int display_reset_cursor(int win)
Daniel Lezcano2adc48d2011-06-08 23:30:01 +0200247{
Daniel Lezcanob3e6e812011-06-15 15:45:12 +0200248 windata[win].nrdata = 0;
Daniel Lezcanof6656822011-06-15 15:45:12 +0200249 werase(windata[win].pad);
250 return wmove(windata[win].pad, 0, 0);
Daniel Lezcano2adc48d2011-06-08 23:30:01 +0200251}
252
Daniel Lezcanob3e6e812011-06-15 15:45:12 +0200253int display_print_line(int win, int line, char *str, int bold, void *data)
Daniel Lezcano2adc48d2011-06-08 23:30:01 +0200254{
255 int attr = 0;
256
Amit Arora031263a2010-11-09 11:12:41 +0530257 if (bold)
Daniel Lezcano2adc48d2011-06-08 23:30:01 +0200258 attr |= WA_BOLD;
259
Daniel Lezcanob3e6e812011-06-15 15:45:12 +0200260 if (line == windata[win].cursor)
Daniel Lezcano2adc48d2011-06-08 23:30:01 +0200261 attr |= WA_STANDOUT;
262
Daniel Lezcanob3e6e812011-06-15 15:45:12 +0200263 if (display_set_row_data(win, line, data, attr))
Daniel Lezcano2adc48d2011-06-08 23:30:01 +0200264 return -1;
265
266 if (attr)
Daniel Lezcanof6656822011-06-15 15:45:12 +0200267 wattron(windata[win].pad, attr);
Daniel Lezcano2adc48d2011-06-08 23:30:01 +0200268
Daniel Lezcanof6656822011-06-15 15:45:12 +0200269 wprintw(windata[win].pad, "%s\n", str);
Daniel Lezcano2adc48d2011-06-08 23:30:01 +0200270
271 if (attr)
Daniel Lezcanof6656822011-06-15 15:45:12 +0200272 wattroff(windata[win].pad, attr);
Daniel Lezcano2adc48d2011-06-08 23:30:01 +0200273
274 return 0;
275}
276
Daniel Lezcanoe64c48e2011-06-21 00:57:08 +0200277static int display_find_keystroke(int fd, void *data);
278
Daniel Lezcano5000abd2011-06-21 00:57:08 +0200279struct find_data {
280 size_t len;
281 char *string;
282 regex_t *reg;
283};
284
285struct find_data *display_find_form_init(void)
286{
287 const char *regexp = "^[a-z|0-9|_|-|.]";
288 struct find_data *findd;
289 const size_t len = 64;
290 regex_t *reg;
291 char *search4;
292 int maxx, maxy;
293
294 getmaxyx(stdscr, maxy, maxx);
295
296 reg = malloc(sizeof(*reg));
297 if (!reg)
298 return NULL;
299
300 if (regcomp(reg, regexp, REG_ICASE))
301 goto out_free_reg;
302
303 search4 = malloc(len);
304 if (!search4)
305 goto out_free_regcomp;
306 memset(search4, '\0', len);
307
308 findd = malloc(sizeof(*findd));
309 if (!findd)
310 goto out_free_search4;
311
312 findd->string = search4;
313 findd->reg = reg;
314 findd->len = len;
315out:
316 return findd;
317
318out_free_search4:
319 free(search4);
320out_free_regcomp:
321 regfree(reg);
322out_free_reg:
323 free(reg);
324
325 goto out;
326}
327
328static void display_find_form_fini(struct find_data *fd)
329{
330 regfree(fd->reg);
331 free(fd->string);
332 free(fd);
333 curs_set(0);
334}
335
Daniel Lezcanoe64c48e2011-06-21 00:57:08 +0200336static int display_switch_to_find(int fd)
337{
Daniel Lezcano5000abd2011-06-21 00:57:08 +0200338 struct find_data *findd;
339
340 findd = display_find_form_init();
341 if (!findd)
342 return -1;
343
Daniel Lezcanoe64c48e2011-06-21 00:57:08 +0200344 if (mainloop_del(fd))
345 return -1;
346
Daniel Lezcano5000abd2011-06-21 00:57:08 +0200347 if (mainloop_add(fd, display_find_keystroke, findd))
348 return -1;
349
350 if (display_show_footer(current_win, "find (esc to exit)?"))
Daniel Lezcanoe64c48e2011-06-21 00:57:08 +0200351 return -1;
352
353 return 0;
354}
355
Daniel Lezcanodb145802011-06-21 00:57:08 +0200356static int display_keystroke(int fd, void *data)
Daniel Lezcano176e69d2011-06-15 15:45:12 +0200357{
Daniel Lezcano176e69d2011-06-15 15:45:12 +0200358 int keystroke = getch();
359
360 switch (keystroke) {
361
362 case KEY_RIGHT:
363 case '\t':
Daniel Lezcano372ffba2011-06-21 00:57:08 +0200364 display_show_header(display_next_panel());
Daniel Lezcano176e69d2011-06-15 15:45:12 +0200365 break;
366
367 case KEY_LEFT:
368 case KEY_BTAB:
Daniel Lezcano372ffba2011-06-21 00:57:08 +0200369 display_show_header(display_prev_panel());
Daniel Lezcano176e69d2011-06-15 15:45:12 +0200370 break;
371
372 case KEY_DOWN:
373 display_next_line();
374 break;
375
376 case KEY_UP:
377 display_prev_line();
378 break;
379
380 case '\r':
381 display_select();
382 break;
383
384 case EOF:
385 case 'q':
386 case 'Q':
387 return 1;
388
Daniel Lezcanoe64c48e2011-06-21 00:57:08 +0200389 case '/':
390 return display_switch_to_find(fd);
391
Daniel Lezcano176e69d2011-06-15 15:45:12 +0200392 case 'r':
393 case 'R':
Daniel Lezcanodb145802011-06-21 00:57:08 +0200394 /* refresh will be done after */
Daniel Lezcano176e69d2011-06-15 15:45:12 +0200395 break;
Daniel Lezcanodb145802011-06-21 00:57:08 +0200396 default:
397 return 0;
Daniel Lezcano176e69d2011-06-15 15:45:12 +0200398 }
399
Daniel Lezcanodb145802011-06-21 00:57:08 +0200400 display_refresh(current_win);
401
402 return 0;
403}
404
Daniel Lezcanoe64c48e2011-06-21 00:57:08 +0200405static int display_switch_to_main(int fd)
406{
407 if (mainloop_del(fd))
408 return -1;
409
410 if (mainloop_add(fd, display_keystroke, NULL))
411 return -1;
412
Daniel Lezcano5000abd2011-06-21 00:57:08 +0200413 if (display_show_header(current_win))
414 return -1;
Daniel Lezcanoe64c48e2011-06-21 00:57:08 +0200415
Daniel Lezcano5000abd2011-06-21 00:57:08 +0200416 if (display_show_footer(current_win, NULL))
417 return -1;
418
419 return display_refresh(current_win);
Daniel Lezcanoe64c48e2011-06-21 00:57:08 +0200420}
421
Daniel Lezcanoe64c48e2011-06-21 00:57:08 +0200422static int display_find_keystroke(int fd, void *data)
423{
Daniel Lezcano5000abd2011-06-21 00:57:08 +0200424 struct find_data *findd = data;
425 regex_t *reg = findd->reg;
426 char *string = findd->string;
Daniel Lezcanoe64c48e2011-06-21 00:57:08 +0200427 int keystroke = getch();
Daniel Lezcano5000abd2011-06-21 00:57:08 +0200428 char match[2] = { [0] = (char)keystroke, [1] = '\0' };
429 regmatch_t m[1];
430
Daniel Lezcanoe64c48e2011-06-21 00:57:08 +0200431 switch (keystroke) {
432
433 case '\e':
Daniel Lezcano5000abd2011-06-21 00:57:08 +0200434 display_find_form_fini(findd);
Daniel Lezcanoe64c48e2011-06-21 00:57:08 +0200435 return display_switch_to_main(fd);
Daniel Lezcano5000abd2011-06-21 00:57:08 +0200436
Daniel Lezcanoa12163d2011-06-21 00:57:08 +0200437 case KEY_DOWN:
438 display_next_line();
439 break;
440
441 case KEY_UP:
442 display_prev_line();
443 break;
444
Daniel Lezcano5000abd2011-06-21 00:57:08 +0200445 case KEY_BACKSPACE:
446 if (strlen(string))
447 string[strlen(string) - 1] = '\0';
448 break;
449
Daniel Lezcano73b40022011-06-21 00:57:08 +0200450 case '\r':
451 if (!windata[current_win].ops || !windata[current_win].ops->selectf)
452 return 0;
453
454 if (windata[current_win].ops->selectf())
455 return -1;
456
457 return 0;
Daniel Lezcano5000abd2011-06-21 00:57:08 +0200458
Daniel Lezcanoe64c48e2011-06-21 00:57:08 +0200459 default:
Daniel Lezcano5000abd2011-06-21 00:57:08 +0200460
461 /* We don't want invalid characters for a name */
462 if (regexec(reg, match, 1, m, 0))
463 return 0;
464
465 if (strlen(string) < findd->len - 1)
466 string[strlen(string)] = (char)keystroke;
467
Daniel Lezcanoe64c48e2011-06-21 00:57:08 +0200468 break;
469 }
470
Daniel Lezcanoa12163d2011-06-21 00:57:08 +0200471 if (!windata[current_win].ops || !windata[current_win].ops->find)
472 return 0;
473
474 if (windata[current_win].ops->find(string))
Daniel Lezcano5000abd2011-06-21 00:57:08 +0200475 return -1;
476
Daniel Lezcanoa12163d2011-06-21 00:57:08 +0200477 if (display_show_header(current_win))
Daniel Lezcano5000abd2011-06-21 00:57:08 +0200478 return -1;
479
480 if (display_show_footer(current_win, strlen(string) ? string :
481 "find (esc to exit)?"))
482 return -1;
483
Daniel Lezcanoe64c48e2011-06-21 00:57:08 +0200484 return 0;
485}
486
Daniel Lezcanodb145802011-06-21 00:57:08 +0200487int display_init(int wdefault)
488{
Daniel Lezcano0a8cc582011-06-21 00:57:08 +0200489 int i, maxx, maxy;
Daniel Lezcanodb145802011-06-21 00:57:08 +0200490 size_t array_size = sizeof(windata) / sizeof(windata[0]);
491
492 current_win = wdefault;
493
494 if (mainloop_add(0, display_keystroke, NULL))
495 return -1;
496
497 if (!initscr())
498 return -1;
499
500 start_color();
501 use_default_colors();
502
503 keypad(stdscr, TRUE);
504 noecho();
505 cbreak();
506 curs_set(0);
507 nonl();
508
509 if (init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK) ||
510 init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED) ||
511 init_pair(PT_COLOR_HEADER_BAR, COLOR_WHITE, COLOR_BLACK) ||
512 init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW) ||
513 init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN) ||
514 init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK) ||
515 init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE) ||
516 init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED))
517 return -1;
518
519 if (atexit(display_fini))
520 return -1;
521
522 getmaxyx(stdscr, maxy, maxx);
523
524 for (i = 0; i < array_size; i++) {
525
Daniel Lezcanoc196d432011-06-21 00:57:08 +0200526 main_win = subwin(stdscr, maxy - 2, maxx, 1, 0);
527 if (!main_win)
Daniel Lezcanodb145802011-06-21 00:57:08 +0200528 return -1;
529
530 windata[i].pad = newpad(maxrows, maxx);
531 if (!windata[i].pad)
532 return -1;
533
534 }
535
536 header_win = subwin(stdscr, 1, maxx, 0, 0);
537 if (!header_win)
538 return -1;
539
540 footer_win = subwin(stdscr, 1, maxx, maxy-1, 0);
541 if (!footer_win)
542 return -1;
543
Daniel Lezcano653cb4a2011-06-21 00:57:08 +0200544 if (display_show_header(wdefault))
545 return -1;
546
Daniel Lezcano5000abd2011-06-21 00:57:08 +0200547 if (display_show_footer(wdefault, NULL))
Daniel Lezcanodb145802011-06-21 00:57:08 +0200548 return -1;
549
550 return display_refresh(wdefault);
551}
552
Daniel Lezcano372ffba2011-06-21 00:57:08 +0200553int display_column_name(const char *line)
Daniel Lezcanodb145802011-06-21 00:57:08 +0200554{
Daniel Lezcanoc196d432011-06-21 00:57:08 +0200555 werase(main_win);
556 wattron(main_win, A_BOLD);
Daniel Lezcanofa453332011-06-21 00:57:08 +0200557 mvwprintw(main_win, 0, 0, "%s", line);
Daniel Lezcanoc196d432011-06-21 00:57:08 +0200558 wattroff(main_win, A_BOLD);
559 wrefresh(main_win);
Daniel Lezcanodb145802011-06-21 00:57:08 +0200560
Daniel Lezcano372ffba2011-06-21 00:57:08 +0200561 return 0;
Daniel Lezcanodb145802011-06-21 00:57:08 +0200562}
563
564int display_register(int win, struct display_ops *ops)
565{
566 size_t array_size = sizeof(windata) / sizeof(windata[0]);
567
568 if (win < 0 || win >= array_size)
569 return -1;
570
571 windata[win].ops = ops;
572
Daniel Lezcano176e69d2011-06-15 15:45:12 +0200573 return 0;
574}