replace ncurses with termios

This commit is contained in:
2025-07-08 15:36:21 -04:00
parent 8302503333
commit b4f1826464
4 changed files with 190 additions and 70 deletions

View File

@@ -1,35 +1,45 @@
// main.cpp
#include "Aquarium.h"
#include <cstdio>
#include <cstdlib>
#ifdef __OpenBSD__
#include <unistd.h>
#endif
#include <chrono>
#include <iostream>
#include <thread>
int main(int argc, char *argv[]) {
int opt;
while ((opt = getopt(argc, argv, "r:")) != -1) {
switch (opt) {
case 'r':
g_maxCells = std::atoi(optarg);
break;
default:
fprintf(stderr, "Usage: %s [-r max_cells]\n", argv[0]);
return 1;
}
}
int main() {
// Get the singleton instance
Aquarium &aquarium = Aquarium::getInstance();
aquarium.resize();
#ifdef __OpenBSD__
// Most restrictive pledge - no file access needed!
if (pledge("stdio tty", NULL) == -1) {
perror("pledge");
return 1;
}
#endif
// Initialize the aquarium display
aquarium.resize(); // Setup initial entities
// Main game loop
while (true) {
aquarium.redraw();
int ch = getch();
if (ch != ERR) {
if (ch == 'q')
break;
if (ch == 'r')
aquarium.resize();
flushinp();
usleep(100000);
// Check for user input
int input = aquarium.checkInput();
if (input == 'q' || input == 'Q' || input == 27) { // ESC key
break;
}
// Check if terminal was resized
if (aquarium.checkResize()) {
aquarium.resize();
}
// Redraw the aquarium
aquarium.redraw();
// Control frame rate (~20 FPS)
// std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
return 0;