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 | |
| 193 | |
Daniel Lezcano | 833b63a | 2011-03-26 22:06:00 +0100 | [diff] [blame] | 194 | void show_regulator_info(struct regulator_info *reg_info, int nr_reg, int verbose) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 195 | { |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 196 | int i, count = 1; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 197 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 198 | (void)verbose; |
Amit Arora | bf50db9 | 2010-10-07 14:09:05 +0530 | [diff] [blame] | 199 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 200 | werase(regulator_win); |
| 201 | wattron(regulator_win, A_BOLD); |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 202 | print(regulator_win, 0, 0, "Name"); |
| 203 | print(regulator_win, 12, 0, "Status"); |
| 204 | print(regulator_win, 24, 0, "State"); |
| 205 | print(regulator_win, 36, 0, "Type"); |
| 206 | print(regulator_win, 48, 0, "Users"); |
| 207 | print(regulator_win, 60, 0, "Microvolts"); |
| 208 | print(regulator_win, 72, 0, "Min u-volts"); |
| 209 | print(regulator_win, 84, 0, "Max u-volts"); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 210 | wattroff(regulator_win, A_BOLD); |
| 211 | |
Daniel Lezcano | 833b63a | 2011-03-26 22:06:00 +0100 | [diff] [blame] | 212 | for (i = 0; i < nr_reg; i++) { |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 213 | int col = 0; |
| 214 | |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 215 | if ((i + 2) > (maxy-2)) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 216 | break; |
| 217 | |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 218 | if (reg_info[i].num_users > 0) |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 219 | wattron(regulator_win, WA_BOLD); |
| 220 | else |
| 221 | wattroff(regulator_win, WA_BOLD); |
| 222 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 223 | print(regulator_win, col, count, "%s", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 224 | reg_info[i].name); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 225 | col += 12; |
| 226 | print(regulator_win, col, count, "%s", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 227 | reg_info[i].status); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 228 | col += 12; |
| 229 | print(regulator_win, col, count, "%s", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 230 | reg_info[i].state); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 231 | col += 12; |
| 232 | print(regulator_win, col, count, "%s", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 233 | reg_info[i].type); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 234 | col += 12; |
| 235 | print(regulator_win, col, count, "%d", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 236 | reg_info[i].num_users); |
Amit Arora | 6a943ec | 2010-10-07 11:49:25 +0530 | [diff] [blame] | 237 | col += 12; |
| 238 | print(regulator_win, col, count, "%d", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 239 | reg_info[i].microvolts); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 240 | col += 12; |
| 241 | print(regulator_win, col, count, "%d", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 242 | reg_info[i].min_microvolts); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 243 | col += 12; |
| 244 | print(regulator_win, col, count, "%d", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 245 | reg_info[i].max_microvolts); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 246 | |
| 247 | count++; |
| 248 | } |
| 249 | wrefresh(regulator_win); |
| 250 | } |
| 251 | |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 252 | |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 253 | void print_clock_header(void) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 254 | { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 255 | werase(clock_labels); |
| 256 | wattron(clock_labels, A_BOLD); |
| 257 | print(clock_labels, 0, 0, "Name"); |
| 258 | print(clock_labels, 56, 0, "Flags"); |
| 259 | print(clock_labels, 75, 0, "Rate"); |
| 260 | print(clock_labels, 88, 0, "Usecount"); |
| 261 | print(clock_labels, 98, 0, "Children"); |
| 262 | wattroff(clock_labels, A_BOLD); |
| 263 | wrefresh(clock_labels); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | void print_sensor_header(void) |
| 267 | { |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 268 | werase(sensor_win); |
| 269 | wattron(sensor_win, A_BOLD); |
| 270 | print(sensor_win, 0, 0, "Name"); |
| 271 | print(sensor_win, 36, 0, "Temperature"); |
| 272 | wattroff(sensor_win, A_BOLD); |
| 273 | wattron(sensor_win, A_BLINK); |
| 274 | print(sensor_win, 0, 1, "Currently Sensor information available" |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 275 | " only in Dump mode!"); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 276 | wattroff(sensor_win, A_BLINK); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 277 | wrefresh(sensor_win); |
| 278 | } |
| 279 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 280 | int display_refresh_pad(int win) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 281 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 282 | return prefresh(clock_pad, windata[win].scrolling, |
| 283 | 0, 2, 0, maxy - 2, maxx); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 284 | } |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 285 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 286 | static int inline display_clock_un_select(int win, int line, |
| 287 | bool highlight, bool bold) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 288 | { |
| 289 | if (mvwchgat(clock_pad, line, 0, -1, |
| 290 | highlight ? WA_STANDOUT : |
| 291 | bold ? WA_BOLD: WA_NORMAL, 0, NULL) < 0) |
| 292 | return -1; |
| 293 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 294 | return display_refresh_pad(win); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 295 | } |
| 296 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 297 | int display_select(int win, int line) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 298 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 299 | return display_clock_un_select(win, line, true, false); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 300 | } |
| 301 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 302 | int display_unselect(int win, int line, bool bold) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 303 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 304 | return display_clock_un_select(win, line, false, bold); |
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 | void *display_get_row_data(int win) |
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 windata[win].rowdata[windata[win].cursor].data; |
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_set_row_data(int win, int line, void *data, int attr) |
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 | struct rowdata *rowdata = windata[win].rowdata; |
| 315 | |
| 316 | if (line >= windata[win].nrdata) { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 317 | rowdata = realloc(rowdata, sizeof(struct rowdata) * (line + 1)); |
| 318 | if (!rowdata) |
| 319 | return -1; |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 320 | windata[win].nrdata = line + 1; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | rowdata[line].data = data; |
| 324 | rowdata[line].attr = attr; |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 325 | windata[win].rowdata = rowdata; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 326 | |
| 327 | return 0; |
| 328 | } |
| 329 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 330 | int display_reset_cursor(win) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 331 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 332 | windata[win].nrdata = 0; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 333 | werase(clock_pad); |
| 334 | return wmove(clock_pad, 0, 0); |
| 335 | } |
| 336 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 337 | 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] | 338 | { |
| 339 | int attr = 0; |
| 340 | |
Amit Arora | 031263a | 2010-11-09 11:12:41 +0530 | [diff] [blame] | 341 | if (bold) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 342 | attr |= WA_BOLD; |
| 343 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 344 | if (line == windata[win].cursor) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 345 | attr |= WA_STANDOUT; |
| 346 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 347 | if (display_set_row_data(win, line, data, attr)) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 348 | return -1; |
| 349 | |
| 350 | if (attr) |
| 351 | wattron(clock_pad, attr); |
| 352 | |
| 353 | wprintw(clock_pad, "%s\n", str); |
| 354 | |
| 355 | if (attr) |
| 356 | wattroff(clock_pad, attr); |
| 357 | |
| 358 | return 0; |
| 359 | } |
| 360 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 361 | int display_next_line(int win) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 362 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 363 | int cursor = windata[win].cursor; |
| 364 | int nrdata = windata[win].nrdata; |
| 365 | int scrolling = windata[win].scrolling; |
| 366 | struct rowdata *rowdata = windata[win].rowdata; |
| 367 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 368 | if (cursor >= nrdata) |
| 369 | return cursor; |
| 370 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 371 | display_unselect(win, cursor, rowdata[cursor].attr); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 372 | if (cursor < nrdata - 1) { |
| 373 | if (cursor >= (maxy - 4 + scrolling)) |
| 374 | scrolling++; |
| 375 | cursor++; |
| 376 | } |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 377 | display_select(win, cursor); |
| 378 | |
| 379 | windata[win].scrolling = scrolling; |
| 380 | windata[win].cursor = cursor; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 381 | |
| 382 | return cursor; |
| 383 | } |
| 384 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 385 | int display_prev_line(int win) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 386 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 387 | int cursor = windata[win].cursor; |
| 388 | int nrdata = windata[win].nrdata; |
| 389 | int scrolling = windata[win].scrolling; |
| 390 | struct rowdata *rowdata = windata[win].rowdata; |
| 391 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 392 | if (cursor >= nrdata) |
| 393 | return cursor; |
| 394 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 395 | display_unselect(win, cursor, rowdata[cursor].attr); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 396 | if (cursor > 0) { |
| 397 | if (cursor <= scrolling) |
| 398 | scrolling--; |
| 399 | cursor--; |
| 400 | } |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 401 | display_select(win, cursor); |
| 402 | |
| 403 | windata[win].scrolling = scrolling; |
| 404 | windata[win].cursor = cursor; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 405 | |
| 406 | return cursor; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 407 | } |