nshell/src/ui.c

54 lines
1.3 KiB
C
Raw Normal View History

2021-09-01 11:04:31 +02:00
#include "ui.h"
#include "term.h"
#include <gint/display.h>
#include <stdio.h>
#include <string.h>
2021-09-01 12:41:58 +02:00
void set_statusbar(int tick_ctr, int shfit_state) {
2021-09-01 11:04:31 +02:00
// set green bar
for (int i = 0; i < UNS_TERM_COLS; i++)
tgrid_sets(0, i, C_NONE, C_GREEN, " ");
// then add actutal text
char statusbar[UNS_TERM_COLS + 1];
2021-09-01 12:41:58 +02:00
if (shfit_state)
sprintf(statusbar, "↑Aa %d", tick_ctr);
else
sprintf(statusbar, "_Aa %d", tick_ctr);
2021-09-01 11:04:31 +02:00
tgrid_sets(0, 0, C_BLACK, C_GREEN, statusbar);
}
static void center_str(int len, char buf[len], const char *s) {
const int l = strlen(s);
const int before = len / 2 - l / 2;
int i;
for (i = 0; i < before; i++)
buf[i] = ' ';
for (int j = 0; j < l; j++)
buf[i++] = s[j];
for (; i < len; i++)
buf[i] = ' ';
}
char fnkeys[6][11] = {"opt 1-", "opt 2--", "opt 3---", "opt 4----", "opt 5-----", "opt 6"};
void set_menubar(void) {
int col = 0;
for (int i = 0; i < 6; i++) {
char buf[11] = "";
center_str(10, buf, fnkeys[i]);
buf[10] = '\0';
tgrid_sets(UNS_TERM_ROWS - 1, col, C_WHITE, C_BLUE, buf);
2021-09-01 13:43:55 +02:00
// print spacers
if (i < 6 - 1)
tgrid_sets(UNS_TERM_ROWS - 1, col + 10, C_WHITE, C_BLACK, " ");
2021-09-01 11:04:31 +02:00
col += 10 + 1;
}
}