From 686ce24e9a67b42765ff5638e1d747c8ea82343d Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sun, 17 Feb 2019 14:38:11 -0500 Subject: Add line numbers to hi Renames previous -n option to -m to stay consistent with cat -n. Prefixing lines with line numbers affects where the first tab indent ends up relative to the text above it. Not sure if it's worth fixing somehow. --- bin/hi.c | 19 +++++++++++++++---- bin/man1/hi.1 | 11 +++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) (limited to 'bin') diff --git a/bin/hi.c b/bin/hi.c index 68674e6a..7fac4bf2 100644 --- a/bin/hi.c +++ b/bin/hi.c @@ -41,7 +41,8 @@ typedef unsigned Set; X(Format) \ X(Interp) \ X(Comment) \ - X(Todo) + X(Todo) \ + X(Line) enum Class { #define X(class) class, @@ -361,6 +362,7 @@ static const enum SGR ANSIStyle[ClassLen][3] = { [Interp] = { SGRYellow }, [Comment] = { SGRBlue }, [Todo] = { SGRBlue, SGRBoldOn, SGRBoldOff }, + [Line] = { SGRRed }, }; static void @@ -474,6 +476,7 @@ static const char *HTMLStyle[ClassLen] = { [Interp] = "color: olive;", [Comment] = "color: navy;", [Todo] = "color: navy; font-weight: bold;", + [Line] = "color: maroon;", }; static void htmlTabSize(const char *tab) { @@ -613,9 +616,10 @@ int main(int argc, char *argv[]) { struct Language lang = {0}; struct Format format = Formats[0]; const char *opts[OptionLen] = {0}; + bool number = false; int opt; - while (0 < (opt = getopt(argc, argv, "cf:l:n:o:"))) { + while (0 < (opt = getopt(argc, argv, "cf:l:m:no:"))) { switch (opt) { break; case 'c': check(); return EX_OK; break; case 'f': { @@ -628,7 +632,8 @@ int main(int argc, char *argv[]) { errx(EX_USAGE, "no such language %s", optarg); } } - break; case 'n': name = optarg; + break; case 'm': name = optarg; + break; case 'n': number = true; break; case 'o': { enum Option key; char *keystr, *valstr; @@ -685,9 +690,15 @@ int main(int argc, char *argv[]) { highlight(lang, hi, str); - if (format.header) format.header(opts); size_t run = 0; + size_t line = 0; + if (format.header) format.header(opts); for (size_t i = 0; i < len; i += run) { + if (number && (!i || str[i - 1] == '\n')) { + char num[sizeof("9999 ")]; + snprintf(num, sizeof(num), "%4zu ", ++line); + format.output(opts, Line, num, sizeof(num) - 1); + } for (run = 1; i + run < len; ++run) { if (hi[i + run] != hi[i]) break; if (str[i + run - 1] == '\n') break; diff --git a/bin/man1/hi.1 b/bin/man1/hi.1 index c48fa796..afe0fe0c 100644 --- a/bin/man1/hi.1 +++ b/bin/man1/hi.1 @@ -1,4 +1,4 @@ -.Dd February 12, 2019 +.Dd February 17, 2019 .Dt HI 1 .Os . @@ -8,9 +8,10 @@ . .Sh SYNOPSIS .Nm +.Op Fl n .Op Fl f Ar format .Op Fl l Ar lang -.Op Fl n Ar name +.Op Fl m Ar name .Op Fl o Ar opts .Op Ar file .Nm @@ -33,9 +34,11 @@ Compile all regular expressions and exit. Set the output format. .It Fl l Ar lang Set the input language. -.It Fl n Ar name +.It Fl m Ar name Override the name used to infer the input language. +.It Fl n +Output line numbers. .It Fl o Ar opts Set output format options. .Ar opts @@ -111,7 +114,7 @@ name. If no input language is set with .Fl l , it may be inferred from the name set by -.Fl n +.Fl m or from the provided .Ar file name. -- cgit 1.4.1 logmsg'> Interesting to see how my code habits have changed. 2021-09-16Fix /* **/ comment matchingJune McEnroe 2021-09-15Remove typer, add downgrade to READMEJune McEnroe 2021-09-15Set bot mode on downgradeJune McEnroe 2021-09-15Enter capsicum in downgradeJune McEnroe 2021-09-15Factor out common parts of downgrade messagesJune McEnroe Also bump the message cap to 1024 because that is ostensibly useful for replying to older messages. 2021-09-14Add downgrade IRC botJune McEnroe 2021-09-14Sort by title if authors matchJune McEnroe There are probably better things to sort by but title definitely always exists. 2021-09-13Swap-remove tags as they're foundJune McEnroe This makes it even faster. From ~1s on a sqlite3.c amalgamation to ~0.85s. 2021-09-12Replace htagml regex with strncmpJune McEnroe Since ctags only ever produces regular expressions of the form /^re$/ or /^re/ with no other special characters, instead unescape the pattern and simply use strncmp. Running on a sqlite3.c amalgamation, the regex version takes ~37s while the strncmp version takes ~1s, producing identical output. Big win! 2021-09-11Also defer printing comment for lone close-parensJune McEnroe 2021-09-10Publish "git-comment"June McEnroe 2021-09-10Add git comment --pretty optionJune McEnroe 2021-09-08Defer printing comment if line is blank or closing braceJune McEnroe This fixes badly indented comments. 2021-09-08Up default min-repeat to 30 linesJune McEnroe 2021-09-08Handle dirty lines in git-commentJune McEnroe 2021-09-08Document and install git-commentJune McEnroe 2021-09-08Add repeat and all options to git-commentJune McEnroe 2021-09-08Add group threshold to git-commentJune McEnroe