Created
January 2, 2021 18:00
-
-
Save insom/5a7ae102136bb08471cc819b633754fd to your computer and use it in GitHub Desktop.
experiments with vt100 scrolling
This file contains 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
/* vim:ts=2:sw=2:expandtab | |
*/ | |
#include <ctype.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <termios.h> | |
#include <unistd.h> | |
struct termios orig_termios; | |
void die(const char *s) { | |
perror(s); | |
exit(1); | |
} | |
// from Kilo | |
void disableRawMode() { | |
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios) == -1) | |
die("tcsetattr"); | |
} | |
// from Kilo | |
void enableRawMode() { | |
if (tcgetattr(STDIN_FILENO, &orig_termios) == -1) | |
die("tcgetattr"); | |
atexit(disableRawMode); | |
struct termios raw = orig_termios; | |
raw.c_iflag &= ~(/*BRKINT |*/ ICRNL | INPCK | ISTRIP | IXON); | |
raw.c_oflag &= ~(OPOST); | |
raw.c_cflag |= (CS8); | |
raw.c_lflag &= ~(ECHO | ICANON | IEXTEN /*| ISIG*/); | |
raw.c_cc[VMIN] = 0; | |
raw.c_cc[VTIME] = 1; | |
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw) == -1) | |
die("tcsetattr"); | |
} | |
void statusline(void) { | |
printf("-- STATUS LINE --\r\eE"); | |
fflush(stdout); | |
} | |
// featuring learning from http://ascii-table.com/ansi-escape-sequences-vt-100.php | |
void main(int c, char **v) { | |
char cc; | |
enableRawMode(); | |
atexit(disableRawMode); | |
printf("\e[2J"); | |
for(int i = 0; i < 16; i++) | |
printf("\eE"); | |
fflush(stdout); | |
statusline(); | |
for(int q = 0;; q++) { | |
usleep(500000); | |
char *newcontent = "NEW CONTENT IS HERE! %d"; | |
printf("\eE"); // new blank | |
printf("\eM"); // old blank | |
printf("\eM"); // old status line | |
printf("\e[K"); // blank it | |
printf(newcontent, q); | |
printf("\r\eE"); // start of status area | |
statusline(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment