1
1
mirror of https://git.shadowkat.net/izaya/OC-PsychOS2.git synced 2024-11-25 12:42:10 -05:00

Compare commits

..

5 Commits

Author SHA1 Message Date
XeonSquared
c5f304380e one more try 2020-08-21 10:38:18 +10:00
XeonSquared
0aaf4acd52 apply the right separator for concat 2020-08-21 10:37:19 +10:00
XeonSquared
d15a841316 made ed.open use the full path for the file 2020-08-21 10:35:48 +10:00
XeonSquared
d12ec38016 made vi not choke when opening a new file, as well as actually preserve the file name 2020-08-21 10:28:51 +10:00
XeonSquared
0db31a2e27 added some more keyboard shortcuts to io.read linemode 2020-08-21 10:18:43 +10:00
2 changed files with 17 additions and 4 deletions

View File

@ -112,6 +112,7 @@ function ed.newBuffer()
end
function ed.open(buffer)
local bpath = buffer
if ed.buffers[buffer] then
buffer = ed.buffers[buffer]
end
@ -120,7 +121,9 @@ function ed.open(buffer)
nb:load(buffer)
buffer = nb
end
if type(buffer) ~= "table" then buffer = ed.newBuffer() buffer[1] = "" end
if type(buffer) ~= "table" then buffer = ed.newBuffer() end
buffer[1] = buffer[1] or ""
buffer.path = buffer.path or "/"..((bpath:sub(1,1) == "/" and table.concat(fs.segments(path),"/")) or table.concat(fs.segments(os.getenv("PWD").."/"..bpath),"/"))
return buffer
end

View File

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