Last active
May 26, 2025 14:01
-
-
Save reagent/9743630 to your computer and use it in GitHub Desktop.
Curses + C Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
demo | |
*.swp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ncurses.h> | |
#include <unistd.h> | |
#define DELAY 35000 | |
int main(int argc, char *argv[]) { | |
int x = 0, | |
y = 0; | |
int max_x = 0, | |
max_y = 0; | |
int next_x = 0; | |
int direction = 1; | |
initscr(); | |
noecho(); | |
curs_set(FALSE); | |
getmaxyx(stdscr, max_y, max_x); | |
x = max_x / 2; | |
y = max_y / 2; | |
while (1) { | |
getmaxyx(stdscr, max_y, max_x); | |
y = max_y / 2; | |
clear(); | |
mvprintw(y, x, "o"); | |
refresh(); | |
usleep(DELAY); | |
next_x = x + direction; | |
if (next_x >= max_x || next_x < 0) { | |
direction*= -1; | |
} else { | |
x+= direction; | |
} | |
} | |
endwin(); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CFLAGS=-Wall | |
LDFLAGS=-lncurses | |
all: demo | |
clean: | |
rm -rf demo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
change it