summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-02-18 17:07:53 -0500
committerJune McEnroe <june@causal.agency>2019-02-18 17:07:53 -0500
commitf438b384749b22a28582e2c17b54ff1bf5ca9fb9 (patch)
tree0c465901a61403583f8c2df0705440193010781e /bin
parentAdd Tag class to hi (diff)
downloadsrc-f438b384749b22a28582e2c17b54ff1bf5ca9fb9.tar.gz
src-f438b384749b22a28582e2c17b54ff1bf5ca9fb9.zip
Remove hi line numbering
Tags are much better for referring to specific parts of a file and line
numbering is better done by a post-processing tool such as cat -n or
producing a two-column HTML <table>.
Diffstat (limited to '')
-rw-r--r--bin/Makefile8
-rw-r--r--bin/hi.c52
-rw-r--r--bin/man1/hi.118
3 files changed, 17 insertions, 61 deletions
diff --git a/bin/Makefile b/bin/Makefile
index 43d2cce1..4788281c 100644
--- a/bin/Makefile
+++ b/bin/Makefile
@@ -101,16 +101,16 @@ $(HTMLS): ttpre hi
 .SUFFIXES: .html
 
 .c.html:
-	@./hi -f html -o document,anchor,tab=4 -m $< /dev/null > $@
+	@./hi -f html -o document,tab=4 -n $< /dev/null > $@
 	@echo '<code><a href="$(GITEA_URL)/$<">$< in git</a></code>' >> $@
 	man -P cat ./man1/$(<:%.c=%.1) | ./ttpre >> $@
-	./hi -n -f html -o anchor $< >> $@
+	./hi -f html -o anchor $< >> $@
 
 .sh.html:
-	@./hi -f html -o document,anchor,tab=4 -m $< /dev/null > $@
+	@./hi -f html -o document,tab=4 -n $< /dev/null > $@
 	@echo '<code><a href="$(GITEA_URL)/$<">$< in git</a></code>' >> $@
 	man -P cat ./man1/$(<:%.sh=%.1) | ./ttpre >> $@
-	./hi -n -f html -o anchor $< >> $@
+	./hi -f html -o anchor $< >> $@
 
 clean:
 	rm -f $(BINS_ALL) $(LINKS) tags scheme.h scheme.png *.o *.html
diff --git a/bin/hi.c b/bin/hi.c
index 18dd9239..15dcd4a2 100644
--- a/bin/hi.c
+++ b/bin/hi.c
@@ -42,8 +42,7 @@ typedef unsigned Set;
 	X(Format)  \
 	X(Interp)  \
 	X(Comment) \
-	X(Todo)    \
-	X(Line)
+	X(Todo)
 
 enum Class {
 #define X(class) class,
@@ -376,7 +375,6 @@ static const enum SGR ANSIStyle[ClassLen][3] = {
 	[Interp]  = { SGRYellow },
 	[Comment] = { SGRBlue },
 	[Todo]    = { SGRBlue, SGRBoldOn, SGRBoldOff },
-	[Line]    = { SGRRed },
 };
 
 static void
@@ -491,7 +489,6 @@ 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) {
@@ -518,23 +515,10 @@ static void htmlHeader(const char *opts[]) {
 			htmlTabSize(opts[Tab]);
 			printf(" }\n");
 		}
-		if (opts[Anchor]) {
-			printf(
-				".hi.%s:focus { outline-style: none; color: goldenrod; }",
-				ClassName[Tag]
-			);
-			printf(
-				".hi.%s { text-decoration: none; %s }\n"
-				".hi.%s:focus {"
-				" outline-style: none;"
-				" font-weight: bold;"
-				" text-decoration: underline;"
-				" }\n"
-				".hi.%s::before { content: attr(data-line); }\n",
-				ClassName[Line], HTMLStyle[Line],
-				ClassName[Line], ClassName[Line]
-			);
-		}
+		printf(
+			".hi.%s:focus { outline-style: none; color: goldenrod; }",
+			ClassName[Tag]
+		);
 		for (enum Class class = 0; class < ClassLen; ++class) {
 			if (!HTMLStyle[class]) continue;
 			printf(".hi.%s { %s }\n", ClassName[class], HTMLStyle[class]);
@@ -570,26 +554,12 @@ static void htmlAnchorTag(const char *opts[], const char *str, size_t len) {
 	printf("</a>");
 }
 
-static void htmlAnchorLine(const char *str, size_t len) {
-	size_t num = 0;
-	sscanf(str, " %zu", &num);
-	printf(
-		"<a class=\"hi %s\" id=\"L%zu\" href=\"#L%zu\" data-line=\"%.*s\">"
-		"</a>",
-		ClassName[Line], num, num, (int)len, str
-	);
-}
-
 static void
 htmlOutput(const char *opts[], enum Class class, const char *str, size_t len) {
 	if (opts[Anchor] && class == Tag) {
 		htmlAnchorTag(opts, str, len);
 		return;
 	}
-	if (opts[Anchor] && class == Line) {
-		htmlAnchorLine(str, len);
-		return;
-	}
 	if (opts[Inline]) {
 		printf("<span style=\"%s\">", HTMLStyle[class] ? HTMLStyle[class] : "");
 	} else {
@@ -680,10 +650,9 @@ 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:m:no:"))) {
+	while (0 < (opt = getopt(argc, argv, "cf:l:n:o:"))) {
 		switch (opt) {
 			break; case 'c': check(); return EX_OK;
 			break; case 'f': {
@@ -696,8 +665,7 @@ int main(int argc, char *argv[]) {
 					errx(EX_USAGE, "no such language %s", optarg);
 				}
 			}
-			break; case 'm': name = optarg;
-			break; case 'n': number = true;
+			break; case 'n': name = optarg;
 			break; case 'o': {
 				enum Option key;
 				char *keystr, *valstr;
@@ -755,14 +723,8 @@ int main(int argc, char *argv[]) {
 	highlight(lang, hi, str);
 
 	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 ee3a55a8..0d82ca75 100644
--- a/bin/man1/hi.1
+++ b/bin/man1/hi.1
@@ -1,4 +1,4 @@
-.Dd February 17, 2019
+.Dd February 18, 2019
 .Dt HI 1
 .Os
 .
@@ -8,10 +8,9 @@
 .
 .Sh SYNOPSIS
 .Nm
-.Op Fl n
 .Op Fl f Ar format
 .Op Fl l Ar lang
-.Op Fl m Ar name
+.Op Fl n Ar name
 .Op Fl o Ar opts
 .Op Ar file
 .Nm
@@ -34,11 +33,9 @@ Compile all regular expressions and exit.
 Set the output format.
 .It Fl l Ar lang
 Set the input language.
-.It Fl m Ar name
+.It Fl n 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
@@ -74,12 +71,9 @@ classes.
 The options are as follows:
 .Bl -tag -width "title=..."
 .It Cm anchor
-With
-.Fl n ,
-output line numbers
-as un-selectable anchor links.
-Incompatible with
-.Cm inline .
+Output tags
+(type and function definitions)
+as anchor links.
 .
 .It Cm css Ns = Ns Ar url
 With