Created
November 14, 2019 11:23
-
-
Save LatinSuD/3ec900f487e1f098e570a41b5253d3d3 to your computer and use it in GitHub Desktop.
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
#include <stdio.h> | |
#define is_num(x) ( x>='0' && x<='9' ) | |
int main(int argc, char **argv) { | |
int a1,a2,a3,a4,a5,a6,a7,a8,a9; | |
int filas; | |
int maxfilas=10; | |
setbuf(stdout,0); | |
do { | |
a1=a2; | |
a2=a3; | |
a3=a4; | |
a4=a5; | |
a5=a6; | |
a6=a7; | |
a7=a8; | |
a8=a9; | |
a9=getchar(); | |
// Contar las filas, ej: "ESC[12;5H" son 12 filas | |
if (a1=='\x1b' && a2=='[' && | |
a3>='0' && a3<='9' && | |
a4>='0' && a4<='9' && | |
a5==';' && | |
( | |
is_num(a6) && a7=='H' | |
|| | |
( | |
is_num(a6) && is_num(a7) && a8=='H' | |
) | |
|| | |
( | |
is_num(a6) && is_num(a7) && is_num(a8) && a9=='H' | |
) | |
) | |
) { | |
filas = (a3-'0')*10 + a4-'0'; | |
if (filas > maxfilas) | |
maxfilas=filas; | |
} | |
// Interceptar ?47h al principio para que no borre la pantalla | |
if (a4=='\x1b' && a5=='[' && a6=='?' && a7=='4' && a8=='7' && a9=='h') { | |
a7='l'; | |
} | |
// Interceptar 2J (limpiar pantalla al final) | |
if (a7=='[' && a8=='2' && a9=='J') { | |
// Convertirlo en: 2C H 15B. (2C=nada, H=ir al inicio, 15B=bajar 15) | |
printf("C\x1b[H\x1b["); | |
printf("%d",maxfilas+1); | |
printf("B"); | |
return 0; | |
} | |
if (a9 != EOF) | |
putchar(a9); | |
} while (a9 != EOF); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment