fsctl/src/menu/info.c

156 lines
3.9 KiB
C

#include <string.h>
#include "fsctl/menu/info.h"
#include "fsctl/fugue.h"
#include "fsctl/fugue/logger.h"
#include "fsctl/utils/display.h"
#include "fsctl/utils/fs_table.h"
//---
// Public
//---
static int logs_line_start;
static int logs_line_disp;
static int logs_test;
/* info_menu_init() : init menu */
void info_menu_init(void)
{
logs_line_start = 0;
logs_line_disp = 17;
logs_test = -1;
}
/* info_menu_display() : display menu */
//TODO : logger display
void info_menu_display(void)
{
fugue_logger_t *log;
fugue_fs_t fs;
char *str;
size_t ssz;
int line_nb;
int line_curr;
fs_table_dtitle();
if (fs_table_info(&fs, NULL, NULL) != 0)
return;
log = fs._private.logger;
switch(logs_test)
{
case 1:
fugue_logger_clear(log);
logs_line_start = 0;
break;
case 2:
fugue_logger_write(log, "one line log test\n");
break;
case 3:
fugue_logger_write(log, "two lines log test\n-line 2\n");
break;
case 4:
fugue_logger_write(log, "two lines log test\n- unfinished");
break;
}
logs_test = -1;
ssz = 0;
str = NULL;
line_nb = 0;
while (fugue_logger_getline(log, &str, &ssz) == 0)
{
if (line_nb < logs_line_start) {
line_nb += 1;
continue;
}
line_curr = line_nb - logs_line_start;
if (line_curr >= logs_line_disp) {
line_nb += 1;
continue;
}
dtext_opt(
1, 15 + (line_curr * 11),
C_BLACK, C_NONE,
DTEXT_TOP, DTEXT_LEFT,
str, ssz + 1
);
line_nb += 1;
}
if (line_nb > logs_line_disp + 1)
{
int granularity = 190 / line_nb;
int y_start = granularity * logs_line_start;
int y_size = granularity * logs_line_disp;
dline(390, 1 + y_start, 390, y_start + y_size, C_BLACK);
dline(391, 1 + y_start, 391, y_start + y_size, C_BLACK);
dline(393, 0, 393, 190, C_BLACK);
}
if (line_nb == 0)
{
dtext(1, 15, C_BLACK, "No logs for now...");
}
#if 0
dprint(300, 15, C_BLACK, "start=%d", logs_line_start);
dprint(300, 26, C_BLACK, "line_nb=%d", line_nb);
int y = 0;
_printXY(0, ++y, "FS type = %s", fs.props.type);
_printXY(0, ++y, "capacity = %d", fs.props.capacity);
_printXY(0, ++y, "cluster free = %d", fs.props.cluster_free);
_printXY(0, ++y, "cluster used = %d", fs.props.cluster_used);
_printXY(0, ++y, "cluster dead = %d", fs.props.cluster_dead);
_printXY(0, ++y, "cluster errs = %d", fs.props.cluster_error);
_printXY(0, ++y, "cluster resv = %d", fs.props.cluster_resv);
_printXY(0, ++y, "cluster number = %d", fs.props.cluster_nb);
_printXY(0, ++y, "cluster number = %x", fs.props.cluster_nb);
_printXY(0, ++y, "FAT0 = %p", fs._private.fat0);
_printXY(0, ++y, "FAT1 = %p", fs._private.fat1);
_printXY(0, ++y, "FATs size = %d", fs.props.fats_size);
_printXY(0, ++y, "FAT0 size = %d", fs.props.fat0_size);
_printXY(0, ++y, "FAT1 size = %d", fs.props.fat1_size);
_printXY(0, ++y, "Root addr = %p", fs._private.root);
#endif
}
/* info_menu_keyboard() : handle keyboard */
void info_menu_keyboard(int key)
{
switch(key)
{
case KEY_LEFT:
fs_table_select_left();
break;
case KEY_RIGHT:
fs_table_select_right();
break;
case KEY_UP:
if (logs_line_start > 0)
logs_line_start -= 1;
break;
case KEY_DOWN:
logs_line_start += 1;
break;
/* test */
case KEY_1:
logs_test = 1;
break;
case KEY_2:
logs_test = 2;
break;
case KEY_3:
logs_test = 3;
break;
case KEY_4:
logs_test = 4;
break;
}
}