aboutsummaryrefslogtreecommitdiff
path: root/tecat.lua
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2025-10-06 00:48:48 +0300
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2025-10-06 00:48:48 +0300
commitad9e7cd5117c965222aae708f660e56d537914fc (patch)
tree580006656ec76513500170e5646e92e7819c6c0b /tecat.lua
downloadsnippets-ad9e7cd5117c965222aae708f660e56d537914fc.tar.gz
imported all of my Github gists from https://gist.github.com/rhaberkorn
Diffstat (limited to 'tecat.lua')
-rwxr-xr-xtecat.lua14
1 files changed, 14 insertions, 0 deletions
diff --git a/tecat.lua b/tecat.lua
new file mode 100755
index 0000000..e287658
--- /dev/null
+++ b/tecat.lua
@@ -0,0 +1,14 @@
+#!/usr/local/bin/lua52
+-- Replace all control characters with printable representations as in SciTECO.
+-- These characters are printed in reverse using ANSI escape sequences.
+-- This is especially useful as the diff textconv filter for Git as in
+-- git config --global diff.teco.textconv tecat
+local file = #arg > 0 and io.open(arg[1], 'rb') or io.stdin
+while true do
+ local buf = file:read(1024)
+ if not buf then break end
+ io.write((buf:gsub("[\00-\08\11\12\14-\31]", function(c)
+ c = c:byte()
+ return "\27[7m"..(c == 27 and '$' or '^'..string.char(c+0x40)).."\27[27m"
+ end)))
+end