Re: [PATCH 2/2] less: replace most uses of NORMAL escape with UNHIGHLIGHT

2022-04-14 Thread Ishan Bhargava
On Fri, 15 Apr 2022 at 05:49, Kang-Che Sung  wrote:
> What's the difference between the NORMAL escape and the UNHIGHLIGHT escape? 
> Is there a test case to demonstrate th>

The UNHIGHLIGHT escape flips only the HIGHLIGHT (invert, actually) bit back to
off. The normal escape flips ALL special display bits back to off, including
color. We don't want that in case there is a highlighted term (e.g. another
control sequence) in between a colored line.

test case:
printf '\033[33mhello\033\007\013hi\033[m' > ./tmp

Compare how busybox less without this 2nd patch vs. greenwood less (and bbless
with this patch) shows the output. In the former, the colored line is just cut
short because of the highlighted control chars. In the latter, the entire line
is colored, with small highlighted (colored) sections in between.

One thing this cannot deal with is a highlight escape in the input itself,
which would be cut short by any less-emmitted highlight sequence. Avoiding that
would probably require looking at the escapes and keeping state.
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH 2/2] less: replace most uses of NORMAL escape with UNHIGHLIGHT

2022-04-14 Thread Kang-Che Sung
On Friday, April 15, 2022, FriendlyNeighborhoodShane <
shane.880088.s...@gmail.com> wrote:
> Fixes conflict when -R's color escape codes are mixed together with
> highlights. Better complement to HIGHLIGHT.

What's the difference between the NORMAL escape and the UNHIGHLIGHT escape?
Is there a test case to demonstrate the difference?
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[PATCH 2/2] less: replace most uses of NORMAL escape with UNHIGHLIGHT

2022-04-14 Thread FriendlyNeighborhoodShane
Fixes conflict when -R's color escape codes are mixed together with
highlights. Better complement to HIGHLIGHT.
---
 miscutils/less.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/miscutils/less.c b/miscutils/less.c
index 392a3ef3c..7fcd6951a 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -155,6 +155,7 @@
 #define ESC "\033"
 /* The escape codes for highlighted and normal text */
 #define HIGHLIGHT   ESC"[7m"
+#define UNHIGHLIGHT ESC"[27m"
 #define NORMAL  ESC"[m"
 /* The escape code to home and clear to the end of screen */
 #define CLEAR   ESC"[H"ESC"[J"
@@ -312,13 +313,13 @@ static void clear_line(void)
 
 static void print_hilite(const char *str)
 {
-   printf(HIGHLIGHT"%s"NORMAL, str);
+   printf(HIGHLIGHT"%s"UNHIGHLIGHT, str);
 }
 
 static void print_statusline(const char *str)
 {
clear_line();
-   printf(HIGHLIGHT"%.*s"NORMAL, width - 1, str);
+   printf(HIGHLIGHT"%.*s"UNHIGHLIGHT, width - 1, str);
 }
 
 /* Exit the program gracefully */
@@ -710,7 +711,7 @@ static void m_status_print(void)
percent = (100 * last + num_lines/2) / num_lines;
printf(" %i%%", percent <= 100 ? percent : 100);
}
-   printf(NORMAL);
+   printf(UNHIGHLIGHT);
 }
 #endif
 
@@ -740,7 +741,7 @@ static void status_print(void)
if (!cur_fline)
p = filename;
if (num_files > 1) {
-   printf(HIGHLIGHT"%s (file %i of %i)"NORMAL,
+   printf(HIGHLIGHT"%s (file %i of %i)"UNHIGHLIGHT,
p, current_file, num_files);
return;
}
@@ -808,7 +809,7 @@ static void print_found(const char *line)
/* buf[] holds quarantined version of str */
 
/* Each part of the line that matches has the HIGHLIGHT
-* and NORMAL escape sequences placed around it.
+* and UNHIGHLIGHT escape sequences placed around it.
 * NB: we regex against line, but insert text
 * from quarantined copy (buf[]) */
str = buf;
@@ -817,7 +818,7 @@ static void print_found(const char *line)
goto start;
 
while (match_status == 0) {
-   char *new = xasprintf("%s%.*s"HIGHLIGHT"%.*s"NORMAL,
+   char *new = xasprintf("%s%.*s"HIGHLIGHT"%.*s"UNHIGHLIGHT,
growline ? growline : "",
(int)match_structs.rm_so, str,
(int)(match_structs.rm_eo - 
match_structs.rm_so),
@@ -1551,7 +1552,7 @@ static void show_flag_status(void)
}
 
clear_line();
-   printf(HIGHLIGHT"The status of the flag is: %u"NORMAL, flag_val != 0);
+   printf(HIGHLIGHT"The status of the flag is: %u"UNHIGHLIGHT, flag_val != 
0);
 }
 #endif
 
-- 
2.35.2

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox