aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-12-21 04:29:14 -0500
committerB. Watson <urchlay@slackware.uk>2024-12-21 04:29:14 -0500
commitd7546f793ca01866ba1a1351e2f139a7c0ed9711 (patch)
tree796dfe98845ed3146350465ff0e71d49682a3bfb
parentb51d501fd23f18f3d1f6222cbf8fc3f714bc330e (diff)
downloaduxd-d7546f793ca01866ba1a1351e2f139a7c0ed9711.tar.gz
alternating colors for specials
-rw-r--r--usage.c2
-rw-r--r--uxd.112
-rw-r--r--uxd.c24
-rw-r--r--uxd.rst12
4 files changed, 32 insertions, 18 deletions
diff --git a/usage.c b/usage.c
index 16a7dd9..57343fa 100644
--- a/usage.c
+++ b/usage.c
@@ -1,7 +1,7 @@
char *usage_opts[] = {
" -1: don't alternate colors for normal characters.",
" -b: bold color output.",
- " -c nnnn: colors (2 to 4 digits, 0 to 7).",
+ " -c nnnnn: colors (2 to 5 digits, 0 to 7).",
" -d data: dump this data instead of a file.",
" -h, --help: print this help message.",
" -i: print number of bytes/chars/ascii/multibyte/bad sequences.",
diff --git a/uxd.1 b/uxd.1
index 2066f89..cb36f29 100644
--- a/uxd.1
+++ b/uxd.1
@@ -84,15 +84,15 @@ terminal and its color settings. Ignored if \fB\-m\fP given.
.
.INDENT 0.0
.TP
-.BI \-c \ nnnn
-Set the colors to use. Must be 2 to 4 digits, from 0 to 7. These are
+.BI \-c \ nnnnn
+Set the colors to use. Must be 2 to 5 digits, from 0 to 7. These are
standard ANSI colors. The first 2 are the alternating colors for
-normal characters, the 3rd digit (optional) is the color for non\-printable
-and space characters, and the 4th (optional) is for invalid UTF\-8
-sequences. Default: \fB2351\fP\&. This option also disables a prior \fB\-m\fP
+normal characters, the 3rd and 4th (optional) are the alternating color for non\-printable
+and space characters, and the 5th (optional) is for invalid UTF\-8
+sequences. Default: \fB23561\fP\&. This option also disables a prior \fB\-m\fP
option.
.UNINDENT
-.\" colors (2 to 4 digits, 0 to 7).
+.\" colors (2 to 5 digits, 0 to 7).
.
.INDENT 0.0
.TP
diff --git a/uxd.c b/uxd.c
index 180de80..5775ef4 100644
--- a/uxd.c
+++ b/uxd.c
@@ -101,11 +101,12 @@ FILE *input;
/* default colors */
int normal_colors[] = { GREEN, YELLOW };
+int special_colors[] = { PURPLE, CYAN };
int bad_color = RED;
-int special_color = PURPLE;
-/* toggles between 0 and 1 for each normal character */
+/* toggles between 0 and 1 for each normal/special character */
int cur_normal_hilite = 0;
+int cur_special_hilite = 0;
/* these buffers are bigger than they need to be really. */
/* offset and hex bytes: */
@@ -219,11 +220,16 @@ void parse_colors(char *arg) {
/* optional 3rd color */
if(!arg[2]) return;
check_color(arg[2]);
- special_color = arg[2] - '0';
+ special_colors[0] = arg[2] - '0';
/* optional 4th color */
if(!arg[3]) return;
check_color(arg[3]);
+ special_colors[1] = arg[2] - '0';
+
+ /* optional 5th color */
+ if(!arg[4]) return;
+ check_color(arg[3]);
bad_color = arg[3] - '0';
}
@@ -428,6 +434,11 @@ void next_normal_hilite(void) {
cur_normal_hilite = !cur_normal_hilite;
}
+void next_special_hilite(void) {
+ if(alternate_colors)
+ cur_special_hilite = !cur_special_hilite;
+}
+
void append_color(char *buf, int hl_type) {
char tmpbuf[100];
int fgcolor, bgcolor;
@@ -442,12 +453,12 @@ void append_color(char *buf, int hl_type) {
bgcolor = normal_colors[cur_normal_hilite];
break;
case HL_SPECIAL:
- fgcolor = special_color;
+ fgcolor = special_colors[cur_special_hilite];
bgcolor = 0;
break;
case HL_SPEC_INV:
fgcolor = 0;
- bgcolor = special_color;
+ bgcolor = special_colors[cur_special_hilite];
break;
case HL_BAD:
default:
@@ -764,6 +775,9 @@ int dump_utf8_char(void) {
if(hl_type == HL_NORMAL || hl_type == HL_NORM_INV)
next_normal_hilite();
+ if(hl_type == HL_SPECIAL || hl_type == HL_SPEC_INV)
+ next_special_hilite();
+
return 1;
}
diff --git a/uxd.rst b/uxd.rst
index 53a9789..6069e4e 100644
--- a/uxd.rst
+++ b/uxd.rst
@@ -69,15 +69,15 @@ as *K*, *M*, and *G* for power-of-10 based (e.g. *1K* is 1000 bytes).
.. bold color output.
--c nnnn
- Set the colors to use. Must be 2 to 4 digits, from 0 to 7. These are
+-c nnnnn
+ Set the colors to use. Must be 2 to 5 digits, from 0 to 7. These are
standard ANSI colors. The first 2 are the alternating colors for
- normal characters, the 3rd digit (optional) is the color for non-printable
- and space characters, and the 4th (optional) is for invalid UTF-8
- sequences. Default: **2351**. This option also disables a prior **-m**
+ normal characters, the 3rd and 4th (optional) are the alternating color for non-printable
+ and space characters, and the 5th (optional) is for invalid UTF-8
+ sequences. Default: **23561**. This option also disables a prior **-m**
option.
-.. colors (2 to 4 digits, 0 to 7).
+.. colors (2 to 5 digits, 0 to 7).
-d data
Dump this data, instead of reading from a file or stdin. If *data*