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) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 21 | |
Daniel Lezcano | eeb1376 | 2011-03-26 22:06:17 +0100 | [diff] [blame] | 22 | enum { PT_COLOR_DEFAULT = 1, |
| 23 | PT_COLOR_HEADER_BAR, |
| 24 | PT_COLOR_ERROR, |
| 25 | PT_COLOR_RED, |
| 26 | PT_COLOR_YELLOW, |
| 27 | PT_COLOR_GREEN, |
| 28 | PT_COLOR_BRIGHT, |
| 29 | PT_COLOR_BLUE, |
| 30 | }; |
| 31 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 32 | static WINDOW *header_win; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 33 | static WINDOW *footer_win; |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 34 | static int current_win; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 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 | 7b3da50 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 41 | #define footer_label " Q (Quit) R (Refresh) Other Keys: 'Left', " \ |
| 42 | "'Right' , 'Up', 'Down', 'enter', , 'Esc'" |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 43 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 44 | struct rowdata { |
| 45 | int attr; |
| 46 | void *data; |
| 47 | }; |
| 48 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 49 | struct windata { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 50 | WINDOW *win; |
| 51 | WINDOW *pad; |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 52 | struct display_ops *ops; |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 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 | 7b3da50 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 71 | static int show_header_footer(int win) |
| 72 | { |
| 73 | int i; |
| 74 | int curr_pointer = 0; |
| 75 | |
| 76 | wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 77 | wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 78 | werase(header_win); |
| 79 | |
| 80 | print(header_win, curr_pointer, 0, "PowerDebug %s", VERSION); |
| 81 | curr_pointer += 20; |
| 82 | |
| 83 | for (i = 0; i < TOTAL_FEATURE_WINS; i++) { |
| 84 | if (win == i) |
| 85 | wattron(header_win, A_REVERSE); |
| 86 | else |
| 87 | wattroff(header_win, A_REVERSE); |
| 88 | |
| 89 | print(header_win, curr_pointer, 0, " %s ", windata[i].name); |
| 90 | curr_pointer += strlen(windata[i].name) + 2; |
| 91 | } |
| 92 | wrefresh(header_win); |
| 93 | werase(footer_win); |
| 94 | |
| 95 | wattron(footer_win, A_REVERSE); |
| 96 | print(footer_win, 0, 0, "%s", footer_label); |
| 97 | wattroff(footer_win, A_REVERSE); |
| 98 | wrefresh(footer_win); |
| 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | int display_init(int wdefault) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 104 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 105 | int i; |
| 106 | size_t array_size = sizeof(windata) / sizeof(windata[0]); |
| 107 | |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 108 | current_win = wdefault; |
| 109 | |
Daniel Lezcano | ca17a72 | 2011-03-26 22:06:16 +0100 | [diff] [blame] | 110 | if (!initscr()) |
| 111 | return -1; |
| 112 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 113 | start_color(); |
Daniel Lezcano | ca17a72 | 2011-03-26 22:06:16 +0100 | [diff] [blame] | 114 | use_default_colors(); |
| 115 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 116 | keypad(stdscr, TRUE); |
| 117 | noecho(); |
| 118 | cbreak(); |
| 119 | curs_set(0); |
| 120 | nonl(); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 121 | |
Daniel Lezcano | ca17a72 | 2011-03-26 22:06:16 +0100 | [diff] [blame] | 122 | if (init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK) || |
| 123 | init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED) || |
| 124 | init_pair(PT_COLOR_HEADER_BAR, COLOR_WHITE, COLOR_BLACK) || |
| 125 | init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW) || |
| 126 | init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN) || |
| 127 | init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK) || |
| 128 | init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE) || |
| 129 | init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED)) |
| 130 | return -1; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 131 | |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 132 | if (atexit(display_fini)) |
| 133 | return -1; |
| 134 | |
| 135 | getmaxyx(stdscr, maxy, maxx); |
| 136 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 137 | for (i = 0; i < array_size; i++) { |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 138 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 139 | windata[i].win = subwin(stdscr, maxy - 2, maxx, 1, 0); |
| 140 | if (!windata[i].win) |
| 141 | return -1; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 142 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 143 | windata[i].pad = newpad(maxrows, maxx); |
| 144 | if (!windata[i].pad) |
| 145 | return -1; |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 146 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 147 | } |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 148 | |
| 149 | header_win = subwin(stdscr, 1, maxx, 0, 0); |
| 150 | if (!header_win) |
| 151 | return -1; |
| 152 | |
| 153 | footer_win = subwin(stdscr, 1, maxx, maxy-1, 0); |
| 154 | if (!footer_win) |
| 155 | return -1; |
| 156 | |
Daniel Lezcano | 7b3da50 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 157 | return show_header_footer(wdefault); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 158 | } |
| 159 | |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 160 | void print_regulator_header(void) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 161 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 162 | WINDOW *regulator_win = windata[REGULATOR].win; |
| 163 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 164 | werase(regulator_win); |
| 165 | wattron(regulator_win, A_BOLD); |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 166 | print(regulator_win, 0, 0, "Name"); |
| 167 | print(regulator_win, 12, 0, "Status"); |
| 168 | print(regulator_win, 24, 0, "State"); |
| 169 | print(regulator_win, 36, 0, "Type"); |
| 170 | print(regulator_win, 48, 0, "Users"); |
| 171 | print(regulator_win, 60, 0, "Microvolts"); |
| 172 | print(regulator_win, 72, 0, "Min u-volts"); |
| 173 | print(regulator_win, 84, 0, "Max u-volts"); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 174 | wattroff(regulator_win, A_BOLD); |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 175 | wrefresh(regulator_win); |
Daniel Lezcano | 7b3da50 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 176 | |
| 177 | show_header_footer(REGULATOR); |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | void print_clock_header(void) |
| 181 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 182 | WINDOW *clock_win = windata[CLOCK].win; |
| 183 | |
| 184 | werase(clock_win); |
| 185 | wattron(clock_win, A_BOLD); |
| 186 | print(clock_win, 0, 0, "Name"); |
| 187 | print(clock_win, 56, 0, "Flags"); |
| 188 | print(clock_win, 75, 0, "Rate"); |
| 189 | print(clock_win, 88, 0, "Usecount"); |
| 190 | print(clock_win, 98, 0, "Children"); |
| 191 | wattroff(clock_win, A_BOLD); |
| 192 | wrefresh(clock_win); |
Daniel Lezcano | 7b3da50 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 193 | |
| 194 | show_header_footer(CLOCK); |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 195 | } |
| 196 | |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 197 | void print_sensor_header(void) |
| 198 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 199 | WINDOW *sensor_win = windata[SENSOR].win; |
| 200 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 201 | werase(sensor_win); |
| 202 | wattron(sensor_win, A_BOLD); |
| 203 | print(sensor_win, 0, 0, "Name"); |
Daniel Lezcano | 2e9df76 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 204 | print(sensor_win, 36, 0, "Value"); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 205 | wattroff(sensor_win, A_BOLD); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 206 | wrefresh(sensor_win); |
Daniel Lezcano | 7b3da50 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 207 | |
| 208 | show_header_footer(SENSOR); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 209 | } |
| 210 | |
Daniel Lezcano | b301b08 | 2011-06-15 15:45:12 +0200 | [diff] [blame^] | 211 | int display_register(int win, struct display_ops *ops) |
| 212 | { |
| 213 | if (win < 0 || win >= TOTAL_FEATURE_WINS) |
| 214 | return -1; |
| 215 | |
| 216 | windata[win].ops = ops; |
| 217 | |
| 218 | return 0; |
| 219 | } |
| 220 | |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 221 | int display_next_panel(void) |
| 222 | { |
| 223 | current_win++; |
| 224 | current_win %= TOTAL_FEATURE_WINS; |
| 225 | |
| 226 | return current_win; |
| 227 | } |
| 228 | |
| 229 | int display_prev_panel(void) |
| 230 | { |
| 231 | current_win--; |
| 232 | if (current_win < 0) |
| 233 | current_win = TOTAL_FEATURE_WINS - 1; |
| 234 | |
| 235 | return current_win; |
| 236 | } |
| 237 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 238 | int display_refresh_pad(int win) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 239 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 240 | return prefresh(windata[win].pad, windata[win].scrolling, |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 241 | 0, 2, 0, maxy - 2, maxx); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 242 | } |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 243 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 244 | static int inline display_un_select(int win, int line, |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 245 | bool highlight, bool bold) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 246 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 247 | if (mvwchgat(windata[win].pad, line, 0, -1, |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 248 | highlight ? WA_STANDOUT : |
| 249 | bold ? WA_BOLD: WA_NORMAL, 0, NULL) < 0) |
| 250 | return -1; |
| 251 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 252 | return display_refresh_pad(win); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 253 | } |
| 254 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 255 | int display_select(int win, int line) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 256 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 257 | return display_un_select(win, line, true, false); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 258 | } |
| 259 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 260 | int display_unselect(int win, int line, bool bold) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 261 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 262 | return display_un_select(win, line, false, bold); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 263 | } |
| 264 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 265 | void *display_get_row_data(int win) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 266 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 267 | return windata[win].rowdata[windata[win].cursor].data; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 268 | } |
| 269 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 270 | 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] | 271 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 272 | struct rowdata *rowdata = windata[win].rowdata; |
| 273 | |
| 274 | if (line >= windata[win].nrdata) { |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 275 | rowdata = realloc(rowdata, sizeof(struct rowdata) * (line + 1)); |
| 276 | if (!rowdata) |
| 277 | return -1; |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 278 | windata[win].nrdata = line + 1; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | rowdata[line].data = data; |
| 282 | rowdata[line].attr = attr; |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 283 | windata[win].rowdata = rowdata; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 288 | int display_reset_cursor(int win) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 289 | { |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 290 | windata[win].nrdata = 0; |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 291 | werase(windata[win].pad); |
| 292 | return wmove(windata[win].pad, 0, 0); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 293 | } |
| 294 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 295 | 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] | 296 | { |
| 297 | int attr = 0; |
| 298 | |
Amit Arora | 031263a | 2010-11-09 11:12:41 +0530 | [diff] [blame] | 299 | if (bold) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 300 | attr |= WA_BOLD; |
| 301 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 302 | if (line == windata[win].cursor) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 303 | attr |= WA_STANDOUT; |
| 304 | |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 305 | if (display_set_row_data(win, line, data, attr)) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 306 | return -1; |
| 307 | |
| 308 | if (attr) |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 309 | wattron(windata[win].pad, attr); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 310 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 311 | wprintw(windata[win].pad, "%s\n", str); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 312 | |
| 313 | if (attr) |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 314 | wattroff(windata[win].pad, attr); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 315 | |
| 316 | return 0; |
| 317 | } |
| 318 | |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 319 | int display_next_line(void) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 320 | { |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 321 | int cursor = windata[current_win].cursor; |
| 322 | int nrdata = windata[current_win].nrdata; |
| 323 | int scrolling = windata[current_win].scrolling; |
| 324 | struct rowdata *rowdata = windata[current_win].rowdata; |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 325 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 326 | if (cursor >= nrdata) |
| 327 | return cursor; |
| 328 | |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 329 | display_unselect(current_win, cursor, rowdata[cursor].attr); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 330 | if (cursor < nrdata - 1) { |
| 331 | if (cursor >= (maxy - 4 + scrolling)) |
| 332 | scrolling++; |
| 333 | cursor++; |
| 334 | } |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 335 | display_select(current_win, cursor); |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 336 | |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 337 | windata[current_win].scrolling = scrolling; |
| 338 | windata[current_win].cursor = cursor; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 339 | |
| 340 | return cursor; |
| 341 | } |
| 342 | |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 343 | int display_prev_line(void) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 344 | { |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 345 | int cursor = windata[current_win].cursor; |
| 346 | int nrdata = windata[current_win].nrdata; |
| 347 | int scrolling = windata[current_win].scrolling; |
| 348 | struct rowdata *rowdata = windata[current_win].rowdata; |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 349 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 350 | if (cursor >= nrdata) |
| 351 | return cursor; |
| 352 | |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 353 | display_unselect(current_win, cursor, rowdata[cursor].attr); |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 354 | if (cursor > 0) { |
| 355 | if (cursor <= scrolling) |
| 356 | scrolling--; |
| 357 | cursor--; |
| 358 | } |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 359 | display_select(current_win, cursor); |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 360 | |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 361 | windata[current_win].scrolling = scrolling; |
| 362 | windata[current_win].cursor = cursor; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 363 | |
| 364 | return cursor; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 365 | } |