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