about summary refs log tree commit diff stats
path: root/doc
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-02-13 21:16:12 +0100
committerbptato <nincsnevem662@gmail.com>2024-02-25 02:46:21 +0100
commit6e98894199442e2213dc89e0c5fe970029f05b65 (patch)
tree57bf69a6fa825d72be1654482e8865b5e9b82829 /doc
parentd41d4803b5ed15b7e8461394ee07ce5ab1de143a (diff)
downloadchawan-6e98894199442e2213dc89e0c5fe970029f05b65.tar.gz
Separate ANSI text decoding from main binary
Handling text/plain as ANSI colored text was problematic for two
reasons:

* You couldn't actually look at the real source of HTML pages or text
  files that used ANSI colors in the source.  In general, I only want
  ANSI colors when piping something into my pager, not when viewing any
  random file.
* More importantly, it introduced a separate rendering mode for
  plaintext documents, which resulted in the problem that only some
  buffers had DOMs.  This made it impossible to add functionality
  that would operate on the buffer's DOM, to e.g. implement w3m's
  MARK_URL.  Also, it locked us into the horribly inefficient line-based
  rendering model of entire documents.

Now we solve the problem in two separate parts:

* text/x-ansi is used automatically for documents received through
  stdin. A text/x-ansi handler ansi2html converts ANSI formatting to
  HTML.  text/x-ansi is also used for .ans, .asc file extensions.
* text/plain is a separate input mode in buffer, which places all text
  in a single <plaintext> tag.  Crucially, this does not invoke the HTML
  parser; that would eat NUL characters, which we should avoid.

One blind spot still remains: copiousoutput used to display ANSI colors,
and now it doesn't. To solve this, users can put the x-ansioutput
extension field to their mailcap entries, which behaves like
x-htmloutput except it first pipes the output into ansi2html.
Diffstat (limited to 'doc')
-rw-r--r--doc/mailcap.md16
1 files changed, 10 insertions, 6 deletions
diff --git a/doc/mailcap.md b/doc/mailcap.md
index e4dc41bc..de8abeaf 100644
--- a/doc/mailcap.md
+++ b/doc/mailcap.md
@@ -52,16 +52,20 @@ execution of every mailcap command.
 ### Fields
 
 The `test`, `nametemplate`, `needsterminal` and `copiousoutput` fields are
-recognized. Additionally, the non-standard `x-htmloutput` extension field
-is recognized too.
+recognized. Additionally, the non-standard `x-htmloutput` and `x-ansioutput`
+extension fields are recognized too.
 
 * When the `test` named field is specified, the mailcap entry is only used
   if the test command returns 0.  
   Warning: as of now, %s does not work with test.
 * `copiousoutput` makes Chawan redirect the output of the external command
-  into a new buffer.
+  into a new buffer. If either x-htmloutput or x-ansioutput is defined too, then
+  it is ignored.
 * The `x-htmloutput` extension field behaves the same as `copiousoutput`,
   but makes Chawan interpret the command's output as HTML.
+* `x-ansioutput` makes Chawan pipe the output through the default "text/x-ansi"
+  content type handler. This means that you get colors, formatting, etc.
+  displayed with ANSI escape sequences.
 * `needsterminal` hands over control of the terminal to the command while
   it is running. Note: as of now, `needsterminal` does nothing if either
   `copiousoutput` or `x-htmloutput` is specified.
@@ -80,7 +84,7 @@ it could have been piped into the command.
 
 ## Note
 
-Entries with a content type of text/html are ignored.
+Entries with a content type of text/html or text/plain are ignored.
 
 ## Examples
 
@@ -92,7 +96,7 @@ Entries with a content type of text/html are ignored.
 text/markdown; pandoc - -f markdown -t html -o -; x-htmloutput
 
 # Show syntax highlighting for JavaScript source files using bat.
-text/javascript; bat -f -l es6 --file-name ${MAILCAP_URL:-STDIN} -; copiousoutput
+text/javascript; bat -f -l es6 --file-name ${MAILCAP_URL:-STDIN} -; x-ansioutput
 
 # Play music using mpv, and hand over control of the terminal until mpv exits.
 audio/*; mpv -; needsterminal
@@ -110,7 +114,7 @@ application/vnd.openxmlformats-officedocument.wordprocessingml.document;lowriter
 application/x-troff-man;pandoc - -f man -t html -o -; x-htmloutput
 
 # Following entry will be ignored, as text/html is supported natively by Chawan.
-text/html; cha -T text/html -I %{charset}; copiousoutput
+text/html; cha -dT text/html -I %{charset}; copiousoutput
 ```
 <!-- MANON
 ## See also