mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Handle ANSI Escape codes in column(1).
This commit is contained in:
parent
a041c107d5
commit
7a8687e063
1 changed files with 24 additions and 1 deletions
|
@ -21,6 +21,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#define _SORTIX_SOURCE
|
#define _SORTIX_SOURCE
|
||||||
|
#include <ctype.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -37,6 +38,28 @@ size_t lineslength = 0;
|
||||||
char** lines = 0;
|
char** lines = 0;
|
||||||
size_t longestline = 0;
|
size_t longestline = 0;
|
||||||
|
|
||||||
|
size_t measurelength(const char* line)
|
||||||
|
{
|
||||||
|
size_t len = 0;
|
||||||
|
bool escaped = false;
|
||||||
|
while ( char c = *line++ )
|
||||||
|
{
|
||||||
|
if ( escaped )
|
||||||
|
{
|
||||||
|
if ( isalpha(c) )
|
||||||
|
escaped = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( c == '\e' )
|
||||||
|
{
|
||||||
|
escaped = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
len++;
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
bool processline(char* line)
|
bool processline(char* line)
|
||||||
{
|
{
|
||||||
if ( linesused == lineslength )
|
if ( linesused == lineslength )
|
||||||
|
@ -50,7 +73,7 @@ bool processline(char* line)
|
||||||
}
|
}
|
||||||
|
|
||||||
lines[linesused++] = line;
|
lines[linesused++] = line;
|
||||||
size_t linelen = strlen(line);
|
size_t linelen = measurelength(line);
|
||||||
if ( longestline < linelen ) { longestline = linelen; }
|
if ( longestline < linelen ) { longestline = linelen; }
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue