Przeglądaj źródła

added history support to buffer:read() in terminal mode, do provide feedback

master
XeonSquared 3 lat temu
rodzic
commit
0421034ff7
1 zmienionych plików z 14 dodań i 1 usunięć
  1. +14
    -1
      module/buffer.lua

+ 14
- 1
module/buffer.lua Wyświetl plik

@@ -259,7 +259,8 @@ function buffer:read(...)
else
-- ?????
io.write("\27[s\27[8m")
local pos, buffer = 1, ""
local pos, buffer, hIndex = 1, "", 0
self.history = self.history or {}
local function redraw()
io.write(string.format("\27[u%s \27[u\27[%iC",buffer,(#buffer-pos)+1))
end
@@ -285,6 +286,16 @@ function buffer:read(...)
if pos <= #buffer then
pos = pos + 1
end
elseif char == "A" then -- up
hIndex = hIndex + 1
io.write("\27[u"..(" "):rep(buffer:len()+1))
buffer = self.history[1+#self.history-hIndex] or buffer
pos = 1
elseif char == "B" then -- down
hIndex = hIndex - 1
io.write("\27[u"..(" "):rep(buffer:len()+1))
buffer = self.history[1+#self.history-hIndex] or buffer
pos = 1
end
end
elseif char == "\8" then
@@ -293,6 +304,8 @@ function buffer:read(...)
end
elseif char == "\13" or char == "\10" or char == "\n" then
io.write("\n")
self.history[#self.history+1] = buffer
if #self.history > (self.maxhistory or 16) then table.remove(self.history,1) end
if chop then buffer = buffer .. "\n" end
return buffer
else


Ładowanie…
Anuluj
Zapisz