fix lines longer than the screen causing weird scrolling artifacts, and avoid superfluous history entries
This commit is contained in:
parent
88bce6cd96
commit
f83b8c999c
@ -257,11 +257,20 @@ function buffer:read(...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- ?????
|
-- this whole thing is a house of cards. good luck.
|
||||||
io.write("\27[s\27[8m")
|
io.write("\27[s\27[8m\27[6n")
|
||||||
local pos, buffer, hIndex = 1, "", 0
|
if not (self.mx or self.my) then
|
||||||
|
io.write("\27[9999;9999H\27[6n")
|
||||||
|
end
|
||||||
|
local pos, buffer, hIndex, sx, sy = 1, "", 0
|
||||||
self.history = self.history or {}
|
self.history = self.history or {}
|
||||||
local function redraw()
|
local function redraw()
|
||||||
|
-- scroll until the buffer will fit on the screen
|
||||||
|
while sx and sy and self.mx and self.my and #buffer > (self.mx * ((self.my - sy) + 1)) - sx do
|
||||||
|
sy = sy - 1
|
||||||
|
io.write("\27[9999;9999H ")
|
||||||
|
io.write(string.format("\27[2K\27[%i;%iH\27[s", sx, sy))
|
||||||
|
end
|
||||||
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
|
||||||
while true do
|
while true do
|
||||||
@ -300,6 +309,9 @@ function buffer:read(...)
|
|||||||
end
|
end
|
||||||
buffer = self.history[1+#self.history-hIndex] or buffer
|
buffer = self.history[1+#self.history-hIndex] or buffer
|
||||||
pos = 1
|
pos = 1
|
||||||
|
elseif char == "R" then -- cursor position report
|
||||||
|
self.mx, self.my = sx and math.max(self.mx or 0, args[1]) or self.mx, sy and math.max(self.my or 0, args[2]) or self.my
|
||||||
|
sx, sy = sx or args[1], sy or args[2]
|
||||||
end
|
end
|
||||||
hIndex = math.max(math.min(hIndex,#self.history),0)
|
hIndex = math.max(math.min(hIndex,#self.history),0)
|
||||||
end
|
end
|
||||||
@ -321,7 +333,7 @@ function buffer:read(...)
|
|||||||
pos = (nc and #buffer-nc+2) or 1
|
pos = (nc and #buffer-nc+2) or 1
|
||||||
elseif char == "\13" or char == "\10" or char == "\n" then -- return / newline
|
elseif char == "\13" or char == "\10" or char == "\n" then -- return / newline
|
||||||
io.write("\n")
|
io.write("\n")
|
||||||
self.history[#self.history+1] = buffer
|
self.history[#self.history+1] = buffer ~= "" and buffer ~= self.history[#self.history] and buffer or nil
|
||||||
if #self.history > (self.maxhistory or 16) then table.remove(self.history,1) end
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user