Amit Arora | 39f2954 | 2010-09-14 12:03:22 +0530 | [diff] [blame] | 1 | /******************************************************************************* |
Amit Kucheria | c0e17fc | 2011-01-17 09:35:52 +0200 | [diff] [blame] | 2 | * Copyright (C) 2010, Linaro Limited. |
Amit Arora | 39f2954 | 2010-09-14 12:03:22 +0530 | [diff] [blame] | 3 | * |
| 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 Lezcano | 1562748 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 16 | #include <stdio.h> |
| 17 | #include <string.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <ncurses.h> |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 20 | #include "powerdebug.h" |
Daniel Lezcano | db14580 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 21 | #include "mainloop.h" |
Amit Arora | 1755278 | 2010-12-02 12:23:14 +0530 | [diff] [blame] | 22 | #include "regulator.h" |
Amit Arora | ed3e565 | 2010-10-27 12:02:53 +0530 | [diff] [blame] | 23 | #include "display.h" |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 24 | |
Daniel Lezcano | eeb1376 | 2011-03-26 22:06:17 +0100 | [diff] [blame] | 25 | enum { PT_COLOR_DEFAULT = 1, |
| 26 | PT_COLOR_HEADER_BAR, |
| 27 | PT_COLOR_ERROR, |
| 28 | PT_COLOR_RED, |
| 29 | PT_COLOR_YELLOW, |
| 30 | PT_COLOR_GREEN, |
| 31 | PT_COLOR_BRIGHT, |
| 32 | PT_COLOR_BLUE, |
| 33 | }; |
| 34 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 35 | static WINDOW *header_win; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 36 | static WINDOW *footer_win; |
Daniel Lezcano | c196d43 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 37 | static WINDOW *main_win; |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 38 | static int current_win; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 39 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 40 | /* Number of lines in the virtual window */ |
| 41 | static const int maxrows = 1024; |
| 42 | |
Daniel Lezcano | 7b3da50 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 43 | #define footer_label " Q (Quit) R (Refresh) Other Keys: 'Left', " \ |
| 44 | "'Right' , 'Up', 'Down', 'enter', , 'Esc'" |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 45 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 46 | struct rowdata { |
| 47 | int attr; |
| 48 | void *data; |
| 49 | }; |
| 50 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 51 | struct windata { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 52 | WINDOW *pad; |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 53 | struct display_ops *ops; |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 54 | struct rowdata *rowdata; |
| 55 | char *name; |
| 56 | int nrdata; |
| 57 | int scrolling; |
| 58 | int cursor; |
| 59 | }; |
| 60 | |
Daniel Lezcano | 4120e26 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 61 | /* Warning this is linked with the enum { CLOCK, REGULATOR, ... } */ |
Daniel Lezcano | 176e69d | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 62 | struct windata windata[] = { |
Daniel Lezcano | 4120e26 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 63 | [CLOCK] = { .name = "Clocks" }, |
| 64 | [REGULATOR] = { .name = "Regulators" }, |
| 65 | [SENSOR] = { .name = "Sensors" }, |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 66 | }; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 67 | |
Daniel Lezcano | 3abd8b1 | 2011-03-26 22:06:15 +0100 | [diff] [blame] | 68 | static void display_fini(void) |
| 69 | { |
| 70 | endwin(); |
| 71 | } |
| 72 | |
Daniel Lezcano | 7b3da50 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 73 | static int show_header_footer(int win) |
| 74 | { |
| 75 | int i; |
| 76 | int curr_pointer = 0; |
Daniel Lezcano | 4120e26 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 77 | size_t array_size = sizeof(windata) / sizeof(windata[0]); |
Daniel Lezcano | 7b3da50 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 78 | |
| 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 Lezcano | c757e6d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 83 | mvwprintw(header_win, 0, curr_pointer, "PowerDebug %s", VERSION); |
Daniel Lezcano | 7b3da50 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 84 | curr_pointer += 20; |
| 85 | |
Daniel Lezcano | 4120e26 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 86 | for (i = 0; i < array_size; i++) { |
Daniel Lezcano | 7b3da50 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 87 | if (win == i) |
| 88 | wattron(header_win, A_REVERSE); |
| 89 | else |
| 90 | wattroff(header_win, A_REVERSE); |
| 91 | |
Daniel Lezcano | c757e6d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 92 | mvwprintw(header_win, 0, curr_pointer, " %s ", windata[i].name); |
Daniel Lezcano | 7b3da50 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 93 | curr_pointer += strlen(windata[i].name) + 2; |
| 94 | } |
| 95 | wrefresh(header_win); |
| 96 | werase(footer_win); |
| 97 | |
| 98 | wattron(footer_win, A_REVERSE); |
Daniel Lezcano | c757e6d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 99 | mvwprintw(footer_win, 0, 0, "%s", footer_label); |
Daniel Lezcano | 7b3da50 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 100 | wattroff(footer_win, A_REVERSE); |
| 101 | wrefresh(footer_win); |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
Daniel Lezcano | db14580 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 106 | int display_refresh(int win) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 107 | { |
Daniel Lezcano | db14580 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 108 | /* we are trying to refresh a window which is not showed */ |
| 109 | if (win != current_win) |
| 110 | return 0; |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 111 | |
Daniel Lezcano | db14580 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 112 | if (windata[win].ops && windata[win].ops->display) |
| 113 | return windata[win].ops->display(); |
Daniel Lezcano | 971515a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 118 | int display_refresh_pad(int win) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 119 | { |
Daniel Lezcano | 0a8cc58 | 2011-06-21 00:57:08 +0200 | [diff] [blame^] | 120 | int maxx, maxy; |
| 121 | |
| 122 | getmaxyx(stdscr, maxy, maxx); |
| 123 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 124 | return prefresh(windata[win].pad, windata[win].scrolling, |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 125 | 0, 2, 0, maxy - 2, maxx); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 126 | } |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 127 | |
Daniel Lezcano | 28203df | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 128 | static int display_show_unselection(int win, int line, bool bold) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 129 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 130 | if (mvwchgat(windata[win].pad, line, 0, -1, |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 131 | bold ? WA_BOLD: WA_NORMAL, 0, NULL) < 0) |
| 132 | return -1; |
| 133 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 134 | return display_refresh_pad(win); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 135 | } |
| 136 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 137 | void *display_get_row_data(int win) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 138 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 139 | return windata[win].rowdata[windata[win].cursor].data; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 140 | } |
| 141 | |
Daniel Lezcano | 28203df | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 142 | static int display_select(void) |
| 143 | { |
| 144 | if (windata[current_win].ops && windata[current_win].ops->select) |
| 145 | return windata[current_win].ops->select(); |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | static int display_next_panel(void) |
| 151 | { |
| 152 | size_t array_size = sizeof(windata) / sizeof(windata[0]); |
| 153 | |
| 154 | current_win++; |
| 155 | current_win %= array_size; |
| 156 | |
| 157 | return current_win; |
| 158 | } |
| 159 | |
| 160 | static int display_prev_panel(void) |
| 161 | { |
| 162 | size_t array_size = sizeof(windata) / sizeof(windata[0]); |
| 163 | |
| 164 | current_win--; |
| 165 | if (current_win < 0) |
| 166 | current_win = array_size - 1; |
| 167 | |
| 168 | return current_win; |
| 169 | } |
| 170 | |
| 171 | static int display_next_line(void) |
| 172 | { |
Daniel Lezcano | 0a8cc58 | 2011-06-21 00:57:08 +0200 | [diff] [blame^] | 173 | int maxx, maxy; |
Daniel Lezcano | 28203df | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 174 | int cursor = windata[current_win].cursor; |
| 175 | int nrdata = windata[current_win].nrdata; |
| 176 | int scrolling = windata[current_win].scrolling; |
| 177 | struct rowdata *rowdata = windata[current_win].rowdata; |
| 178 | |
Daniel Lezcano | 0a8cc58 | 2011-06-21 00:57:08 +0200 | [diff] [blame^] | 179 | getmaxyx(stdscr, maxy, maxx); |
| 180 | |
Daniel Lezcano | 28203df | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 181 | if (cursor >= nrdata) |
| 182 | return cursor; |
| 183 | |
| 184 | display_show_unselection(current_win, cursor, rowdata[cursor].attr); |
| 185 | if (cursor < nrdata - 1) { |
| 186 | if (cursor >= (maxy - 4 + scrolling)) |
| 187 | scrolling++; |
| 188 | cursor++; |
| 189 | } |
| 190 | |
| 191 | windata[current_win].scrolling = scrolling; |
| 192 | windata[current_win].cursor = cursor; |
| 193 | |
| 194 | return cursor; |
| 195 | } |
| 196 | |
| 197 | static int display_prev_line(void) |
| 198 | { |
| 199 | int cursor = windata[current_win].cursor; |
| 200 | int nrdata = windata[current_win].nrdata; |
| 201 | int scrolling = windata[current_win].scrolling; |
| 202 | struct rowdata *rowdata = windata[current_win].rowdata; |
| 203 | |
| 204 | if (cursor >= nrdata) |
| 205 | return cursor; |
| 206 | |
| 207 | display_show_unselection(current_win, cursor, rowdata[cursor].attr); |
| 208 | if (cursor > 0) { |
| 209 | if (cursor <= scrolling) |
| 210 | scrolling--; |
| 211 | cursor--; |
| 212 | } |
| 213 | |
| 214 | windata[current_win].scrolling = scrolling; |
| 215 | windata[current_win].cursor = cursor; |
| 216 | |
| 217 | return cursor; |
| 218 | } |
| 219 | |
| 220 | static int display_set_row_data(int win, int line, void *data, int attr) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 221 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 222 | struct rowdata *rowdata = windata[win].rowdata; |
| 223 | |
| 224 | if (line >= windata[win].nrdata) { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 225 | rowdata = realloc(rowdata, sizeof(struct rowdata) * (line + 1)); |
| 226 | if (!rowdata) |
| 227 | return -1; |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 228 | windata[win].nrdata = line + 1; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | rowdata[line].data = data; |
| 232 | rowdata[line].attr = attr; |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 233 | windata[win].rowdata = rowdata; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 234 | |
| 235 | return 0; |
| 236 | } |
| 237 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 238 | int display_reset_cursor(int win) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 239 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 240 | windata[win].nrdata = 0; |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 241 | werase(windata[win].pad); |
| 242 | return wmove(windata[win].pad, 0, 0); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 243 | } |
| 244 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 245 | int display_print_line(int win, int line, char *str, int bold, void *data) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 246 | { |
| 247 | int attr = 0; |
| 248 | |
Amit Arora | 031263a | 2010-11-09 11:12:41 +0530 | [diff] [blame] | 249 | if (bold) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 250 | attr |= WA_BOLD; |
| 251 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 252 | if (line == windata[win].cursor) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 253 | attr |= WA_STANDOUT; |
| 254 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 255 | if (display_set_row_data(win, line, data, attr)) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 256 | return -1; |
| 257 | |
| 258 | if (attr) |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 259 | wattron(windata[win].pad, attr); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 260 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 261 | wprintw(windata[win].pad, "%s\n", str); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 262 | |
| 263 | if (attr) |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 264 | wattroff(windata[win].pad, attr); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 265 | |
| 266 | return 0; |
| 267 | } |
| 268 | |
Daniel Lezcano | db14580 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 269 | static int display_keystroke(int fd, void *data) |
Daniel Lezcano | 176e69d | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 270 | { |
Daniel Lezcano | 176e69d | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 271 | int keystroke = getch(); |
| 272 | |
| 273 | switch (keystroke) { |
| 274 | |
| 275 | case KEY_RIGHT: |
| 276 | case '\t': |
| 277 | display_next_panel(); |
| 278 | break; |
| 279 | |
| 280 | case KEY_LEFT: |
| 281 | case KEY_BTAB: |
| 282 | display_prev_panel(); |
| 283 | break; |
| 284 | |
| 285 | case KEY_DOWN: |
| 286 | display_next_line(); |
| 287 | break; |
| 288 | |
| 289 | case KEY_UP: |
| 290 | display_prev_line(); |
| 291 | break; |
| 292 | |
| 293 | case '\r': |
| 294 | display_select(); |
| 295 | break; |
| 296 | |
| 297 | case EOF: |
| 298 | case 'q': |
| 299 | case 'Q': |
| 300 | return 1; |
| 301 | |
| 302 | case 'r': |
| 303 | case 'R': |
Daniel Lezcano | db14580 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 304 | /* refresh will be done after */ |
Daniel Lezcano | 176e69d | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 305 | break; |
Daniel Lezcano | db14580 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 306 | default: |
| 307 | return 0; |
Daniel Lezcano | 176e69d | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 308 | } |
| 309 | |
Daniel Lezcano | db14580 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 310 | display_refresh(current_win); |
| 311 | |
| 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | int display_init(int wdefault) |
| 316 | { |
Daniel Lezcano | 0a8cc58 | 2011-06-21 00:57:08 +0200 | [diff] [blame^] | 317 | int i, maxx, maxy; |
Daniel Lezcano | db14580 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 318 | size_t array_size = sizeof(windata) / sizeof(windata[0]); |
| 319 | |
| 320 | current_win = wdefault; |
| 321 | |
| 322 | if (mainloop_add(0, display_keystroke, NULL)) |
| 323 | return -1; |
| 324 | |
| 325 | if (!initscr()) |
| 326 | return -1; |
| 327 | |
| 328 | start_color(); |
| 329 | use_default_colors(); |
| 330 | |
| 331 | keypad(stdscr, TRUE); |
| 332 | noecho(); |
| 333 | cbreak(); |
| 334 | curs_set(0); |
| 335 | nonl(); |
| 336 | |
| 337 | if (init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK) || |
| 338 | init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED) || |
| 339 | init_pair(PT_COLOR_HEADER_BAR, COLOR_WHITE, COLOR_BLACK) || |
| 340 | init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW) || |
| 341 | init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN) || |
| 342 | init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK) || |
| 343 | init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE) || |
| 344 | init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED)) |
| 345 | return -1; |
| 346 | |
| 347 | if (atexit(display_fini)) |
| 348 | return -1; |
| 349 | |
| 350 | getmaxyx(stdscr, maxy, maxx); |
| 351 | |
| 352 | for (i = 0; i < array_size; i++) { |
| 353 | |
Daniel Lezcano | c196d43 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 354 | main_win = subwin(stdscr, maxy - 2, maxx, 1, 0); |
| 355 | if (!main_win) |
Daniel Lezcano | db14580 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 356 | return -1; |
| 357 | |
| 358 | windata[i].pad = newpad(maxrows, maxx); |
| 359 | if (!windata[i].pad) |
| 360 | return -1; |
| 361 | |
| 362 | } |
| 363 | |
| 364 | header_win = subwin(stdscr, 1, maxx, 0, 0); |
| 365 | if (!header_win) |
| 366 | return -1; |
| 367 | |
| 368 | footer_win = subwin(stdscr, 1, maxx, maxy-1, 0); |
| 369 | if (!footer_win) |
| 370 | return -1; |
| 371 | |
| 372 | if (show_header_footer(wdefault)) |
| 373 | return -1; |
| 374 | |
| 375 | return display_refresh(wdefault); |
| 376 | } |
| 377 | |
| 378 | void print_regulator_header(void) |
| 379 | { |
Daniel Lezcano | c196d43 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 380 | werase(main_win); |
| 381 | wattron(main_win, A_BOLD); |
Daniel Lezcano | c757e6d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 382 | mvwprintw(main_win, 0, 0, "Name"); |
| 383 | mvwprintw(main_win, 0, 12, "Status"); |
| 384 | mvwprintw(main_win, 0, 24, "State"); |
| 385 | mvwprintw(main_win, 0, 36, "Type"); |
| 386 | mvwprintw(main_win, 0, 48, "Users"); |
| 387 | mvwprintw(main_win, 0, 60, "Microvolts"); |
| 388 | mvwprintw(main_win, 0, 72, "Min u-volts"); |
| 389 | mvwprintw(main_win, 0, 84, "Max u-volts"); |
Daniel Lezcano | c196d43 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 390 | wattroff(main_win, A_BOLD); |
| 391 | wrefresh(main_win); |
Daniel Lezcano | db14580 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 392 | |
| 393 | show_header_footer(REGULATOR); |
| 394 | } |
| 395 | |
| 396 | void print_clock_header(void) |
| 397 | { |
Daniel Lezcano | c196d43 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 398 | werase(main_win); |
| 399 | wattron(main_win, A_BOLD); |
Daniel Lezcano | c757e6d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 400 | mvwprintw(main_win, 0, 0, "Name"); |
| 401 | mvwprintw(main_win, 0, 56, "Flags"); |
| 402 | mvwprintw(main_win, 0, 75, "Rate"); |
| 403 | mvwprintw(main_win, 0, 88, "Usecount"); |
| 404 | mvwprintw(main_win, 0, 98, "Children"); |
Daniel Lezcano | c196d43 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 405 | wattroff(main_win, A_BOLD); |
| 406 | wrefresh(main_win); |
Daniel Lezcano | db14580 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 407 | |
| 408 | show_header_footer(CLOCK); |
| 409 | } |
| 410 | |
| 411 | void print_sensor_header(void) |
| 412 | { |
Daniel Lezcano | c196d43 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 413 | werase(main_win); |
| 414 | wattron(main_win, A_BOLD); |
Daniel Lezcano | c757e6d | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 415 | mvwprintw(main_win, 0, 0, "Name"); |
| 416 | mvwprintw(main_win, 0, 36, "Value"); |
Daniel Lezcano | c196d43 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 417 | wattroff(main_win, A_BOLD); |
| 418 | wrefresh(main_win); |
Daniel Lezcano | db14580 | 2011-06-21 00:57:08 +0200 | [diff] [blame] | 419 | |
| 420 | show_header_footer(SENSOR); |
| 421 | } |
| 422 | |
| 423 | int display_register(int win, struct display_ops *ops) |
| 424 | { |
| 425 | size_t array_size = sizeof(windata) / sizeof(windata[0]); |
| 426 | |
| 427 | if (win < 0 || win >= array_size) |
| 428 | return -1; |
| 429 | |
| 430 | windata[win].ops = ops; |
| 431 | |
Daniel Lezcano | 176e69d | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 432 | return 0; |
| 433 | } |