From 0db31a2e27de033062bc43197ecf54a36c506812 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Fri, 21 Aug 2020 10:18:43 +1000 Subject: [PATCH] added some more keyboard shortcuts to io.read linemode --- module/buffer.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/module/buffer.lua b/module/buffer.lua index b6805a3..7536f35 100644 --- a/module/buffer.lua +++ b/module/buffer.lua @@ -303,11 +303,21 @@ function buffer:read(...) end hIndex = math.max(math.min(hIndex,#self.history),0) end - elseif char == "\8" then + elseif char == "\8" then -- backspace if #buffer > 0 and pos <= #buffer then buffer = buffer:sub(1, (#buffer - pos)) .. buffer:sub((#buffer - pos) + 2) end - elseif char == "\13" or char == "\10" or char == "\n" then + elseif char == "\1" then -- ^A, go to start of line + pos = buffer:len()+1 + elseif char == "\5" then -- ^E, go to end of line + pos = 1 + elseif char == "\2" then -- ^B, back one word + local nc = buffer:reverse():find(" ",pos+1) + pos = nc or #buffer+1 + elseif char == "\6" then -- ^F, forward one word + local nc = buffer:find(" ",math.max(#buffer-pos+3,0)) + pos = (nc and #buffer-nc+2) or 1 + elseif char == "\13" or char == "\10" or char == "\n" then -- return / newline io.write("\n") self.history[#self.history+1] = buffer if #self.history > (self.maxhistory or 16) then table.remove(self.history,1) end