Last active
May 15, 2017 10:15
-
-
Save LatinSuD/4b64e877af325d0b83938d23b8574e0b to your computer and use it in GitHub Desktop.
Filter MTR output to prevent it from clearing screen after finishing (tested on Cygwin). It works by messing with the ANSI codes
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
/* | |
MTR is an enhanced traceroute tool for Linux and friends | |
Needs: | |
Cygwin (tested with 32 bit version, 2017-05-10). | |
MTR built from https://github.com/traviscross/mtr | |
Simple compiling: | |
gcc -o procesarmtr.exe procesarmtr.c | |
Invoke mtr using: | |
real-mtr -b "$@" | procesarmtr.exe | cat | |
(where real-mtr is the path to the actual mtr binary) | |
*/ | |
#include <stdio.h> | |
int main(int argc, char **argv) { | |
int a1,a2,a3,a4,a5,a6,a7; | |
int filas; | |
int maxfilas=10; | |
setbuf(stdout,0); | |
do { | |
a1=a2; | |
a2=a3; | |
a3=a4; | |
a4=a5; | |
a5=a6; | |
a6=a7; | |
a7=getchar(); | |
// Contar las filas, ej: "ESC[12;5H" son 12 filas | |
if (a1=='\x1b' && a2=='[' && | |
a3>='0' && a3<='9' && | |
a4>='0' && a4<='9' && | |
a5==';' && | |
a6=='5' && a7=='H' | |
) { | |
filas = (a3-'0')*10 + a4-'0'; | |
if (filas > maxfilas) | |
maxfilas=filas; | |
} | |
// Interceptar ?47h al principio para que no borre la pantalla | |
if (a2=='\x1b' && a3=='[' && a4=='?' && a5=='4' && a6=='7' && a7=='h') { | |
a7='l'; | |
} | |
// Interceptar 2J (limpiar pantalla al final) | |
if (a5=='[' && a6=='2' && a7=='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 (a7 != EOF) | |
putchar(a7); | |
} while (a7 != EOF); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment