blob: e2876583cfdb940a8e6d87c7b9b0ac39a60c0522 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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
|