diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-05-06 05:26:26 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-05-06 05:26:26 -0700 |
commit | 9ff7f30cb1e0e743655548c6b10da5ef5641ac00 (patch) | |
tree | 63d5efdc69efa07f5f229c1e70e9670d681532bd /pw.c | |
parent | e5c48d3b66a434156699402031c0cd78628a9850 (diff) | |
download | pw-9ff7f30cb1e0e743655548c6b10da5ef5641ac00.tar.gz pw-9ff7f30cb1e0e743655548c6b10da5ef5641ac00.tar.bz2 pw-9ff7f30cb1e0e743655548c6b10da5ef5641ac00.zip |
Toggle highlighting of marker chars.
Diffstat (limited to 'pw.c')
-rw-r--r-- | pw.c | 41 |
1 files changed, 35 insertions, 6 deletions
@@ -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--; |