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 | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 52 | struct rowdata *rowdata; |
| 53 | char *name; |
| 54 | int nrdata; |
| 55 | int scrolling; |
| 56 | int cursor; |
| 57 | }; |
| 58 | |
| 59 | struct windata windata[TOTAL_FEATURE_WINS] = { |
| 60 | { .name = "Clocks" }, |
| 61 | { .name = "Regulators" }, |
| 62 | { .name = "Sensors" }, |
| 63 | }; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 64 | |
Daniel Lezcano | 3abd8b1 | 2011-03-26 22:06:15 +0100 | [diff] [blame] | 65 | static void display_fini(void) |
| 66 | { |
| 67 | endwin(); |
| 68 | } |
| 69 | |
Daniel Lezcano | 7b3da50 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 70 | static int show_header_footer(int win) |
| 71 | { |
| 72 | int i; |
| 73 | int curr_pointer = 0; |
| 74 | |
| 75 | wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 76 | wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 77 | werase(header_win); |
| 78 | |
| 79 | print(header_win, curr_pointer, 0, "PowerDebug %s", VERSION); |
| 80 | curr_pointer += 20; |
| 81 | |
| 82 | for (i = 0; i < TOTAL_FEATURE_WINS; i++) { |
| 83 | if (win == i) |
| 84 | wattron(header_win, A_REVERSE); |
| 85 | else |
| 86 | wattroff(header_win, A_REVERSE); |
| 87 | |
| 88 | print(header_win, curr_pointer, 0, " %s ", windata[i].name); |
| 89 | curr_pointer += strlen(windata[i].name) + 2; |
| 90 | } |
| 91 | wrefresh(header_win); |
| 92 | werase(footer_win); |
| 93 | |
| 94 | wattron(footer_win, A_REVERSE); |
| 95 | print(footer_win, 0, 0, "%s", footer_label); |
| 96 | wattroff(footer_win, A_REVERSE); |
| 97 | wrefresh(footer_win); |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | int display_init(int wdefault) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 103 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 104 | int i; |
| 105 | size_t array_size = sizeof(windata) / sizeof(windata[0]); |
| 106 | |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 107 | current_win = wdefault; |
| 108 | |
Daniel Lezcano | ca17a72 | 2011-03-26 22:06:16 +0100 | [diff] [blame] | 109 | if (!initscr()) |
| 110 | return -1; |
| 111 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 112 | start_color(); |
Daniel Lezcano | ca17a72 | 2011-03-26 22:06:16 +0100 | [diff] [blame] | 113 | use_default_colors(); |
| 114 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 115 | keypad(stdscr, TRUE); |
| 116 | noecho(); |
| 117 | cbreak(); |
| 118 | curs_set(0); |
| 119 | nonl(); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 120 | |
Daniel Lezcano | ca17a72 | 2011-03-26 22:06:16 +0100 | [diff] [blame] | 121 | if (init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK) || |
| 122 | init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED) || |
| 123 | init_pair(PT_COLOR_HEADER_BAR, COLOR_WHITE, COLOR_BLACK) || |
| 124 | init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW) || |
| 125 | init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN) || |
| 126 | init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK) || |
| 127 | init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE) || |
| 128 | init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED)) |
| 129 | return -1; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 130 | |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 131 | if (atexit(display_fini)) |
| 132 | return -1; |
| 133 | |
| 134 | getmaxyx(stdscr, maxy, maxx); |
| 135 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 136 | for (i = 0; i < array_size; i++) { |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 137 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 138 | windata[i].win = subwin(stdscr, maxy - 2, maxx, 1, 0); |
| 139 | if (!windata[i].win) |
| 140 | return -1; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 141 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 142 | windata[i].pad = newpad(maxrows, maxx); |
| 143 | if (!windata[i].pad) |
| 144 | return -1; |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 145 | |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 146 | } |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 147 | |
| 148 | header_win = subwin(stdscr, 1, maxx, 0, 0); |
| 149 | if (!header_win) |
| 150 | return -1; |
| 151 | |
| 152 | footer_win = subwin(stdscr, 1, maxx, maxy-1, 0); |
| 153 | if (!footer_win) |
| 154 | return -1; |
| 155 | |
Daniel Lezcano | 7b3da50 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 156 | return show_header_footer(wdefault); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 157 | } |
| 158 | |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 159 | void print_regulator_header(void) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 160 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 161 | WINDOW *regulator_win = windata[REGULATOR].win; |
| 162 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 163 | werase(regulator_win); |
| 164 | wattron(regulator_win, A_BOLD); |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 165 | print(regulator_win, 0, 0, "Name"); |
| 166 | print(regulator_win, 12, 0, "Status"); |
| 167 | print(regulator_win, 24, 0, "State"); |
| 168 | print(regulator_win, 36, 0, "Type"); |
| 169 | print(regulator_win, 48, 0, "Users"); |
| 170 | print(regulator_win, 60, 0, "Microvolts"); |
| 171 | print(regulator_win, 72, 0, "Min u-volts"); |
| 172 | print(regulator_win, 84, 0, "Max u-volts"); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 173 | wattroff(regulator_win, A_BOLD); |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 174 | wrefresh(regulator_win); |
Daniel Lezcano | 7b3da50 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 175 | |
| 176 | show_header_footer(REGULATOR); |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | void print_clock_header(void) |
| 180 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 181 | WINDOW *clock_win = windata[CLOCK].win; |
| 182 | |
| 183 | werase(clock_win); |
| 184 | wattron(clock_win, A_BOLD); |
| 185 | print(clock_win, 0, 0, "Name"); |
| 186 | print(clock_win, 56, 0, "Flags"); |
| 187 | print(clock_win, 75, 0, "Rate"); |
| 188 | print(clock_win, 88, 0, "Usecount"); |
| 189 | print(clock_win, 98, 0, "Children"); |
| 190 | wattroff(clock_win, A_BOLD); |
| 191 | wrefresh(clock_win); |
Daniel Lezcano | 7b3da50 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 192 | |
| 193 | show_header_footer(CLOCK); |
Daniel Lezcano | b25be4a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 194 | } |
| 195 | |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 196 | void print_sensor_header(void) |
| 197 | { |
Daniel Lezcano | f665682 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 198 | WINDOW *sensor_win = windata[SENSOR].win; |
| 199 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 200 | werase(sensor_win); |
| 201 | wattron(sensor_win, A_BOLD); |
| 202 | print(sensor_win, 0, 0, "Name"); |
Daniel Lezcano | 2e9df76 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 203 | print(sensor_win, 36, 0, "Value"); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 204 | wattroff(sensor_win, A_BOLD); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 205 | wrefresh(sensor_win); |
Daniel Lezcano | 7b3da50 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 206 | |
| 207 | show_header_footer(SENSOR); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 208 | } |
| 209 | |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 210 | int display_next_panel(void) |
| 211 | { |
| 212 | current_win++; |
| 213 | current_win %= TOTAL_FEATURE_WINS; |
| 214 | |
| 215 | return current_win; |
| 216 | } |
| 217 | |
| 218 | int display_prev_panel(void) |
| 219 | { |
| 220 | current_win--; |
| 221 | if (current_win < 0) |
| 222 | current_win = TOTAL_FEATURE_WINS - 1; |
| 223 | |
| 224 | return current_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 | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 308 | int display_next_line(void) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 309 | { |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 310 | int cursor = windata[current_win].cursor; |
| 311 | int nrdata = windata[current_win].nrdata; |
| 312 | int scrolling = windata[current_win].scrolling; |
| 313 | struct rowdata *rowdata = windata[current_win].rowdata; |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 314 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 315 | if (cursor >= nrdata) |
| 316 | return cursor; |
| 317 | |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 318 | display_unselect(current_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 | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 324 | display_select(current_win, cursor); |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 325 | |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 326 | windata[current_win].scrolling = scrolling; |
| 327 | windata[current_win].cursor = cursor; |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 328 | |
| 329 | return cursor; |
| 330 | } |
| 331 | |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 332 | int display_prev_line(void) |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 333 | { |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 334 | int cursor = windata[current_win].cursor; |
| 335 | int nrdata = windata[current_win].nrdata; |
| 336 | int scrolling = windata[current_win].scrolling; |
| 337 | struct rowdata *rowdata = windata[current_win].rowdata; |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 338 | |
Daniel Lezcano | 2adc48d | 2011-06-08 23:30:01 +0200 | [diff] [blame] | 339 | if (cursor >= nrdata) |
| 340 | return cursor; |
| 341 | |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 342 | display_unselect(current_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 | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 348 | display_select(current_win, cursor); |
Daniel Lezcano | b3e6e81 | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 349 | |
Daniel Lezcano | d96731a | 2011-06-15 15:45:12 +0200 | [diff] [blame] | 350 | windata[current_win].scrolling = scrolling; |
| 351 | windata[current_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 | } |