about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--adapter/format/img2html.nim22
-rw-r--r--doc/config.md7
-rw-r--r--res/chawan.html2
-rw-r--r--res/mailcap8
5 files changed, 40 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index d4d2d03b..703bf48e 100644
--- a/Makefile
+++ b/Makefile
@@ -59,6 +59,7 @@ all: $(OUTDIR_BIN)/cha $(OUTDIR_BIN)/mancha $(OUTDIR_CGI_BIN)/http \
 	$(OUTDIR_CGI_BIN)/finger $(OUTDIR_CGI_BIN)/about \
 	$(OUTDIR_CGI_BIN)/file $(OUTDIR_CGI_BIN)/ftp $(OUTDIR_CGI_BIN)/sftp \
 	$(OUTDIR_LIBEXEC)/dirlist2html $(OUTDIR_LIBEXEC)/uri2html \
+	$(OUTDIR_LIBEXEC)/img2html \
 	$(OUTDIR_CGI_BIN)/man $(OUTDIR_CGI_BIN)/spartan \
 	$(OUTDIR_CGI_BIN)/stbi $(OUTDIR_CGI_BIN)/jebp $(OUTDIR_CGI_BIN)/canvas \
 	$(OUTDIR_CGI_BIN)/nanosvg $(OUTDIR_CGI_BIN)/sixel $(OUTDIR_CGI_BIN)/resize \
@@ -129,6 +130,7 @@ $(OUTDIR_LIBEXEC)/gopher2html: $(twtstr)
 $(OUTDIR_LIBEXEC)/ansi2html: src/types/color.nim src/io/poll.nim $(twtstr) $(dynstream)
 $(OUTDIR_LIBEXEC)/md2html: $(twtstr)
 $(OUTDIR_LIBEXEC)/dirlist2html: $(twtstr)
+$(OUTDIR_LIBEXEC)/img2html: $(twtstr)
 
 $(OUTDIR_CGI_BIN)/%: adapter/protocol/%.nim
 	@mkdir -p "$(OUTDIR_CGI_BIN)"
@@ -190,7 +192,7 @@ manpage: $(manpages:%=doc/%)
 
 protocols = http about file ftp sftp gopher gemini finger man spartan stbi \
 	jebp sixel canvas resize chabookmark nanosvg
-converters = gopher2html md2html ansi2html gmi2html dirlist2html uri2html
+converters = gopher2html md2html ansi2html gmi2html dirlist2html uri2html img2html
 tools = urlenc nc
 
 .PHONY: install
diff --git a/adapter/format/img2html.nim b/adapter/format/img2html.nim
new file mode 100644
index 00000000..29604805
--- /dev/null
+++ b/adapter/format/img2html.nim
@@ -0,0 +1,22 @@
+import std/os
+
+import utils/twtstr
+
+proc main() =
+  if paramCount() != 2:
+    stderr.writeLine("Usage: img2html [content-type] [title]")
+    quit(1)
+  stdout.write("<!DOCTYPE html><title>" & paramStr(2).htmlEscape() &
+    "</title><img src='data:" & paramStr(1) & ";base64,")
+  var buffer {.noinit.}: array[6144, uint8]
+  var s = ""
+  while true:
+    let n = stdin.readBuffer(addr buffer[0], buffer.len)
+    if n == 0:
+      break
+    s.btoa(buffer.toOpenArray(0, n - 1))
+    stdout.write(s)
+    s.setLen(0)
+  stdout.write("'>")
+
+main()
diff --git a/doc/config.md b/doc/config.md
index 2b5cf816..45516a80 100644
--- a/doc/config.md
+++ b/doc/config.md
@@ -1370,6 +1370,13 @@ line.</td>
 </tr>
 
 <tr>
+<td><kbd>I</kbd></td>
+<td>`cmd.buffer.viewImage`</td>
+<td>View the image currently under the cursor in an external
+viewer.</td>
+</tr>
+
+<tr>
 <td><kbd>R</kbd></td>
 <td>`cmd.buffer.reshape`</td>
 <td>Reshape the current buffer (=render the current page anew.) Useful
diff --git a/res/chawan.html b/res/chawan.html
index 81349271..f7a39838 100644
--- a/res/chawan.html
+++ b/res/chawan.html
@@ -91,7 +91,7 @@ beginning)
 <li><kbd>sE</kbd>: see source in editor
 <li><kbd>sS</kbd>: save current page's source
 <li><kbd>sI</kbd>: save image
-<li><kbd>s{return/enter key}</kbd>: save page that anchor (link) points to
+<li><kbd>s{enter key}</kbd>: save page that link points to
 <li><kbd>0</kbd>: cursor to first cell on line
 <li><kbd>^</kbd>: cursor to first non-whitespace on line
 <li><kbd>$</kbd>: cursor to last character on line
diff --git a/res/mailcap b/res/mailcap
index e0e2b503..647596ac 100644
--- a/res/mailcap
+++ b/res/mailcap
@@ -1,8 +1,14 @@
 # default mailcap for Chawan
 
-text/gopher;	"$CHA_LIBEXEC_DIR"/gopher2html -u "$MAILCAP_URL"; x-htmloutput
+text/gopher;	"$CHA_LIBEXEC_DIR"/gopher2html -u '%u'; x-htmloutput
 text/gemini;	"$CHA_LIBEXEC_DIR"/gmi2html; x-htmloutput; x-needsstyle
 text/markdown;	"$CHA_LIBEXEC_DIR"/md2html; x-htmloutput
 text/x-ansi;	"$CHA_LIBEXEC_DIR"/ansi2html -st '%{title}'; x-htmloutput; x-needsstyle
 text/x-dirlist;	"$CHA_LIBEXEC_DIR"/dirlist2html -t '%{title}'; x-htmloutput
 text/uri-list;	"$CHA_LIBEXEC_DIR"/uri2html '%{title}'; x-htmloutput
+image/png;	"$CHA_LIBEXEC_DIR"/img2html '%t' '%u'; x-htmloutput
+image/jpeg;	"$CHA_LIBEXEC_DIR"/img2html '%t' '%u'; x-htmloutput
+image/bmp;	"$CHA_LIBEXEC_DIR"/img2html '%t' '%u'; x-htmloutput
+image/gif;	"$CHA_LIBEXEC_DIR"/img2html '%t' '%u'; x-htmloutput
+image/webp;	"$CHA_LIBEXEC_DIR"/img2html '%t' '%u'; x-htmloutput
+image/svg+xml;	"$CHA_LIBEXEC_DIR"/img2html '%t' '%u'; x-htmloutput