Commit a881209c authored by Alice Mitchell's avatar Alice Mitchell

Add reset sequence &0& and more fixes to ignoring invalid sequences

parent ae7e7128
Pipeline #547 passed with stage
in 8 minutes and 13 seconds
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <stdbool.h>
#include "frl.h" #include "frl.h"
#include "colour.h" #include "colour.h"
#include "user.h" #include "user.h"
...@@ -96,6 +97,7 @@ int colour(const char *input, char *output, int outlen) ...@@ -96,6 +97,7 @@ int colour(const char *input, char *output, int outlen)
if (strchr("-n", text[0]) && if (strchr("-n", text[0]) &&
strchr("-n", text[1]) ) strchr("-n", text[1]) )
{ {
output[i++] = '0';
output[i++] = 'm'; output[i++] = 'm';
output[i] = '\0'; output[i] = '\0';
return(consume); return(consume);
...@@ -146,41 +148,47 @@ int colour(const char *input, char *output, int outlen) ...@@ -146,41 +148,47 @@ int colour(const char *input, char *output, int outlen)
output[i] = '\0'; output[i] = '\0';
} }
if (*input == '&') { if (*input == '&') {
bool fg_done = false;
/* first let us test this is a valid colour string */ /* first let us test this is a valid colour string */
const char *p = input + 1; const char *p = input + 1;
/* skip past all valid chars */ /* skip past all valid chars */
while (*p && strchr("0123456789AbBcCdDeEfF:", *p)) p++; while (*p && strchr("0123456789aAbBcCdDeEfF:", *p)) p++;
/* not the ending we were expecting, ignore it then */ /* not the ending we were expecting, ignore it then */
if (*p != '&') return 0; if (*p != '&') return 0;
/* empty pattern is not a pattern */
if (p == input + 1) return 0;
char hex[7]; int outused = 0;
int i = 0;
consume = 1;
while (i < 7 && input[consume] && strchr("0123456789AbBcCdDeEfF", input[consume]))
hex[i++] = input[consume++];
hex[i] = '\0';
if (i == 2) {
int col = hex_decode(hex, 2);
snprintf(output, outlen, "\033[38;5;%dm", col);
}
if (input[consume] == ':') { do {
char hex[7];
int i = 0;
consume++; consume++;
i=0; while (i < 7 && input[consume] && strchr("0123456789aAbBcCdDeEfF", input[consume]))
while (i < 7 && input[consume] && strchr("0123456789AbBcCdDeEfF", input[consume]))
hex[i++] = input[consume++]; hex[i++] = input[consume++];
hex[i] = '\0'; hex[i] = '\0';
if (i == 1) {
int col = hex_decode(hex, 1);
if (col < 10)
snprintf(&output[outused], outlen-outused, "\033[%dm", col);
} else
if (i == 2) { if (i == 2) {
int col = hex_decode(hex, 2); int col = hex_decode(hex, 2);
int off = strlen(output); snprintf(&output[outused], outlen-outused, "\033[%d;5;%dm", fg_done?48:38, col);
snprintf(&output[off], outlen-off, "\033[48;5;%dm", col); fg_done = true;
} else {
output[0] = '\0';
return 0;
} }
outused = strlen(output);
} while(input[consume] == ':');
if (input[consume] != '&') {
output[0] = '\0';
return 0;
} }
while (input[consume] && strchr("0123456789AbBcCdDeEfF:", input[consume])) consume++;
consume++;
if (input[consume] == '&') consume++;
} }
return(consume); return(consume);
} }
......
...@@ -1129,6 +1129,7 @@ void display_message(const char *text, int beeps, int newline) ...@@ -1129,6 +1129,7 @@ void display_message(const char *text, int beeps, int newline)
if (!s_colouroff(user) && colr[0]) { if (!s_colouroff(user) && colr[0]) {
outline[olen++] = 033; outline[olen++] = 033;
outline[olen++] = '['; outline[olen++] = '[';
outline[olen++] = '0';
outline[olen++] = 'm'; outline[olen++] = 'm';
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment