Skip to content

Instantly share code, notes, and snippets.

@bitnetwork
Created February 3, 2017 19:31
Show Gist options
  • Save bitnetwork/5a22d33ba4178578f24646bc8a441611 to your computer and use it in GitHub Desktop.
Save bitnetwork/5a22d33ba4178578f24646bc8a441611 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
#include <stdio.h>
#include <stdlib.h>
#include <curses.h>
#include <term.h>
static char term_buffer[2048];
void initTerminalData (void) {
char *termtype = getenv("TERM");
int success;
success = tgetent(term_buffer, termtype);
if (termtype == NULL || success <= 0) {
printf("Error! $TERM isn't defined.");
}
}
void redraw (void) {
lines = tgetnum("li");
for (int i=0; i<lines; i++) {
printf("\r\e[A");
}
}
void reflash (void) {
lines = tgetnum("li");
columns = tgetnum("co");
for (int i=0; i<lines; i++) {
printf("\r\e[A");
for (int j=0; j<columns; j++) {
printf(" ");
}
}
}
int main () {
initTerminalData();
reflash();
printf ("Got: Lines: %d, Columns: %d\n", tgetnum("li"), tgetnum("co"));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment