commit e6c16381f36382ac1892587dd2bb246837c4fbe6
parent a519945d8fdbb3248dd0a886a257f552dc4866e6
Author: Remy Noulin <loader2x@gmail.com>
Date: Wed, 2 Jan 2019 12:34:51 +0100
move stripAnsiSequences lower
boxen.c | 55 ++++++++++++++++++++++++++++---------------------------
1 file changed, 28 insertions(+), 27 deletions(-)
Diffstat:
| M | boxen.c | | | 55 | ++++++++++++++++++++++++++++--------------------------- |
1 file changed, 28 insertions(+), 27 deletions(-)
diff --git a/boxen.c b/boxen.c
@@ -28,6 +28,7 @@ internal char *boxBoxen(boxent *self, char *input, char *opts);
/* #undef pLog */
/* #define pLog(...) */
+internal void stripAnsiSequences(char *string);
internal size_t widestLine(char **text);
typ struct {u16 rows; u16 cols;} winSizet;
internal winSizet wsize (void);
@@ -257,33 +258,6 @@ internal const char* helpBoxen(boxent UNUSED *self) {
ret "TODO - boxen help";
}
-// https://en.wikipedia.org/wiki/ANSI_escape_code#Escape_sequences
-// [\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)
-// (?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))
-internal void stripAnsiSequences(char *string) {
- size_t i = 0,j = 0;
- enum {SEARCH_SEQ, CTRL_CODE};
- u8 status = SEARCH_SEQ;
- while(string[i]) {
- if (status == SEARCH_SEQ) {
- if (string[i] == '\x1b' || string[i] == '\x9b') {
- // dont copy sequence
- status = CTRL_CODE;
- }
- else {
- // copy other char
- string[j++] = string[i];
- }
- }
- if (status == CTRL_CODE and string[i] == 'm') {
- // all libsheepy codes end with 'm'
- status = SEARCH_SEQ;
- }
- i++;
- }
- string[j] = 0;
-}
-
#define border(bord) self->borderStyle.bord
#define oborderColor(color, value)\
if (icEqG(getG(&j, rtChar, "borderColor"), color)) {\
@@ -558,6 +532,33 @@ internal char *boxBoxen(boxent *self, char *input, char *opts) {
ret r;
}
+// https://en.wikipedia.org/wiki/ANSI_escape_code#Escape_sequences
+// [\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)
+// (?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))
+internal void stripAnsiSequences(char *string) {
+ size_t i = 0,j = 0;
+ enum {SEARCH_SEQ, CTRL_CODE};
+ u8 status = SEARCH_SEQ;
+ while(string[i]) {
+ if (status == SEARCH_SEQ) {
+ if (string[i] == '\x1b' || string[i] == '\x9b') {
+ // dont copy sequence
+ status = CTRL_CODE;
+ }
+ else {
+ // copy other char
+ string[j++] = string[i];
+ }
+ }
+ if (status == CTRL_CODE and string[i] == 'm') {
+ // all libsheepy codes end with 'm'
+ status = SEARCH_SEQ;
+ }
+ i++;
+ }
+ string[j] = 0;
+}
+
internal size_t widestLine(char **text) {
size_t r = 0;
if (!text) ret 0;