From 9ff7f30cb1e0e743655548c6b10da5ef5641ac00 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 6 May 2022 05:26:26 -0700 Subject: Toggle highlighting of marker chars. --- pw.c | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'pw.c') diff --git a/pw.c b/pw.c index 9daaf5e..38d08b4 100644 --- a/pw.c +++ b/pw.c @@ -76,7 +76,8 @@ enum status_flags { stat_grep = 64, // grep mode stat_force = 128, // force refresh even if clean stat_lino = 256, // render line numbers - stat_bkgnd = 512 // running in the background + stat_bkgnd = 512, // running in the background + stat_hlite = 1024 // running in the background }; typedef struct pwstate { @@ -337,6 +338,29 @@ static void clreol(int nl) putchar('\n'); } +static void hlon(void) +{ + printf("\033[7m"); +} + +static void hloff(void) +{ + printf("\033[m"); +} + +#define with_hl(pw, expr) do { \ + if ((pw)->stat & stat_hlite) \ + hlon(); \ + expr; \ + if ((pw)->stat & stat_hlite) \ + hloff(); \ +} while (0) + +static void hlchar(pwstate *pw, int ch) +{ + with_hl(pw, putchar(ch)); +} + static void drawline(pwstate *pw, const char *line, int lineno) { const char *oline = line; @@ -372,7 +396,7 @@ static void drawline(pwstate *pw, const char *line, int lineno) len = 0; } else if (len - delta <= vsplit2) { if (vsplit1) { - putchar('|'); + hlchar(pw, '|'); delta++; } fputs(line + delta, stdout); @@ -382,7 +406,7 @@ static void drawline(pwstate *pw, const char *line, int lineno) } else { unsigned start = 0; if (vsplit1) { - putchar('|'); + hlchar(pw, '|'); start++; } for (unsigned i = start; i < vsplit2; i++) @@ -398,7 +422,7 @@ static void drawline(pwstate *pw, const char *line, int lineno) if (pw->hpos || vsplit1 || vsplit2) { line += pw->hpos + 1; len -= pw->hpos + 1; - putchar('>'); + hlchar(pw, '>'); columns--; } if (len < (size_t) columns) { @@ -407,11 +431,12 @@ static void drawline(pwstate *pw, const char *line, int lineno) } else { for (int i = 0; i < columns - 1; i++) putchar(line[i]); - puts("<"); + hlchar(pw, '<'); + putchar('\n'); } } else { if (endmark) - putchar('>'); + hlchar(pw, '>'); clreol(1); } } @@ -1197,6 +1222,10 @@ int main(int argc, char **argv) pw.stat |= stat_force; } break; + case ctrl('i'): + pw.stat ^= stat_hlite; + pw.stat |= stat_force; + break; case 'j': if (pw.hist > 0) { pw.hist--; -- cgit v1.2.3