about summary refs log tree commit diff stats
path: root/adapter/format
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-03-21 16:35:44 +0100
committerbptato <nincsnevem662@gmail.com>2024-03-21 16:35:44 +0100
commit71af803e1696cd87177ca3e9b16778288b75c69b (patch)
treef68346dd8a3a549e4359e0d7db16caea9bc6fa59 /adapter/format
parente4463ecb7c435894c5a67a3377823ab0f991a191 (diff)
downloadchawan-71af803e1696cd87177ca3e9b16778288b75c69b.tar.gz
ansi2html: add separate switch for "standalone"
this way its output can be embedded into documents without a pointless
DT declaration
Diffstat (limited to 'adapter/format')
-rw-r--r--adapter/format/ansi2html.nim8
1 files changed, 7 insertions, 1 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("<!DOCTYPE html>\n<body><pre style='margin: 0'>")
+  let standalone = paramCount() >= 1 and paramStr(1) == "-s"
+  if standalone:
+    state.puts("<!DOCTYPE html>\n<body>")
+  state.puts("<pre style='margin: 0'>")
   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("</body>")
   state.flushOutbuf()
 
 main()