HTMLify
ui.c
Views: 5 | Author: abh
#include "ui.h"
#include "search.h"
#include <ncurses.h>
void ui(SearchResult sr) {
char **rs=sr.results;
int
curr_h=1, key,
rc = sr.result_count,
offset = 0, i, j, index
;
bool uirunning = rc > 0;
initscr();
curs_set(0);
start_color();
noecho();
keypad(stdscr, true);
while (uirunning) {
clear();
for (i=0; i<LINES && i<rc; i++) {
index = offset + i + 1;
if (index == curr_h)
attron(A_BOLD | A_UNDERLINE);
mvaddnstr(i, 0, rs[index], COLS);
if (index == curr_h)
attroff(A_BOLD | A_UNDERLINE);
}
refresh();
key = getch();
switch (key) {
case KEY_UP:
if (curr_h > 1)
curr_h--;
if (curr_h < offset)
offset--;
break;
case KEY_DOWN:
if (curr_h < rc - 1)
curr_h++;
if (curr_h > offset + LINES)
offset++;
break;
case 27:
uirunning = false;
break;
}
}
endwin();
}