coreinfo: make the CBFS list scrollable

This enables viewing more than ~20 files in the file list on the left.
Arrows are added to indicate that more items are available off-screen.
This mimics what was done in pci_module.

Change-Id: Idd1363e1abe98ba51c795879db061cc54808da8e
Signed-off-by: Ben Gardner <gardner.ben@gmail.com>
Reviewed-on: https://review.coreboot.org/14546
Tested-by: build bot (Jenkins)
Reviewed-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Martin Roth <martinroth@google.com>
This commit is contained in:
Ben Gardner 2016-04-29 12:45:43 -05:00 committed by Patrick Georgi
parent 1190e9cf42
commit d770bad317
1 changed files with 27 additions and 6 deletions

View File

@ -18,6 +18,8 @@
#if IS_ENABLED(CONFIG_MODULE_CBFS) #if IS_ENABLED(CONFIG_MODULE_CBFS)
#define FILES_VISIBLE 19
#define HEADER_MAGIC 0x4F524243 #define HEADER_MAGIC 0x4F524243
#define HEADER_ADDR 0xfffffffc #define HEADER_ADDR 0xfffffffc
#define LARCHIVE_MAGIC 0x455649484352414cLL /* "LARCHIVE" */ #define LARCHIVE_MAGIC 0x455649484352414cLL /* "LARCHIVE" */
@ -53,7 +55,7 @@ struct cbfile {
char filename[0]; char filename[0];
} __attribute__ ((packed)); } __attribute__ ((packed));
static int filecount = 0, selected = 0; static int filecount = 0, selected = 0, start_row = 0;
static char **filenames; static char **filenames;
static struct cbheader *header = NULL; static struct cbheader *header = NULL;
@ -120,7 +122,7 @@ static int cbfs_module_init(void)
static int cbfs_module_redraw(WINDOW * win) static int cbfs_module_redraw(WINDOW * win)
{ {
struct cbfile *f; struct cbfile *f;
int i, row = 2; int i, row, frow;
print_module_title(win, "CBFS Listing"); print_module_title(win, "CBFS Listing");
@ -134,7 +136,11 @@ static int cbfs_module_redraw(WINDOW * win)
mvwaddch(win, i, 30, ACS_VLINE); mvwaddch(win, i, 30, ACS_VLINE);
/* Draw the names down the left side. */ /* Draw the names down the left side. */
for (i = 0; i < filecount; i++) { for (frow = 0; frow < FILES_VISIBLE; frow++) {
row = 2 + frow;
i = start_row + frow;
if (i >= filecount)
break;
if (i == selected) if (i == selected)
wattrset(win, COLOR_PAIR(3) | A_BOLD); wattrset(win, COLOR_PAIR(3) | A_BOLD);
else else
@ -142,11 +148,20 @@ static int cbfs_module_redraw(WINDOW * win)
if (strlen(filenames[i]) == 0) { if (strlen(filenames[i]) == 0) {
if (findfile(filenames[i])->type == COMPONENT_NULL) if (findfile(filenames[i])->type == COMPONENT_NULL)
mvwprintw(win, 2 + i, 1, "<free space>"); mvwprintw(win, row, 1, "<free space>");
else else
mvwprintw(win, 2 + i, 1, "<unnamed>"); mvwprintw(win, row, 1, "<unnamed>");
} else { } else {
mvwprintw(win, 2 + i, 1, "%.25s", filenames[i]); mvwprintw(win, row, 1, "%.25s", filenames[i]);
}
/* show scroll arrows */
if (frow == 0 && start_row > 0) {
wattrset(win, COLOR_PAIR(2));
mvwaddch(win, row, 28, ACS_UARROW);
}
if (frow == FILES_VISIBLE - 1 && i != filecount - 1) {
wattrset(win, COLOR_PAIR(2));
mvwaddch(win, row, 28, ACS_DARROW);
} }
} }
@ -158,6 +173,8 @@ static int cbfs_module_redraw(WINDOW * win)
wattrset(win, COLOR_PAIR(2)); wattrset(win, COLOR_PAIR(2));
/* Draw the file information */
row = 2;
/* mvwprintw(win, row++, 32, "Offset: 0x%x", f->offset); *//* FIXME */ /* mvwprintw(win, row++, 32, "Offset: 0x%x", f->offset); *//* FIXME */
mvwprintw(win, row, 32, "Type: "); mvwprintw(win, row, 32, "Type: ");
switch (ntohl(f->type)) { switch (ntohl(f->type)) {
@ -212,12 +229,16 @@ static int cbfs_module_handle(int key)
case KEY_DOWN: case KEY_DOWN:
if (selected + 1 < filecount) { if (selected + 1 < filecount) {
selected++; selected++;
if (selected >= start_row + FILES_VISIBLE - 1)
start_row = selected - (FILES_VISIBLE - 1);
ret = 1; ret = 1;
} }
break; break;
case KEY_UP: case KEY_UP:
if (selected > 0) { if (selected > 0) {
selected--; selected--;
if (selected < start_row)
start_row = selected;
ret = 1; ret = 1;
} }
break; break;