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; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 34 | static WINDOW *footer_win; |
| 35 | |
| 36 | int maxx, maxy; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 37 | |
| 38 | /* Number of lines in the virtual window */ |
| 39 | static const int maxrows = 1024; |
| 40 | |
Daniel Lezcano | 68500e8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 41 | static char footer_items[NUM_FOOTER_ITEMS][64]; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 42 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 43 | struct rowdata { |
| 44 | int attr; |
| 45 | void *data; |
| 46 | }; |
| 47 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 48 | struct windata { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 49 | WINDOW *win; |
| 50 | WINDOW *pad; |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 51 | struct rowdata *rowdata; |
| 52 | char *name; |
| 53 | int nrdata; |
| 54 | int scrolling; |
| 55 | int cursor; |
| 56 | }; |
| 57 | |
| 58 | struct windata windata[TOTAL_FEATURE_WINS] = { |
| 59 | { .name = "Clocks" }, |
| 60 | { .name = "Regulators" }, |
| 61 | { .name = "Sensors" }, |
| 62 | }; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 63 | |
Daniel Lezcano | 3abd8b1 | 2011-03-26 22:06:15 +0100 | [diff] [blame] | 64 | static void display_fini(void) |
| 65 | { |
| 66 | endwin(); |
| 67 | } |
| 68 | |
Daniel Lezcano | ca17a72 | 2011-03-26 22:06:16 +0100 | [diff] [blame] | 69 | int display_init(void) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 70 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 71 | int i; |
| 72 | size_t array_size = sizeof(windata) / sizeof(windata[0]); |
| 73 | |
Daniel Lezcano | ca17a72 | 2011-03-26 22:06:16 +0100 | [diff] [blame] | 74 | if (!initscr()) |
| 75 | return -1; |
| 76 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 77 | start_color(); |
Daniel Lezcano | ca17a72 | 2011-03-26 22:06:16 +0100 | [diff] [blame] | 78 | use_default_colors(); |
| 79 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 80 | keypad(stdscr, TRUE); |
| 81 | noecho(); |
| 82 | cbreak(); |
| 83 | curs_set(0); |
| 84 | nonl(); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 85 | |
Daniel Lezcano | ca17a72 | 2011-03-26 22:06:16 +0100 | [diff] [blame] | 86 | if (init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK) || |
| 87 | init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED) || |
| 88 | init_pair(PT_COLOR_HEADER_BAR, COLOR_WHITE, COLOR_BLACK) || |
| 89 | init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW) || |
| 90 | init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN) || |
| 91 | init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK) || |
| 92 | init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE) || |
| 93 | init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED)) |
| 94 | return -1; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 95 | |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 96 | if (atexit(display_fini)) |
| 97 | return -1; |
| 98 | |
| 99 | getmaxyx(stdscr, maxy, maxx); |
| 100 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 101 | for (i = 0; i < array_size; i++) { |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 102 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 103 | windata[i].win = subwin(stdscr, maxy - 2, maxx, 1, 0); |
| 104 | if (!windata[i].win) |
| 105 | return -1; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 106 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 107 | windata[i].pad = newpad(maxrows, maxx); |
| 108 | if (!windata[i].pad) |
| 109 | return -1; |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 110 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 111 | } |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 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 | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 142 | void create_selectedwindow(int win) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 143 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 144 | wrefresh(windata[win].win); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 145 | } |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 146 | |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 147 | void show_header(int selectedwindow) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 148 | { |
| 149 | int i, j = 0; |
Amit Kucheria | 0a4d019 | 2011-01-12 04:54:37 +0530 | [diff] [blame] | 150 | int curr_pointer = 0; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 151 | |
| 152 | wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 153 | wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 154 | werase(header_win); |
| 155 | |
Amit Kucheria | 0a4d019 | 2011-01-12 04:54:37 +0530 | [diff] [blame] | 156 | print(header_win, curr_pointer, 0, "PowerDebug %s", VERSION); |
| 157 | curr_pointer += 20; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 158 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 159 | for (i = 0; i < TOTAL_FEATURE_WINS; i++) { |
| 160 | if (selectedwindow == i) |
| 161 | wattron(header_win, A_REVERSE); |
| 162 | else |
| 163 | wattroff(header_win, A_REVERSE); |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 164 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 165 | print(header_win, curr_pointer, 0, " %s ", windata[i].name); |
| 166 | curr_pointer += strlen(windata[i].name) + 2; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 167 | } |
| 168 | wrefresh(header_win); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 169 | werase(footer_win); |
| 170 | |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 171 | for (i = 0; i < NUM_FOOTER_ITEMS; i++) { |
| 172 | if (strlen(footer_items[i]) == 0) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 173 | continue; |
| 174 | wattron(footer_win, A_REVERSE); |
| 175 | print(footer_win, j, 0, "%s", footer_items[i]); |
| 176 | wattroff(footer_win, A_REVERSE); |
| 177 | j+= strlen(footer_items[i])+1; |
| 178 | } |
| 179 | wrefresh(footer_win); |
| 180 | } |
| 181 | |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 182 | void print_regulator_header(void) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 183 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 184 | WINDOW *regulator_win = windata[REGULATOR].win; |
| 185 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 186 | werase(regulator_win); |
| 187 | wattron(regulator_win, A_BOLD); |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 188 | print(regulator_win, 0, 0, "Name"); |
| 189 | print(regulator_win, 12, 0, "Status"); |
| 190 | print(regulator_win, 24, 0, "State"); |
| 191 | print(regulator_win, 36, 0, "Type"); |
| 192 | print(regulator_win, 48, 0, "Users"); |
| 193 | print(regulator_win, 60, 0, "Microvolts"); |
| 194 | print(regulator_win, 72, 0, "Min u-volts"); |
| 195 | print(regulator_win, 84, 0, "Max u-volts"); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 196 | wattroff(regulator_win, A_BOLD); |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 197 | wrefresh(regulator_win); |
| 198 | } |
| 199 | |
| 200 | void print_clock_header(void) |
| 201 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 202 | WINDOW *clock_win = windata[CLOCK].win; |
| 203 | |
| 204 | werase(clock_win); |
| 205 | wattron(clock_win, A_BOLD); |
| 206 | print(clock_win, 0, 0, "Name"); |
| 207 | print(clock_win, 56, 0, "Flags"); |
| 208 | print(clock_win, 75, 0, "Rate"); |
| 209 | print(clock_win, 88, 0, "Usecount"); |
| 210 | print(clock_win, 98, 0, "Children"); |
| 211 | wattroff(clock_win, A_BOLD); |
| 212 | wrefresh(clock_win); |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 213 | } |
| 214 | |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 215 | void print_sensor_header(void) |
| 216 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 217 | WINDOW *sensor_win = windata[SENSOR].win; |
| 218 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 219 | werase(sensor_win); |
| 220 | wattron(sensor_win, A_BOLD); |
| 221 | print(sensor_win, 0, 0, "Name"); |
Daniel Lezcano | 2e9df76 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 222 | print(sensor_win, 36, 0, "Value"); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 223 | wattroff(sensor_win, A_BOLD); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 224 | wrefresh(sensor_win); |
| 225 | } |
| 226 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 227 | int display_refresh_pad(int win) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 228 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 229 | return prefresh(windata[win].pad, windata[win].scrolling, |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 230 | 0, 2, 0, maxy - 2, maxx); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 231 | } |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 232 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 233 | static int inline display_un_select(int win, int line, |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 234 | bool highlight, bool bold) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 235 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 236 | if (mvwchgat(windata[win].pad, line, 0, -1, |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 237 | highlight ? WA_STANDOUT : |
| 238 | bold ? WA_BOLD: WA_NORMAL, 0, NULL) < 0) |
| 239 | return -1; |
| 240 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 241 | return display_refresh_pad(win); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 242 | } |
| 243 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 244 | int display_select(int win, int line) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 245 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 246 | return display_un_select(win, line, true, false); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 247 | } |
| 248 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 249 | int display_unselect(int win, int line, bool bold) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 250 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 251 | return display_un_select(win, line, false, bold); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 252 | } |
| 253 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 254 | void *display_get_row_data(int win) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 255 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 256 | return windata[win].rowdata[windata[win].cursor].data; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 257 | } |
| 258 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 259 | 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] | 260 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 261 | struct rowdata *rowdata = windata[win].rowdata; |
| 262 | |
| 263 | if (line >= windata[win].nrdata) { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 264 | rowdata = realloc(rowdata, sizeof(struct rowdata) * (line + 1)); |
| 265 | if (!rowdata) |
| 266 | return -1; |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 267 | windata[win].nrdata = line + 1; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | rowdata[line].data = data; |
| 271 | rowdata[line].attr = attr; |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 272 | windata[win].rowdata = rowdata; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 273 | |
| 274 | return 0; |
| 275 | } |
| 276 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 277 | int display_reset_cursor(int win) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 278 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 279 | windata[win].nrdata = 0; |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 280 | werase(windata[win].pad); |
| 281 | return wmove(windata[win].pad, 0, 0); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 282 | } |
| 283 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 284 | 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] | 285 | { |
| 286 | int attr = 0; |
| 287 | |
Amit Arora | 031263a | 2010-11-09 11:12:41 +0530 | [diff] [blame] | 288 | if (bold) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 289 | attr |= WA_BOLD; |
| 290 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 291 | if (line == windata[win].cursor) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 292 | attr |= WA_STANDOUT; |
| 293 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 294 | if (display_set_row_data(win, line, data, attr)) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 295 | return -1; |
| 296 | |
| 297 | if (attr) |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 298 | wattron(windata[win].pad, attr); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 299 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 300 | wprintw(windata[win].pad, "%s\n", str); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 301 | |
| 302 | if (attr) |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 303 | wattroff(windata[win].pad, attr); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 304 | |
| 305 | return 0; |
| 306 | } |
| 307 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 308 | int display_next_line(int win) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 309 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 310 | int cursor = windata[win].cursor; |
| 311 | int nrdata = windata[win].nrdata; |
| 312 | int scrolling = windata[win].scrolling; |
| 313 | struct rowdata *rowdata = windata[win].rowdata; |
| 314 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 315 | if (cursor >= nrdata) |
| 316 | return cursor; |
| 317 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 318 | display_unselect(win, cursor, rowdata[cursor].attr); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 319 | if (cursor < nrdata - 1) { |
| 320 | if (cursor >= (maxy - 4 + scrolling)) |
| 321 | scrolling++; |
| 322 | cursor++; |
| 323 | } |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 324 | display_select(win, cursor); |
| 325 | |
| 326 | windata[win].scrolling = scrolling; |
| 327 | windata[win].cursor = cursor; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 328 | |
| 329 | return cursor; |
| 330 | } |
| 331 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 332 | int display_prev_line(int win) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 333 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 334 | int cursor = windata[win].cursor; |
| 335 | int nrdata = windata[win].nrdata; |
| 336 | int scrolling = windata[win].scrolling; |
| 337 | struct rowdata *rowdata = windata[win].rowdata; |
| 338 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 339 | if (cursor >= nrdata) |
| 340 | return cursor; |
| 341 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 342 | display_unselect(win, cursor, rowdata[cursor].attr); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 343 | if (cursor > 0) { |
| 344 | if (cursor <= scrolling) |
| 345 | scrolling--; |
| 346 | cursor--; |
| 347 | } |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 348 | display_select(win, cursor); |
| 349 | |
| 350 | windata[win].scrolling = scrolling; |
| 351 | windata[win].cursor = cursor; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 352 | |
| 353 | return cursor; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 354 | } |