|
|
@@ -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 |
|
|
|