136 lines
4.9 KiB
Diff
136 lines
4.9 KiB
Diff
|
|
From 2c01af28e833131c9b27119095414b636a8a1474 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Mark Nudelman <markn@greenwoodsoftware.com>
|
||
|
|
Date: Tue, 18 Oct 2022 23:00:39 -0700
|
||
|
|
Subject: [PATCH 25/48] Have lt_screen use ANSI sequences for bold, underline
|
||
|
|
etc rather than custom sequences. Need to support ANSI anyway and having two
|
||
|
|
mechanisms is unnecessarily complicated.
|
||
|
|
|
||
|
|
---
|
||
|
|
lesstest/env.c | 12 ++++++------
|
||
|
|
lesstest/lt_screen.c | 46 +++++++++++++++++++++++++++++++-------------
|
||
|
|
2 files changed, 39 insertions(+), 19 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/lesstest/env.c b/lesstest/env.c
|
||
|
|
index 76d26d0..72c2023 100644
|
||
|
|
--- a/lesstest/env.c
|
||
|
|
+++ b/lesstest/env.c
|
||
|
|
@@ -73,13 +73,13 @@ static void env_setup(EnvBuf* env, char* const* prog_env, int interactive) {
|
||
|
|
{ "LESS_TERMCAP_ho", "\33h" },
|
||
|
|
{ "LESS_TERMCAP_ll", "\33l" },
|
||
|
|
{ "LESS_TERMCAP_mb", "\33b" },
|
||
|
|
- { "LESS_TERMCAP_md", "\33d" },
|
||
|
|
- { "LESS_TERMCAP_me", "\33E" },
|
||
|
|
- { "LESS_TERMCAP_se", "\33t" },
|
||
|
|
- { "LESS_TERMCAP_so", "\33s" },
|
||
|
|
+ { "LESS_TERMCAP_md", "\33[1m" },
|
||
|
|
+ { "LESS_TERMCAP_me", "\33[m" },
|
||
|
|
+ { "LESS_TERMCAP_se", "\33[m" },
|
||
|
|
+ { "LESS_TERMCAP_so", "\33[7m" },
|
||
|
|
{ "LESS_TERMCAP_sr", "\33r" },
|
||
|
|
- { "LESS_TERMCAP_ue", "\33v" },
|
||
|
|
- { "LESS_TERMCAP_uo", "\33u" },
|
||
|
|
+ { "LESS_TERMCAP_ue", "\33[24m" },
|
||
|
|
+ { "LESS_TERMCAP_us", "\33[4m" },
|
||
|
|
{ "LESS_TERMCAP_vb", "\33g" },
|
||
|
|
{ "LESS_TERMCAP_kr", terminfo.key_right ? terminfo.key_right : "" },
|
||
|
|
{ "LESS_TERMCAP_kl", terminfo.key_left ? terminfo.key_left : "" },
|
||
|
|
diff --git a/lesstest/lt_screen.c b/lesstest/lt_screen.c
|
||
|
|
index 723a0e9..6cfa348 100644
|
||
|
|
--- a/lesstest/lt_screen.c
|
||
|
|
+++ b/lesstest/lt_screen.c
|
||
|
|
@@ -211,6 +211,9 @@ static int screen_clear_attr(int attr) {
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
+// ------------------------------------------------------------------
|
||
|
|
+// lt_screen supports certain ANSI color values.
|
||
|
|
+// This simplifies testing SGR sequences with less -R.
|
||
|
|
static int screen_set_color(int color) {
|
||
|
|
int ret = 0;
|
||
|
|
switch (color) {
|
||
|
|
@@ -219,17 +222,26 @@ static int screen_set_color(int color) {
|
||
|
|
case 5:
|
||
|
|
case 6: ret = screen_set_attr(ATTR_BLINK); break;
|
||
|
|
case 7: ret = screen_set_attr(ATTR_STANDOUT); break;
|
||
|
|
+ case 21:
|
||
|
|
case 22: ret = screen_clear_attr(ATTR_BOLD); break;
|
||
|
|
case 24: ret = screen_clear_attr(ATTR_UNDERLINE); break;
|
||
|
|
+ case 25: ret = screen_clear_attr(ATTR_BLINK); break;
|
||
|
|
+ case 27: ret = screen_clear_attr(ATTR_STANDOUT); break;
|
||
|
|
+ // case 38: break;
|
||
|
|
+ // case 48: break;
|
||
|
|
default:
|
||
|
|
- if (color < 0)
|
||
|
|
+ if (color < 0) {
|
||
|
|
screen.curr_fg_color = screen.curr_bg_color = NULL_COLOR;
|
||
|
|
- else if ((color >= 30 && color <= 37) || (color >= 90 && color <= 97))
|
||
|
|
+ ret = 1;
|
||
|
|
+ } else if ((color >= 30 && color <= 37) || (color >= 90 && color <= 97)) {
|
||
|
|
screen.curr_fg_color = color;
|
||
|
|
- else if ((color >= 40 && color <= 47) || (color >= 100 && color <= 107))
|
||
|
|
+ ret = 1;
|
||
|
|
+ } else if ((color >= 40 && color <= 47) || (color >= 100 && color <= 107)) {
|
||
|
|
screen.curr_bg_color = color;
|
||
|
|
- else
|
||
|
|
- fprintf(stderr, "unrecognized color %d\n", color);
|
||
|
|
+ ret = 1;
|
||
|
|
+ } else {
|
||
|
|
+ fprintf(stderr, "[%d,%d] unrecognized color %d\n", screen.cx, screen.cy, color);
|
||
|
|
+ }
|
||
|
|
if (verbose) fprintf(stderr, "[%d,%d] set_color(%d)=%d/%d\n", screen.cx, screen.cy, color, screen.curr_fg_color, screen.curr_bg_color);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
@@ -282,25 +294,33 @@ static int exec_esc(wchar ch) {
|
||
|
|
return screen_rscroll();
|
||
|
|
case '<': // cursor left to start of line
|
||
|
|
return screen_cr();
|
||
|
|
- case 's': // enter standout
|
||
|
|
- return screen_set_attr(ATTR_STANDOUT);
|
||
|
|
- case 't': // exit standout
|
||
|
|
- return screen_clear_attr(ATTR_STANDOUT);
|
||
|
|
+#if 1
|
||
|
|
case 'u': // enter underline
|
||
|
|
+fprintf(stderr, "DEPRECATED ESC-%c\n", (char)ch);
|
||
|
|
return screen_set_attr(ATTR_UNDERLINE);
|
||
|
|
case 'v': // exit underline
|
||
|
|
+fprintf(stderr, "DEPRECATED ESC-%c\n", (char)ch);
|
||
|
|
return screen_clear_attr(ATTR_UNDERLINE);
|
||
|
|
case 'd': // enter bold
|
||
|
|
+fprintf(stderr, "DEPRECATED ESC-%c\n", (char)ch);
|
||
|
|
return screen_set_attr(ATTR_BOLD);
|
||
|
|
+ case 'E': // exit bold/blink
|
||
|
|
+fprintf(stderr, "DEPRECATED ESC-%c\n", (char)ch);
|
||
|
|
+ return screen_clear_attr(ATTR_BOLD|ATTR_BLINK);
|
||
|
|
+ case 's': // enter standout
|
||
|
|
+fprintf(stderr, "DEPRECATED ESC-%c\n", (char)ch);
|
||
|
|
+ return screen_set_attr(ATTR_STANDOUT);
|
||
|
|
+ case 't': // exit standout
|
||
|
|
+fprintf(stderr, "DEPRECATED ESC-%c\n", (char)ch);
|
||
|
|
+ return screen_clear_attr(ATTR_STANDOUT);
|
||
|
|
+#endif
|
||
|
|
case 'e': // exit bold
|
||
|
|
return screen_clear_attr(ATTR_BOLD);
|
||
|
|
case 'b': // enter blink
|
||
|
|
return screen_set_attr(ATTR_BLINK);
|
||
|
|
case 'c': // exit blink
|
||
|
|
return screen_clear_attr(ATTR_BLINK);
|
||
|
|
- case 'E': // exit bold/blink
|
||
|
|
- return screen_clear_attr(ATTR_BOLD|ATTR_BLINK);
|
||
|
|
- case 'm': // set color
|
||
|
|
+ case 'm': // SGR (Select Graphics Rendition)
|
||
|
|
if (num_params() == 0) {
|
||
|
|
screen_set_color(-1);
|
||
|
|
} else {
|
||
|
|
@@ -346,7 +366,7 @@ static int process_char(wchar ch) {
|
||
|
|
} else if (ch == ';') {
|
||
|
|
param_push(0);
|
||
|
|
} else if (ch == '[') {
|
||
|
|
- ; // ANSI sequence
|
||
|
|
+ ; // Ignore ANSI marker
|
||
|
|
} else {
|
||
|
|
screen.in_esc = 0;
|
||
|
|
ok = exec_esc(ch);
|
||
|
|
--
|
||
|
|
2.27.0
|
||
|
|
|