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 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 16 | #include "powerdebug.h" |
Amit Arora | 1755278 | 2010-12-02 12:23:14 +0530 | [diff] [blame] | 17 | #include "regulator.h" |
Amit Arora | ed3e565 | 2010-10-27 12:02:53 +0530 | [diff] [blame] | 18 | #include "display.h" |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 19 | |
| 20 | #define print(w, x, y, fmt, args...) do { mvwprintw(w, y, x, fmt, ##args); } while (0) |
| 21 | #define NUM_FOOTER_ITEMS 5 |
| 22 | |
Daniel Lezcano | eeb1376 | 2011-03-26 22:06:17 +0100 | [diff] [blame] | 23 | enum { PT_COLOR_DEFAULT = 1, |
| 24 | PT_COLOR_HEADER_BAR, |
| 25 | PT_COLOR_ERROR, |
| 26 | PT_COLOR_RED, |
| 27 | PT_COLOR_YELLOW, |
| 28 | PT_COLOR_GREEN, |
| 29 | PT_COLOR_BRIGHT, |
| 30 | PT_COLOR_BLUE, |
| 31 | }; |
| 32 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 33 | static WINDOW *header_win; |
| 34 | static WINDOW *regulator_win; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 35 | static WINDOW *clock_pad; |
| 36 | static WINDOW *clock_labels; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 37 | static WINDOW *sensor_win; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 38 | static WINDOW *footer_win; |
| 39 | |
| 40 | int maxx, maxy; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 41 | |
| 42 | /* Number of lines in the virtual window */ |
| 43 | static const int maxrows = 1024; |
| 44 | |
Daniel Lezcano | 68500e8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 45 | static char footer_items[NUM_FOOTER_ITEMS][64]; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 46 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 47 | struct rowdata { |
| 48 | int attr; |
| 49 | void *data; |
| 50 | }; |
| 51 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 52 | struct windata { |
| 53 | struct rowdata *rowdata; |
| 54 | char *name; |
| 55 | int nrdata; |
| 56 | int scrolling; |
| 57 | int cursor; |
| 58 | }; |
| 59 | |
| 60 | struct windata windata[TOTAL_FEATURE_WINS] = { |
| 61 | { .name = "Clocks" }, |
| 62 | { .name = "Regulators" }, |
| 63 | { .name = "Sensors" }, |
| 64 | }; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 65 | |
Daniel Lezcano | 3abd8b1 | 2011-03-26 22:06:15 +0100 | [diff] [blame] | 66 | static void display_fini(void) |
| 67 | { |
| 68 | endwin(); |
| 69 | } |
| 70 | |
Daniel Lezcano | ca17a72 | 2011-03-26 22:06:16 +0100 | [diff] [blame] | 71 | int display_init(void) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 72 | { |
Daniel Lezcano | ca17a72 | 2011-03-26 22:06:16 +0100 | [diff] [blame] | 73 | if (!initscr()) |
| 74 | return -1; |
| 75 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 76 | start_color(); |
Daniel Lezcano | ca17a72 | 2011-03-26 22:06:16 +0100 | [diff] [blame] | 77 | use_default_colors(); |
| 78 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 79 | keypad(stdscr, TRUE); |
| 80 | noecho(); |
| 81 | cbreak(); |
| 82 | curs_set(0); |
| 83 | nonl(); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 84 | |
Daniel Lezcano | ca17a72 | 2011-03-26 22:06:16 +0100 | [diff] [blame] | 85 | if (init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK) || |
| 86 | init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED) || |
| 87 | init_pair(PT_COLOR_HEADER_BAR, COLOR_WHITE, COLOR_BLACK) || |
| 88 | init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW) || |
| 89 | init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN) || |
| 90 | init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK) || |
| 91 | init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE) || |
| 92 | init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED)) |
| 93 | return -1; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 94 | |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 95 | if (atexit(display_fini)) |
| 96 | return -1; |
| 97 | |
| 98 | getmaxyx(stdscr, maxy, maxx); |
| 99 | |
| 100 | regulator_win = subwin(stdscr, maxy - 2, maxx, 1, 0); |
| 101 | if (!regulator_win) |
| 102 | return -1; |
| 103 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 104 | clock_labels = subwin(stdscr, maxy - 2, maxx, 1, 0); |
| 105 | if (!clock_labels) |
| 106 | return -1; |
| 107 | |
| 108 | clock_pad = newpad(maxrows, maxx); |
| 109 | if (!clock_pad) |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 110 | return -1; |
| 111 | |
| 112 | sensor_win = subwin(stdscr, maxy - 2, maxx, 1, 0); |
| 113 | if (!sensor_win) |
| 114 | return -1; |
| 115 | |
| 116 | header_win = subwin(stdscr, 1, maxx, 0, 0); |
| 117 | if (!header_win) |
| 118 | return -1; |
| 119 | |
| 120 | footer_win = subwin(stdscr, 1, maxx, maxy-1, 0); |
| 121 | if (!footer_win) |
| 122 | return -1; |
| 123 | |
| 124 | return 0; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 125 | } |
| 126 | |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 127 | void create_windows(int selectedwindow) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 128 | { |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 129 | strcpy(footer_items[0], " Q (Quit) "); |
| 130 | strcpy(footer_items[1], " R (Refresh) "); |
| 131 | |
Amit Arora | 83ae6cb | 2010-12-02 12:22:19 +0530 | [diff] [blame] | 132 | if (selectedwindow == CLOCK) |
| 133 | strcpy(footer_items[2], " Other Keys: 'Left', 'Right', 'Up', 'Down', 'enter', " |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 134 | " '/', 'Esc' "); |
Amit Arora | 83ae6cb | 2010-12-02 12:22:19 +0530 | [diff] [blame] | 135 | else |
| 136 | strcpy(footer_items[2], " Other Keys: 'Left', 'Right' "); |
| 137 | |
| 138 | strcpy(footer_items[3], ""); |
| 139 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 140 | werase(stdscr); |
| 141 | refresh(); |
| 142 | |
| 143 | } |
| 144 | |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 145 | void create_selectedwindow(int selectedwindow) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 146 | { |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 147 | switch (selectedwindow) { |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 148 | case REGULATOR: |
| 149 | wrefresh(regulator_win); |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 150 | break; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 151 | |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 152 | case SENSOR: |
| 153 | wrefresh(sensor_win); |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 154 | break; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 155 | } |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 156 | } |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 157 | |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 158 | void show_header(int selectedwindow) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 159 | { |
| 160 | int i, j = 0; |
Amit Kucheria | 0a4d019 | 2011-01-12 04:54:37 +0530 | [diff] [blame] | 161 | int curr_pointer = 0; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 162 | |
| 163 | wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 164 | wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 165 | werase(header_win); |
| 166 | |
Amit Kucheria | 0a4d019 | 2011-01-12 04:54:37 +0530 | [diff] [blame] | 167 | print(header_win, curr_pointer, 0, "PowerDebug %s", VERSION); |
| 168 | curr_pointer += 20; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 169 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 170 | for (i = 0; i < TOTAL_FEATURE_WINS; i++) { |
| 171 | if (selectedwindow == i) |
| 172 | wattron(header_win, A_REVERSE); |
| 173 | else |
| 174 | wattroff(header_win, A_REVERSE); |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 175 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 176 | print(header_win, curr_pointer, 0, " %s ", windata[i].name); |
| 177 | curr_pointer += strlen(windata[i].name) + 2; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 178 | } |
| 179 | wrefresh(header_win); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 180 | werase(footer_win); |
| 181 | |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 182 | for (i = 0; i < NUM_FOOTER_ITEMS; i++) { |
| 183 | if (strlen(footer_items[i]) == 0) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 184 | continue; |
| 185 | wattron(footer_win, A_REVERSE); |
| 186 | print(footer_win, j, 0, "%s", footer_items[i]); |
| 187 | wattroff(footer_win, A_REVERSE); |
| 188 | j+= strlen(footer_items[i])+1; |
| 189 | } |
| 190 | wrefresh(footer_win); |
| 191 | } |
| 192 | |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 193 | void print_regulator_header(void) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 194 | { |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 195 | werase(regulator_win); |
| 196 | wattron(regulator_win, A_BOLD); |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 197 | print(regulator_win, 0, 0, "Name"); |
| 198 | print(regulator_win, 12, 0, "Status"); |
| 199 | print(regulator_win, 24, 0, "State"); |
| 200 | print(regulator_win, 36, 0, "Type"); |
| 201 | print(regulator_win, 48, 0, "Users"); |
| 202 | print(regulator_win, 60, 0, "Microvolts"); |
| 203 | print(regulator_win, 72, 0, "Min u-volts"); |
| 204 | print(regulator_win, 84, 0, "Max u-volts"); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 205 | wattroff(regulator_win, A_BOLD); |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 206 | wrefresh(regulator_win); |
| 207 | } |
| 208 | |
| 209 | void print_clock_header(void) |
| 210 | { |
| 211 | werase(clock_labels); |
| 212 | wattron(clock_labels, A_BOLD); |
| 213 | print(clock_labels, 0, 0, "Name"); |
| 214 | print(clock_labels, 56, 0, "Flags"); |
| 215 | print(clock_labels, 75, 0, "Rate"); |
| 216 | print(clock_labels, 88, 0, "Usecount"); |
| 217 | print(clock_labels, 98, 0, "Children"); |
| 218 | wattroff(clock_labels, A_BOLD); |
| 219 | wrefresh(clock_labels); |
| 220 | } |
| 221 | |
| 222 | #if 0 |
| 223 | void show_regulator_info(struct regulator_info *reg_info, int nr_reg, int verbose) |
| 224 | { |
| 225 | int i, count = 1; |
| 226 | |
| 227 | print_regulator_header(); |
| 228 | |
| 229 | wrefresh(regulator_win); |
| 230 | |
| 231 | return; |
| 232 | |
| 233 | (void)verbose; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 234 | |
Daniel Lezcano | 833b63a | 2011-03-26 22:06:00 +0100 | [diff] [blame] | 235 | for (i = 0; i < nr_reg; i++) { |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 236 | int col = 0; |
| 237 | |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 238 | if ((i + 2) > (maxy-2)) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 239 | break; |
| 240 | |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 241 | if (reg_info[i].num_users > 0) |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 242 | wattron(regulator_win, WA_BOLD); |
| 243 | else |
| 244 | wattroff(regulator_win, WA_BOLD); |
| 245 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 246 | print(regulator_win, col, count, "%s", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 247 | reg_info[i].name); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 248 | col += 12; |
| 249 | print(regulator_win, col, count, "%s", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 250 | reg_info[i].status); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 251 | col += 12; |
| 252 | print(regulator_win, col, count, "%s", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 253 | reg_info[i].state); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 254 | col += 12; |
| 255 | print(regulator_win, col, count, "%s", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 256 | reg_info[i].type); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 257 | col += 12; |
| 258 | print(regulator_win, col, count, "%d", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 259 | reg_info[i].num_users); |
Amit Arora | 6a943ec | 2010-10-07 11:49:25 +0530 | [diff] [blame] | 260 | col += 12; |
| 261 | print(regulator_win, col, count, "%d", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 262 | reg_info[i].microvolts); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 263 | col += 12; |
| 264 | print(regulator_win, col, count, "%d", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 265 | reg_info[i].min_microvolts); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 266 | col += 12; |
| 267 | print(regulator_win, col, count, "%d", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 268 | reg_info[i].max_microvolts); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 269 | |
| 270 | count++; |
| 271 | } |
| 272 | wrefresh(regulator_win); |
| 273 | } |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 274 | #endif |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 275 | |
| 276 | void print_sensor_header(void) |
| 277 | { |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 278 | werase(sensor_win); |
| 279 | wattron(sensor_win, A_BOLD); |
| 280 | print(sensor_win, 0, 0, "Name"); |
| 281 | print(sensor_win, 36, 0, "Temperature"); |
| 282 | wattroff(sensor_win, A_BOLD); |
| 283 | wattron(sensor_win, A_BLINK); |
| 284 | print(sensor_win, 0, 1, "Currently Sensor information available" |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 285 | " only in Dump mode!"); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 286 | wattroff(sensor_win, A_BLINK); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 287 | wrefresh(sensor_win); |
| 288 | } |
| 289 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 290 | int display_refresh_pad(int win) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 291 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 292 | return prefresh(clock_pad, windata[win].scrolling, |
| 293 | 0, 2, 0, maxy - 2, maxx); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 294 | } |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 295 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 296 | static int inline display_clock_un_select(int win, int line, |
| 297 | bool highlight, bool bold) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 298 | { |
| 299 | if (mvwchgat(clock_pad, line, 0, -1, |
| 300 | highlight ? WA_STANDOUT : |
| 301 | bold ? WA_BOLD: WA_NORMAL, 0, NULL) < 0) |
| 302 | return -1; |
| 303 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 304 | return display_refresh_pad(win); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 305 | } |
| 306 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 307 | int display_select(int win, int line) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 308 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 309 | return display_clock_un_select(win, line, true, false); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 310 | } |
| 311 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 312 | int display_unselect(int win, int line, bool bold) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 313 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 314 | return display_clock_un_select(win, line, false, bold); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 315 | } |
| 316 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 317 | void *display_get_row_data(int win) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 318 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 319 | return windata[win].rowdata[windata[win].cursor].data; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 320 | } |
| 321 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 322 | 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] | 323 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 324 | struct rowdata *rowdata = windata[win].rowdata; |
| 325 | |
| 326 | if (line >= windata[win].nrdata) { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 327 | rowdata = realloc(rowdata, sizeof(struct rowdata) * (line + 1)); |
| 328 | if (!rowdata) |
| 329 | return -1; |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 330 | windata[win].nrdata = line + 1; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | rowdata[line].data = data; |
| 334 | rowdata[line].attr = attr; |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 335 | windata[win].rowdata = rowdata; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 336 | |
| 337 | return 0; |
| 338 | } |
| 339 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 340 | int display_reset_cursor(win) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 341 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 342 | windata[win].nrdata = 0; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 343 | werase(clock_pad); |
| 344 | return wmove(clock_pad, 0, 0); |
| 345 | } |
| 346 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 347 | 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] | 348 | { |
| 349 | int attr = 0; |
| 350 | |
Amit Arora | 031263a | 2010-11-09 11:12:41 +0530 | [diff] [blame] | 351 | if (bold) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 352 | attr |= WA_BOLD; |
| 353 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 354 | if (line == windata[win].cursor) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 355 | attr |= WA_STANDOUT; |
| 356 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 357 | if (display_set_row_data(win, line, data, attr)) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 358 | return -1; |
| 359 | |
| 360 | if (attr) |
| 361 | wattron(clock_pad, attr); |
| 362 | |
| 363 | wprintw(clock_pad, "%s\n", str); |
| 364 | |
| 365 | if (attr) |
| 366 | wattroff(clock_pad, attr); |
| 367 | |
| 368 | return 0; |
| 369 | } |
| 370 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 371 | int display_next_line(int win) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 372 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 373 | int cursor = windata[win].cursor; |
| 374 | int nrdata = windata[win].nrdata; |
| 375 | int scrolling = windata[win].scrolling; |
| 376 | struct rowdata *rowdata = windata[win].rowdata; |
| 377 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 378 | if (cursor >= nrdata) |
| 379 | return cursor; |
| 380 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 381 | display_unselect(win, cursor, rowdata[cursor].attr); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 382 | if (cursor < nrdata - 1) { |
| 383 | if (cursor >= (maxy - 4 + scrolling)) |
| 384 | scrolling++; |
| 385 | cursor++; |
| 386 | } |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 387 | display_select(win, cursor); |
| 388 | |
| 389 | windata[win].scrolling = scrolling; |
| 390 | windata[win].cursor = cursor; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 391 | |
| 392 | return cursor; |
| 393 | } |
| 394 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 395 | int display_prev_line(int win) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 396 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 397 | int cursor = windata[win].cursor; |
| 398 | int nrdata = windata[win].nrdata; |
| 399 | int scrolling = windata[win].scrolling; |
| 400 | struct rowdata *rowdata = windata[win].rowdata; |
| 401 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 402 | if (cursor >= nrdata) |
| 403 | return cursor; |
| 404 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 405 | display_unselect(win, cursor, rowdata[cursor].attr); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 406 | if (cursor > 0) { |
| 407 | if (cursor <= scrolling) |
| 408 | scrolling--; |
| 409 | cursor--; |
| 410 | } |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 411 | display_select(win, cursor); |
| 412 | |
| 413 | windata[win].scrolling = scrolling; |
| 414 | windata[win].cursor = cursor; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 415 | |
| 416 | return cursor; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 417 | } |