forked from amberisvibin/bbs
each screen now has it's own file, and there is a framework for adding more
This commit is contained in:
34
bbs.c
34
bbs.c
@@ -5,17 +5,13 @@
|
|||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "home.h"
|
#include "screens.h"
|
||||||
|
|
||||||
const unsigned int GETCH_TIMEOUT = 10; /* in ms */
|
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 */
|
const char* LOCALE = "en_US.UTF-8"; /* enable unicode support, set to "ANSI_X3.4-1968" for ascii */
|
||||||
|
|
||||||
char error_message[MAX_ERROR_MESSAGE_SIZE];
|
char error_message[MAX_ERROR_MESSAGE_SIZE];
|
||||||
|
|
||||||
static void draw_error(struct Screen *screen, __attribute__((unused)) char *input) {
|
|
||||||
mvwprintw(screen->win, 1, 2, "%s", error_message);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void draw_screen (struct Screen *screen, char *input) {
|
static void draw_screen (struct Screen *screen, char *input) {
|
||||||
screen->draw_screen(screen, input);
|
screen->draw_screen(screen, input);
|
||||||
box(screen->win, 0, 0);
|
box(screen->win, 0, 0);
|
||||||
@@ -48,31 +44,9 @@ int main() {
|
|||||||
|
|
||||||
enum ActiveScreen active_screen = HOME;
|
enum ActiveScreen active_screen = HOME;
|
||||||
|
|
||||||
struct Screen screens[] = {
|
/* could be it's own init func within the screen's file. */
|
||||||
{
|
screens[HOME].win = newwin(terminal_height, terminal_width, 0, 0);
|
||||||
"home",
|
screens[ERROR].win = newwin(terminal_height, terminal_width, 0, 0);
|
||||||
newwin(terminal_height, terminal_width, 0, 0),
|
|
||||||
draw_home
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"error",
|
|
||||||
newwin(terminal_height, terminal_width, 0, 0),
|
|
||||||
draw_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 */
|
/* main event loop */
|
||||||
while (status != STATUS_QUIT) {
|
while (status != STATUS_QUIT) {
|
||||||
|
8
error.c
Normal file
8
error.c
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
|
||||||
|
#include <curses.h>
|
||||||
|
#include "screens.h"
|
||||||
|
|
||||||
|
void draw_error(struct Screen *screen, __attribute__((unused)) char *input) {
|
||||||
|
mvwprintw(screen->win, 1, 2, "%s", error_message);
|
||||||
|
}
|
10
error.h
Normal file
10
error.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
|
||||||
|
#ifndef ERROR_H /* header guard */
|
||||||
|
#define ERROR_H
|
||||||
|
|
||||||
|
#include "screens.h"
|
||||||
|
|
||||||
|
void draw_error(struct Screen *screen, char *input);
|
||||||
|
|
||||||
|
#endif
|
22
globals.h
22
globals.h
@@ -1,11 +1,21 @@
|
|||||||
/* SPDX-License-Identifier: MIT */
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
|
||||||
#define MAX_ERROR_MESSAGE_SIZE 60 /* size of error_message array */
|
|
||||||
#define MAX_SCREEN_NAME_SIZE 20 /* size of the screen name array */
|
#define MAX_SCREEN_NAME_SIZE 20 /* size of the screen name array */
|
||||||
|
#define MAX_ERROR_MESSAGE_SIZE 60 /* size of error_message array */
|
||||||
|
|
||||||
#ifndef GLOBALS_H /* header guard */
|
#ifndef GLOBALS_H /* header guard */
|
||||||
#define GLOBALS_H
|
#define GLOBALS_H
|
||||||
|
|
||||||
|
#include <curses.h>
|
||||||
|
|
||||||
|
extern char error_message[];
|
||||||
|
|
||||||
|
struct Screen {
|
||||||
|
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 */
|
||||||
|
};
|
||||||
|
|
||||||
enum Status {
|
enum Status {
|
||||||
STATUS_QUIT,
|
STATUS_QUIT,
|
||||||
STATUS_WAITING,
|
STATUS_WAITING,
|
||||||
@@ -17,14 +27,4 @@ enum ActiveScreen {
|
|||||||
ERROR
|
ERROR
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Screen {
|
|
||||||
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 */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* 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
|
#endif
|
||||||
|
2
home.c
2
home.c
@@ -1,7 +1,7 @@
|
|||||||
/* SPDX-License-Identifier: MIT */
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include "globals.h"
|
#include "screens.h"
|
||||||
|
|
||||||
void draw_home(struct Screen *screen, char *input) {
|
void draw_home(struct Screen *screen, char *input) {
|
||||||
static char* banner = ""
|
static char* banner = ""
|
||||||
|
2
home.h
2
home.h
@@ -3,7 +3,7 @@
|
|||||||
#ifndef HOME_H /* header guard */
|
#ifndef HOME_H /* header guard */
|
||||||
#define HOME_H
|
#define HOME_H
|
||||||
|
|
||||||
#include "globals.h"
|
#include "screens.h"
|
||||||
|
|
||||||
void draw_home(struct Screen *screen, char *input);
|
void draw_home(struct Screen *screen, char *input);
|
||||||
|
|
||||||
|
19
screens.c
Normal file
19
screens.c
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
|
||||||
|
#include "globals.h"
|
||||||
|
#include "home.h"
|
||||||
|
#include "error.h"
|
||||||
|
|
||||||
|
/* NOTE: this should be compile time */
|
||||||
|
struct Screen screens[] = {
|
||||||
|
{
|
||||||
|
"home",
|
||||||
|
NULL,
|
||||||
|
draw_home
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"error",
|
||||||
|
NULL,
|
||||||
|
draw_error
|
||||||
|
}
|
||||||
|
};
|
Reference in New Issue
Block a user