prepare for compile time init of screens[]

This commit is contained in:
2025-08-05 14:45:43 -04:00
parent 1a90a816e5
commit 18eba940f1
2 changed files with 31 additions and 20 deletions

42
bbs.c
View File

@@ -7,8 +7,6 @@
#include "globals.h"
#include "home.h"
#define MAX_ERROR_MESSAGE_SIZE 60 /* size of error_message array */
const unsigned int GETCH_TIMEOUT = 10; /* in ms */
const char* LOCALE = "en_US.UTF-8"; /* enable unicode support, set to "ANSI_X3.4-1968" for ascii */
@@ -34,15 +32,11 @@ int main() {
timeout(GETCH_TIMEOUT); /* set timeout for getch() */
setlocale(LC_CTYPE, LOCALE); /* set locale, UTF8 support is enabled here */
unsigned int start_y = 0;
unsigned int start_x = 0;
unsigned int terminal_width;
unsigned int terminal_height;
unsigned int old_terminal_width = 0;
unsigned int old_terminal_height = 0;
// struct Screen screens[MAX_SCREENS];
enum Status status = STATUS_NEED_REFRESH; /* refresh screens[active_screen].window on first loop */
char input = ' ';
@@ -53,18 +47,32 @@ int main() {
unsigned int screen_before_error = HOME;
enum ActiveScreen active_screen = HOME;
struct Screen home = {
"home",
newwin(terminal_height, terminal_width, start_y, start_x),
draw_home
struct Screen screens[] = {
{
"home",
newwin(terminal_height, terminal_width, 0, 0),
draw_home
},
{
"error",
newwin(terminal_height, terminal_width, 0, 0),
draw_error
}
};
screens[HOME] = home;
struct Screen error = {
"error",
newwin(terminal_height, terminal_width, start_y, start_x),
draw_error
};
screens[ERROR] = error;
// struct Screen home = {
// "home",
// newwin(terminal_height, terminal_width, start_y, start_x),
// draw_home
// };
// screens[HOME] = home;
// struct Screen error = {
// "error",
// newwin(terminal_height, terminal_width, start_y, start_x),
// draw_error
// };
// screens[ERROR] = error;
/* main event loop */
while (status != STATUS_QUIT) {

View File

@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: MIT */
#define MAX_SCREENS 2 /* size of screens array */
#define MAX_ERROR_MESSAGE_SIZE 60 /* size of error_message array */
#define MAX_SCREEN_NAME_SIZE 20 /* size of the screen name array */
#ifndef GLOBALS_H /* header guard */
#define GLOBALS_H
@@ -17,11 +18,13 @@ enum ActiveScreen {
};
struct Screen {
char name[20];
char name[MAX_SCREEN_NAME_SIZE];
WINDOW *win;
void (*draw_screen)(struct Screen *, char *input); /* GETCH_TIMEOUT determines how often this is run, in ms */
};
struct Screen screens[MAX_SCREENS];
/* TODO: put this in a screens.c file and include all screens there, that way the array can be initialized at compile
* time */
extern struct Screen screens[];
#endif