Skip to content

Commit

Permalink
pseudo win cmd ;)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugeping committed Sep 14, 2023
1 parent e620ee2 commit d53160d
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion data/lib/red/proc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ local function pipe(w, prog, tmp)
f:close()
w:history 'end'
-- w.buf:setsel(cur, w:cur())
w:cur(cur)
-- w:cur(cur)
if tmp then
os.remove(tmp)
end
Expand Down Expand Up @@ -258,6 +258,31 @@ function proc.Clear(w)
w.buf:setsel(1, #w.buf.text + 1)
w.buf:cut()
w.buf.cur = 1
w:visible()
end

function win_newline(self)
self.buf:linestart()
local t = ''
for i = self.buf.cur, #self.buf.text do
t = t .. self.buf.text[i]
end
self.buf:lineend()
self.buf:input '\n'
local cmd = t:split(1)
if cmd[1] == 'cd' and #cmd == 2 then
local r, e = sys.chdir(cmd[2])
if not r then
self.buf:input("Error\n")
end
else
pipe(self, t)
end
end

function proc.win(w)
w = w:output("+win")
w.newline = win_newline
end

--luacheck: pop
Expand Down

0 comments on commit d53160d

Please sign in to comment.