about summary refs log tree commit diff stats
path: root/src/config
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-12-10 17:15:18 +0100
committerbptato <nincsnevem662@gmail.com>2023-12-10 17:29:41 +0100
commit48b197133783bf7ec7211b1e114b6ca73f36a3c6 (patch)
treeb1bbc4ddec8791022f04b11587c1aee3c7b1656a /src/config
parent2dec7483045c9e5696182db7b4ad842491b6c2b2 (diff)
downloadchawan-48b197133783bf7ec7211b1e114b6ca73f36a3c6.tar.gz
Separate gopher conversion from main binary
Now we use a (much simplified) gopher2html binary in libexec,
instead of converting gopher directories to HTML in loader/gopher.

This has two advantages:
* Less ugly conversion logic in the loader module; we can just
  convert the file line by line. (The previous converter also had
  some correctness issues, that is fixed now as well.)
* If the user desires, they can replace the gopher converter with
  another binary using the mailcap mechanism.

The disadvantages are:
* For now, source display is broken. This is a problem with all
  mailcap filters in general, and should be fixed in the future. (That
  said, the previous version also only displayed the converted HTML
  source, which was not really useful anyway.)
* The proper directory structure is required for this to work;
  OTOH plenty of work has been done so that this is as frictionless as
  possible, so it should not really be a problem.
Diffstat (limited to 'src/config')
-rw-r--r--src/config/chapath.nim5
-rw-r--r--src/config/config.nim14
2 files changed, 18 insertions, 1 deletions
diff --git a/src/config/chapath.nim b/src/config/chapath.nim
index caaf9435..8f1ff539 100644
--- a/src/config/chapath.nim
+++ b/src/config/chapath.nim
@@ -9,6 +9,8 @@ import js/tojs
 import types/opt
 import utils/twtstr
 
+const libexecPath {.strdefine.} = "${%CHA_BIN_DIR}/../libexec/chawan"
+
 type ChaPath* = distinct string
 
 func `$`*(p: ChaPath): string =
@@ -34,6 +36,7 @@ type
 
   ChaPathResult[T] = Result[T, ChaPathError]
 
+proc unquote*(p: ChaPath): ChaPathResult[string]
 proc unquote(p: string, starti: var int, terminal: Option[char]):
     ChaPathResult[string]
 
@@ -181,6 +184,8 @@ proc stateCurlyPerc(ctx: var UnquoteContext, c: char): ChaPathResult[void] =
   if c == '}':
     if ctx.identStr == "CHA_BIN_DIR":
       ctx.s &= getAppFileName().beforeLast('/')
+    elif ctx.identStr == "CHA_LIBEXEC_DIR":
+      ctx.s &= ?ChaPath(libexecPath).unquote()
     else:
       return err("Unknown internal variable " & ctx.identStr)
     ctx.identStr = ""
diff --git a/src/config/config.nim b/src/config/config.nim
index 1274e731..ae4a8f85 100644
--- a/src/config/config.nim
+++ b/src/config/config.nim
@@ -350,7 +350,14 @@ proc readUserStylesheet(dir, file: string): string =
 # of several individual configuration files known as mailcap files.
 proc getMailcap*(config: Config): tuple[mailcap: Mailcap, errs: seq[string]] =
   let configDir = getConfigDir() / "chawan" #TODO store this in config?
-  var mailcap: Mailcap
+  const gopherPath0 = ChaPath("${%CHA_LIBEXEC_DIR}/gopher2html -u %u")
+  let gopherPath = gopherPath0.unquote().get
+  var mailcap = @[MailcapEntry(
+    mt: "text",
+    subt: "gopher",
+    cmd: gopherPath,
+    flags: {HTMLOUTPUT}
+  )]
   var errs: seq[string]
   var found = false
   for p in config.external.mailcap:
@@ -363,6 +370,11 @@ proc getMailcap*(config: Config): tuple[mailcap: Mailcap, errs: seq[string]] =
         errs.add(res.error)
       found = true
   if not found:
+    mailcap.insert(MailcapEntry(
+      mt: "*",
+      subt: "*",
+      cmd: "xdg-open '%s'"
+    ), 0)
     return (DefaultMailcap, errs)
   return (mailcap, errs)