added history support to buffer:read() in terminal mode, do provide feedback
This commit is contained in:
parent
e3069f94a3
commit
0421034ff7
@ -259,7 +259,8 @@ function buffer:read(...)
|
|||||||
else
|
else
|
||||||
-- ?????
|
-- ?????
|
||||||
io.write("\27[s\27[8m")
|
io.write("\27[s\27[8m")
|
||||||
local pos, buffer = 1, ""
|
local pos, buffer, hIndex = 1, "", 0
|
||||||
|
self.history = self.history or {}
|
||||||
local function redraw()
|
local function redraw()
|
||||||
io.write(string.format("\27[u%s \27[u\27[%iC",buffer,(#buffer-pos)+1))
|
io.write(string.format("\27[u%s \27[u\27[%iC",buffer,(#buffer-pos)+1))
|
||||||
end
|
end
|
||||||
@ -285,6 +286,16 @@ function buffer:read(...)
|
|||||||
if pos <= #buffer then
|
if pos <= #buffer then
|
||||||
pos = pos + 1
|
pos = pos + 1
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
elseif char == "\8" then
|
elseif char == "\8" then
|
||||||
@ -293,6 +304,8 @@ function buffer:read(...)
|
|||||||
end
|
end
|
||||||
elseif char == "\13" or char == "\10" or char == "\n" then
|
elseif char == "\13" or char == "\10" or char == "\n" then
|
||||||
io.write("\n")
|
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
|
if chop then buffer = buffer .. "\n" end
|
||||||
return buffer
|
return buffer
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user