[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-zile] Converting interactive tests to split up keystrokes
From: |
Reuben Thomas |
Subject: |
[Bug-zile] Converting interactive tests to split up keystrokes |
Date: |
Mon, 17 Sep 2012 23:12:46 +0100 |
Another useful disposable script:
-- N.B. keyname must be made non-local to make this work!
-- Extract a prefix of a key string.
local function strtokey (s)
local head
for _, match in pairs (keyname) do
if match == s:sub (1, #match) then
head = match
return head, s:sub (#head + 1)
end
end
return s[1], s:sub (2)
end
local function keychords (s)
local tail = s
local function strtochord (tail)
local head, fragment = ""
repeat
fragment, tail = strtokey (tail)
if fragment == nil then return nil end
head = head .. fragment
until fragment ~= "C-" and fragment ~= "M-"
return head, tail
end
return function ()
while tail ~= "" do
local head
head, tail = strtochord (tail)
return head
end
end
end
function keystrtovec (s)
local keys = {}
for chord in keychords (s) do
table.insert (keys, keycode (chord))
end
return keys
end
for i, lua_file in ipairs (arg) do
posix.chdir ("/home/rrt/Software/zile-zee")
if i > 3 then
local out = {}
for l in io.lines (lua_file) do
local s = l:match ("^macro_play %(\"(.*)\"%)")
if s then
s = s:gsub ("\\\\", "\\")
s = s:gsub ("\\r", "RET")
s = s:gsub ("\\e", "ESC")
s = s:gsub ("\\([A-Z\\])", "%1")
local t = list.map (tostring, keystrtovec (s))
l = "macro_play (\"" .. table.concat (t, "\", \"") .. "\")"
end
table.insert (out, l)
end
os.execute ("cp -n " .. lua_file .. " " .. lua_file:gsub ("%.lua",
".lua.bak"))
local h = io.open (lua_file, "w")
for _, l in ipairs (out) do h:write (l:gsub ("\\", "\\\\") .. "\n") end
h:close ()
end
end
--
http://rrt.sc3d.org
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug-zile] Converting interactive tests to split up keystrokes,
Reuben Thomas <=