Purpose: speed-read in place.
Usage: srip [file [index [delb [delm]]]]
Displays text from file, one word at a time, on the terminal, in a consistent location, and displays the index of that word just below the word itself. If index is given, srip starts displaying the file from that word index. The delay for each word is delm * wl + delb, where delm and delb come from arguments (0.02s and 0.1s, respectively) and wl is the length of the word, in characters.
Changelog:
2021-205 and before: initial development
2021-228 documentation added
2023-236 reformat/redocument a tad
Source code (perhaps slightly corrupted) is as follows.
local function sleep(t)
--[[
POSIX does not require `sleep` to support non-integer values,
but GNU Coreutils and Busybox implementations support it anyway,
so it Works On My Machine
]]
-- portable, but prevents ^C termination of srip
--os.execute("sleep " .. t)
-- not guaranteed, but allows ^C termination, and Works On My Machine
local h = io.popen("sleep " .. t)
h:close()
end
-- an argument is necessary to specify an input file
if not arg[1] then
io.stderr:write(arg[0] .. ": no input file given
")
os.exit(false)
end
-- input file shall be broken down into words
local words = {}
-- try to open input file
local fp = io.open(arg[1], "r")
if not fp then
io.stderr:write(arg[0] .. ": could not access file '" .. arg[1] .. "'
")
os.exit(false)
end
-- extract all the words
for line in fp:lines() do
line = line .. "
"
for word in line:gmatch("[^
]+") do
table.insert(words, word)
end
-- extra "word" for newlines
table.insert(words, "")
end
fp:close()
--[[
get numeric arguments, or use defaults
$2 is starting word index
$3 is minimum delay
$4 is delay added per character
]]
local swi = tonumber(arg[2]) or 1
local bd = tonumber(arg[3]) or 0.1
local dpc = tonumber(arg[4]) or 0.02
-- main display loop
for wi = swi, #words do
local cw = words[wi]
-- clear screen: ANSI
print("x1b[2Jx1b[H")
-- clear screen: XTerm-compatible (mintty), might not be portable/standard
--print("x1bc")
print(cw)
print(wi)
sleep(bd + dpc * #cw)
end