From 71af803e1696cd87177ca3e9b16778288b75c69b Mon Sep 17 00:00:00 2001 From: bptato Date: Thu, 21 Mar 2024 16:35:44 +0100 Subject: ansi2html: add separate switch for "standalone" this way its output can be embedded into documents without a pointless DT declaration --- adapter/format/ansi2html.nim | 8 +++++++- bonus/git.cgi | 2 +- res/mailcap | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/adapter/format/ansi2html.nim b/adapter/format/ansi2html.nim index fe8deef4..2906e076 100644 --- a/adapter/format/ansi2html.nim +++ b/adapter/format/ansi2html.nim @@ -1,4 +1,5 @@ import std/options +import std/os import std/selectors import io/posixstream @@ -357,7 +358,10 @@ proc processData(state: var State, buf: openArray[char]) = proc main() = let ps = newPosixStream(stdin.getFileHandle()) var state = State(os: newPosixStream(stdout.getFileHandle())) - state.puts("\n
")
+  let standalone = paramCount() >= 1 and paramStr(1) == "-s"
+  if standalone:
+    state.puts("\n")
+  state.puts("
")
   ps.setBlocking(false)
   var buffer {.noinit.}: array[4096, char]
   var selector = newSelector[int]()
@@ -373,6 +377,8 @@ proc main() =
         selector.registerHandle(ps.fd, {Read}, 0)
         discard selector.select(-1)
         selector.unregister(ps.fd)
+  if standalone:
+    state.puts("")
   state.flushOutbuf()
 
 main()
diff --git a/bonus/git.cgi b/bonus/git.cgi
index 9038f332..5bbf12a3 100755
--- a/bonus/git.cgi
+++ b/bonus/git.cgi
@@ -54,7 +54,7 @@ if (params[0] == "log") {
 	const cgi = `${query.prefix}git.cgi?prefix=${query.prefix}&path=${query.path}¶ms=show`;
 	const titleParams = params.join(' ').replace(/[&<>]/g,
 		x => ({'&': '&', '<': '<', '>': '>'}[x]));
-	console.log(`git ${titleParams}`);
+	console.log(`\ngit ${titleParams}`);
 	while ((l = f.getline()) !== null) {
 		console.log(l.replace(/[a-f0-9]{40}/g,
 			x => `${x}`));
diff --git a/res/mailcap b/res/mailcap
index 07ac93f7..4d6619d7 100644
--- a/res/mailcap
+++ b/res/mailcap
@@ -3,4 +3,4 @@
 text/gopher;	"$CHA_LIBEXEC_DIR"/gopher2html -u "$MAILCAP_URL"; x-htmloutput
 text/gemini;	"$CHA_LIBEXEC_DIR"/gmi2html; x-htmloutput
 text/markdown;	"$CHA_LIBEXEC_DIR"/md2html; x-htmloutput
-text/x-ansi;	"$CHA_LIBEXEC_DIR"/ansi2html; x-htmloutput
+text/x-ansi;	"$CHA_LIBEXEC_DIR"/ansi2html -s; x-htmloutput
-- 
cgit 1.4.1-2-gfad0