about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-07-05 21:57:36 +0200
committerbptato <nincsnevem662@gmail.com>2024-07-05 21:57:36 +0200
commitdf3838f373a688b0faffec7d8b98198661e7a3d7 (patch)
tree4f1296be4cc3cd182b84f53a9989fd95a3c43b0a
parent2c087d701becb78efc0d40ddbb82e11641df6643 (diff)
downloadchawan-df3838f373a688b0faffec7d8b98198661e7a3d7.tar.gz
main: misc improvements
-rw-r--r--res/chawan.html3
-rw-r--r--src/main.nim38
-rw-r--r--src/utils/sandbox.nim23
3 files changed, 50 insertions, 14 deletions
diff --git a/res/chawan.html b/res/chawan.html
index 43c093e8..06d0597a 100644
--- a/res/chawan.html
+++ b/res/chawan.html
@@ -105,8 +105,7 @@ beginning)
 of {char}
 <li><kbd>M-,</kbd>/<kbd>M-.</kbd>: previous/next sibling buffer
 <li><kbd>M-/</kbd>: parent buffer
-<li><kbd>{number}</kbd>, then movement: repeat movement n times<br>
-(or move to nth line, depending on command)
+<li><kbd>{number}</kbd>, then movement: repeat movement n times (or move to nth line, depending on command)
 <li><kbd>: (colon)</kbd>: convert URL-like strings to anchor tags
 <li><kbd>M-c</kbd>: input command
 <li><kbd>M-cM-c</kbd>: command mode (browser console)
diff --git a/src/main.nim b/src/main.nim
index e070597f..6a1e9b8f 100644
--- a/src/main.nim
+++ b/src/main.nim
@@ -12,17 +12,37 @@ import local/term
 import monoucha/javascript
 import server/forkserver
 import types/opt
+import utils/sandbox
 import utils/strwidth
 import utils/twtstr
 
+const ChaVersionStr0 = "Chawan browser v0.1"
+
 const ChaVersionStr = block:
-  var s = "Chawan browser v0.1 "
+  var s = ChaVersionStr0 & " ("
+  when defined(debug):
+    s &= "debug"
+  else:
+    s &= "release"
+  s &= ", "
+  when SandboxMode == stNone:
+    s &= "not sandboxed"
+  else:
+    s &= "sandboxed"
+  s & ")\n"
+
+const ChaVersionStrLong = block:
+  var s = ChaVersionStr0 & " ("
   when defined(debug):
-    s &= "(debug)"
+    s &= "debug"
+  else:
+    s &= "release"
+  s &= ", "
+  when SandboxMode == stNone:
+    s &= "not sandboxed"
   else:
-    s &= "(release)"
-  s &= '\n'
-  s
+    s &= "sandboxed by " & $SandboxMode
+  s & ")\n"
 
 proc help(i: int) =
   let s = ChaVersionStr & """
@@ -49,7 +69,7 @@ Options:
   quit(i)
 
 proc version() =
-  stdout.write(ChaVersionStr)
+  stdout.write(ChaVersionStrLong)
   quit(0)
 
 type ParamParseContext = object
@@ -86,7 +106,7 @@ proc getCharset(ctx: var ParamParseContext): Charset =
   let s = ctx.getnext()
   let charset = getCharset(s)
   if charset == CHARSET_UNKNOWN:
-    stderr.write("Unknown charset " & s & "\n")
+    stderr.writeLine("Unknown charset " & s)
     quit(1)
   return charset
 
@@ -186,14 +206,14 @@ proc main() =
   for opt in ctx.opts:
     let res = config.parseConfig(getCurrentDir(), opt, laxnames = true)
     if not res.success:
-      stderr.write(res.errorMsg)
+      stderr.writeLine(res.errorMsg)
       quit(1)
     warnings.add(res.warnings)
   config.css.stylesheet &= ctx.stylesheet
   block commands:
     let res = config.initCommands()
     if res.isNone:
-      stderr.write("Error parsing commands: " & res.error)
+      stderr.writeLine("Error parsing commands: " & res.error)
       quit(1)
   isCJKAmbiguous = config.display.double_width_ambiguous
   if ctx.pages.len == 0 and stdin.isatty():
diff --git a/src/utils/sandbox.nim b/src/utils/sandbox.nim
index a700ea2e..efc03e49 100644
--- a/src/utils/sandbox.nim
+++ b/src/utils/sandbox.nim
@@ -33,7 +33,24 @@
 
 const disableSandbox {.booldefine.} = false
 
-when defined(freebsd) and not disableSandbox:
+type SandboxType* = enum
+  stNone = "no sandbox"
+  stCapsicum = "capsicum"
+  stPledge = "pledge"
+  stLibSeccomp = "libseccomp"
+
+const SandboxMode* = when disableSandbox:
+  stNone
+elif defined(freebsd):
+  stCapsicum
+elif defined(openbsd):
+  stPledge
+elif defined(linux):
+  stLibSeccomp
+else:
+  stNone
+
+when SandboxMode == stCapsicum:
   import bindings/capsicum
 
   proc enterBufferSandbox*(sockPath: string) =
@@ -47,7 +64,7 @@ when defined(freebsd) and not disableSandbox:
     # no difference between buffer; Capsicum is quite straightforward
     # to use in this regard.
     discard cap_enter()
-elif defined(openbsd) and not disableSandbox:
+elif SandboxMode == stPledge:
   import bindings/pledge
 
   proc enterBufferSandbox*(sockPath: string) =
@@ -60,7 +77,7 @@ elif defined(openbsd) and not disableSandbox:
   proc enterNetworkSandbox*() =
     # we don't need much to write out data from sockets to stdout.
     doAssert pledge("stdio", nil) == 0
-elif defined(linux) and not disableSandbox:
+elif SandboxMode == stLibSeccomp:
   import std/posix
   import bindings/libseccomp