Compare commits
3 Commits
77829db002
...
1a90a816e5
Author | SHA1 | Date | |
---|---|---|---|
1a90a816e5 | |||
7d8f3d70b3 | |||
f48ed22602 |
19
Makefile
19
Makefile
@@ -1,18 +1,17 @@
|
|||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
CC=gcc
|
CC=gcc
|
||||||
CFLAGS=-std=c99 -pedantic -Wall -Wextra
|
CFLAGS=-std=c99 -pedantic -Wall -Wextra -O2 -ggdb
|
||||||
LIBS=-lncursesw
|
LIBS=-lncursesw
|
||||||
EXECUTABLE=bbs
|
EXECUTABLE=bbs
|
||||||
|
|
||||||
.PHONY: all
|
# .PHONY: all
|
||||||
all: make
|
# all: make
|
||||||
|
|
||||||
|
make: bbs
|
||||||
|
|
||||||
make:
|
bbs: bbs.c home.c home.h globals.h
|
||||||
$(CC) $(CFLAGS) $(LIBS) bbs.c -o $(EXECUTABLE)
|
$(CC) $(CFLAGS) $(LIBS) bbs.c home.c -o $(EXECUTABLE)
|
||||||
|
|
||||||
.PHONY: execute
|
run: bbs
|
||||||
execute:
|
|
||||||
./$(EXECUTABLE)
|
./$(EXECUTABLE)
|
||||||
|
|
||||||
.PHONY: run
|
|
||||||
run: make execute
|
|
||||||
|
57
bbs.c
57
bbs.c
@@ -1,56 +1,29 @@
|
|||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
|
||||||
|
#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 unsigned int GETCH_TIMEOUT = 10; /* in ms */
|
||||||
const unsigned int MAX_SCREENS = 2; /* size of screens array */
|
|
||||||
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 errorMessage[60];
|
char error_message[MAX_ERROR_MESSAGE_SIZE];
|
||||||
|
|
||||||
enum Status {
|
|
||||||
STATUS_QUIT,
|
|
||||||
STATUS_WAITING,
|
|
||||||
STATUS_NEED_REFRESH
|
|
||||||
};
|
|
||||||
|
|
||||||
enum ActiveScreen {
|
|
||||||
HOME,
|
|
||||||
ERROR
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Screen {
|
|
||||||
char name[20];
|
|
||||||
WINDOW *win;
|
|
||||||
void (*draw_screen)(struct Screen *, char *input); /* this is run about every 10ms */
|
|
||||||
};
|
|
||||||
|
|
||||||
static void draw_home(struct Screen *screen, char *input) {
|
|
||||||
static char* banner = ""
|
|
||||||
" _ _ _ \n"
|
|
||||||
" | | | | | | \n"
|
|
||||||
" __ _ _ __ ___ | |__ ___ _ __ ___ _ __ | | __ _ ___ ___ _ __ ___| |_ \n"
|
|
||||||
" / _` | '_ ` _ \\| '_ \\ / _ \\ '__/ __| '_ \\| |/ _` |/ __/ _ \\ | '_ \\ / _ \\ __|\n"
|
|
||||||
" | (_| | | | | | | |_) | __/ | \\__ \\ |_) | | (_| | (_| __/_| | | | __/ |_ \n"
|
|
||||||
" \\__,_|_| |_| |_|_.__/ \\___|_| |___/ .__/|_|\\__,_|\\___\\___(_)_| |_|\\___|\\__|\n"
|
|
||||||
" | | \n"
|
|
||||||
" |_| \n";
|
|
||||||
|
|
||||||
mvwprintw(screen->win, 1, 2, "Thank you for visiting:");
|
|
||||||
mvwprintw(screen->win, 2, 1, "%s", banner);
|
|
||||||
mvwprintw(screen->win, 10, 1, "Your current input is: %s", input);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void draw_error(struct Screen *screen, __attribute__((unused)) char *input) {
|
static void draw_error(struct Screen *screen, __attribute__((unused)) char *input) {
|
||||||
mvwprintw(screen->win, 1, 2, "%s", errorMessage);
|
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);
|
||||||
// wattron(screen->win, A_STANDOUT);
|
/* wattron(screen->win, A_STANDOUT); */
|
||||||
mvwprintw(screen->win, 0, 1, " %s ", screen->name);
|
mvwprintw(screen->win, 0, 1, " %s ", screen->name);
|
||||||
// wattroff(screen->win, A_STANDOUT);
|
/* wattroff(screen->win, A_STANDOUT); */
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@@ -68,12 +41,12 @@ int main() {
|
|||||||
unsigned int old_terminal_width = 0;
|
unsigned int old_terminal_width = 0;
|
||||||
unsigned int old_terminal_height = 0;
|
unsigned int old_terminal_height = 0;
|
||||||
|
|
||||||
struct Screen screens[MAX_SCREENS];
|
// struct Screen screens[MAX_SCREENS];
|
||||||
|
|
||||||
enum Status status = STATUS_NEED_REFRESH; /* refresh screens[active_screen].window on first loop */
|
enum Status status = STATUS_NEED_REFRESH; /* refresh screens[active_screen].window on first loop */
|
||||||
char input = ' ';
|
char input = ' ';
|
||||||
|
|
||||||
strcpy(errorMessage, "");
|
strcpy(error_message, "");
|
||||||
|
|
||||||
getmaxyx(stdscr, terminal_height, terminal_width);
|
getmaxyx(stdscr, terminal_height, terminal_width);
|
||||||
|
|
||||||
@@ -116,7 +89,7 @@ int main() {
|
|||||||
|
|
||||||
if (terminal_width < 80 || terminal_height < 24) {
|
if (terminal_width < 80 || terminal_height < 24) {
|
||||||
if (active_screen != ERROR) {
|
if (active_screen != ERROR) {
|
||||||
strcpy(errorMessage, "This program expects at least 80 rows by 24 columns.");
|
strcpy(error_message, "This program expects at least 80 rows by 24 columns.");
|
||||||
screen_before_error = active_screen;
|
screen_before_error = active_screen;
|
||||||
};
|
};
|
||||||
active_screen = ERROR;
|
active_screen = ERROR;
|
||||||
@@ -136,7 +109,7 @@ int main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* clean up */
|
/* clean up */
|
||||||
delwin(screens[active_screen].win);
|
delwin(screens[active_screen].win); /* TODO: delete all windows in screens[] */
|
||||||
nocbreak();
|
nocbreak();
|
||||||
endwin(); /* ends curses mode */
|
endwin(); /* ends curses mode */
|
||||||
curs_set(1);
|
curs_set(1);
|
||||||
|
27
globals.h
Normal file
27
globals.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
|
||||||
|
#define MAX_SCREENS 2 /* size of screens array */
|
||||||
|
|
||||||
|
#ifndef GLOBALS_H /* header guard */
|
||||||
|
#define GLOBALS_H
|
||||||
|
|
||||||
|
enum Status {
|
||||||
|
STATUS_QUIT,
|
||||||
|
STATUS_WAITING,
|
||||||
|
STATUS_NEED_REFRESH
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ActiveScreen {
|
||||||
|
HOME,
|
||||||
|
ERROR
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Screen {
|
||||||
|
char name[20];
|
||||||
|
WINDOW *win;
|
||||||
|
void (*draw_screen)(struct Screen *, char *input); /* GETCH_TIMEOUT determines how often this is run, in ms */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Screen screens[MAX_SCREENS];
|
||||||
|
|
||||||
|
#endif
|
20
home.c
Normal file
20
home.c
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
|
||||||
|
#include <curses.h>
|
||||||
|
#include "globals.h"
|
||||||
|
|
||||||
|
void draw_home(struct Screen *screen, char *input) {
|
||||||
|
static char* banner = ""
|
||||||
|
" _ _ _ \n"
|
||||||
|
" | | | | | | \n"
|
||||||
|
" __ _ _ __ ___ | |__ ___ _ __ ___ _ __ | | __ _ ___ ___ _ __ ___| |_ \n"
|
||||||
|
" / _` | '_ ` _ \\| '_ \\ / _ \\ '__/ __| '_ \\| |/ _` |/ __/ _ \\ | '_ \\ / _ \\ __|\n"
|
||||||
|
" | (_| | | | | | | |_) | __/ | \\__ \\ |_) | | (_| | (_| __/_| | | | __/ |_ \n"
|
||||||
|
" \\__,_|_| |_| |_|_.__/ \\___|_| |___/ .__/|_|\\__,_|\\___\\___(_)_| |_|\\___|\\__|\n"
|
||||||
|
" | | \n"
|
||||||
|
" |_| \n";
|
||||||
|
|
||||||
|
mvwprintw(screen->win, 1, 2, "Thank you for visiting:");
|
||||||
|
mvwprintw(screen->win, 2, 1, "%s", banner);
|
||||||
|
mvwprintw(screen->win, 10, 1, "Your current input is: %s", input);
|
||||||
|
}
|
Reference in New Issue
Block a user