about summary refs log tree commit diff stats
path: root/src/io/dynstream.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-12-11 18:37:26 +0100
committerbptato <nincsnevem662@gmail.com>2024-12-11 19:40:26 +0100
commitd4c40ab5c1c1fe2df49f54d61632c1c979e63514 (patch)
treee1fcdc92d4559884c6bb22cf4d7c4b48d0e25039 /src/io/dynstream.nim
parentf2454bf6ecd79f454c54b5ccd2cdcc513d232c4b (diff)
downloadchawan-d4c40ab5c1c1fe2df49f54d61632c1c979e63514.tar.gz
pager, mailcap: misc fixes, add prompt for global mailcap
In the past, Chawan would read global mailcap (/etc/mailcap, ...) too,
but every now and then that would run entries that I didn't even know
existed and definitely didn't intend to run.  So I changed it to only
use ~/.mailcap, but this meant users now had to add mailcap entries for
every single mime type.

At some point I also changed application/octet-stream to always save to
disk, which is usually nice except when a text file is misrecognized as
binary.  Often times I just want to decide myself what to do.

So now there are two layers.  First, the global mailcap files (path as
per RFC) prompt before executing.  Then there is ~/.chawan/auto.mailcap
(or ~/.config/chawan/auto.mailcap) which runs entries automatically.

If you press shift before selecting an option in the prompt, the
corresponding entry gets copied to auto.mailcap.  It's also possible to
type a new entry on the fly.  Overall I think it's quite convenient.

One unfortunate side effect is that existing users will have to migrate
their entries to auto.mailcap, or redefine external.auto-mailcap to e.g.
~/.mailcap, but this seems acceptable.
Diffstat (limited to 'src/io/dynstream.nim')
-rw-r--r--src/io/dynstream.nim7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/io/dynstream.nim b/src/io/dynstream.nim
index 8b917b98..8117d22b 100644
--- a/src/io/dynstream.nim
+++ b/src/io/dynstream.nim
@@ -320,15 +320,12 @@ proc maybeMmapForSend*(ps: PosixStream; len: int): MaybeMappedMemory =
   return res
 
 template toOpenArray*(mem: MaybeMappedMemory): openArray[char] =
-  if mem.len > 0:
-    cast[ptr UncheckedArray[char]](mem.p).toOpenArray(0, mem.len - 1)
-  else:
-    []
+  cast[ptr UncheckedArray[char]](mem.p).toOpenArray(0, mem.len - 1)
 
 proc sendDataLoop*(ps: PosixStream; mem: MaybeMappedMemory) =
   # only send if not mmapped; otherwise everything is already where it should be
   if mem.t != mmmtMmap:
-    ps.sendDataLoop(mem.p, mem.len)
+    ps.sendDataLoop(mem.toOpenArray())
 
 template dealloc*(mem: MaybeMappedMemory) {.error: "use deallocMem".} = discard