1
0
mirror of https://github.com/20kdc/OC-KittenOS.git synced 2024-11-23 10:58:06 +11:00

A bit of terminal polish

This commit is contained in:
20kdc 2020-04-02 01:52:25 +01:00
parent a585ce4a75
commit 7d1f6d2cae
2 changed files with 105 additions and 48 deletions

View File

@ -32,45 +32,61 @@ event.listen("k.procdie", function (_, _, pid)
end end
end) end)
TERM.write("KittenOS NEO Lua Shell\r\n") TERM.write(([[
KittenOS NEO Shell Usage Notes
print = function (...) Prefixing = is an alias for 'return '.
local n = {} io.read(): Reads a line.
local s = {...} print: 'print with table dumping' impl.
for i = 1, #s do TERM: Your terminal. (see us-termi doc.)
local v = s[i] os.execute(): launch terminal apps!
if v == nil then tries '*', 'sys-t-*', 'svc-t-*', 'app-*'
v = "nil" example: os.execute("luashell")
os.exit(): quit the shell
=listCmdApps(): -t- (terminal) apps
event: useful for setting up listeners
without breaking shell functionality
]]):gsub("[\r]*\n", "\r\n"))
function listCmdApps()
local apps = {}
for _, v in ipairs(neo.listApps()) do
if v:sub(4, 6) == "-t-" then
table.insert(apps, v)
end end
table.insert(n, tostring(v))
end end
TERM.write(table.concat(n, " ") .. "\r\n") return apps
end end
run = function (x, ...) local function vPrint(slike, ...)
local subPid = neo.executeAsync(x, ...) local s = {...}
if not subPid then if #s > 1 then
subPid = neo.executeAsync("sys-t-" .. x, TERM.id, ...) for i = 1, #s do
end if i ~= 1 then TERM.write("\t") end
if not subPid then vPrint(slike, s[i])
subPid = neo.executeAsync("svc-t-" .. x, TERM.id, ...)
end
if not subPid then
subPid = neo.executeAsync("app-" .. x, TERM.id, ...)
end
if not subPid then
error("cannot find " .. x)
end
while true do
local e = {event.pull()}
if e[1] == "k.procdie" then
if e[3] == subPid then
return
end
end end
elseif slike and type(s[1]) == "string" then
TERM.write("\"" .. s[1] .. "\"")
elseif type(s[1]) ~= "table" then
TERM.write(tostring(s[1]))
else
TERM.write("{")
for k, v in pairs(s[1]) do
TERM.write("[")
vPrint(true, k)
TERM.write("] = ")
vPrint(true, v)
TERM.write(", ")
end
TERM.write("}")
end end
end end
print = function (...)
vPrint(false, ...)
TERM.write("\r\n")
end
local ioBuffer = "" local ioBuffer = ""
io = { io = {
@ -98,10 +114,34 @@ os = setmetatable({}, {
__index = originalOS __index = originalOS
}) })
os.exit = function () function os.exit()
alive = false alive = false
end end
function os.execute(x, ...)
local subPid = neo.executeAsync(x, TERM.id, ...)
if not subPid then
subPid = neo.executeAsync("sys-t-" .. x, TERM.id, ...)
end
if not subPid then
subPid = neo.executeAsync("svc-t-" .. x, TERM.id, ...)
end
if not subPid then
subPid = neo.executeAsync("app-" .. x, TERM.id, ...)
end
if not subPid then
error("cannot find " .. x)
end
while true do
local e = {event.pull()}
if e[1] == "k.procdie" then
if e[3] == subPid then
return
end
end
end
end
while alive do while alive do
TERM.write("> ") TERM.write("> ")
local code = io.read() local code = io.read()

View File

@ -127,6 +127,10 @@ local function writeData(data)
local char = unicode.sub(data, 1, 1) local char = unicode.sub(data, 1, 1)
data = unicode.sub(data, 2) data = unicode.sub(data, 2)
-- handle character -- handle character
if char == "\t" then
-- not ideal, but allowed
char = " "
end
if char == "\r" then if char == "\r" then
conCX = 1 conCX = 1
elseif char == "\n" then elseif char == "\n" then
@ -254,21 +258,45 @@ do
end end
end end
local control = false
local function key(a, c) local function key(a, c)
if control then
if e[5] == 203 and conW > 8 then
setSize(conW - 1, #console)
return
elseif e[5] == 200 and #console > 1 then
setSize(conW, #console - 1)
return
elseif e[5] == 205 then
setSize(conW + 1, #console)
return
elseif e[5] == 208 then
setSize(conW, #console + 1)
return
end
end
-- so with the reserved ones dealt with...
if not leText then if not leText then
-- Line Editing not active.
-- For now support a bare minimum.
for _, v in pairs(sendSigs) do for _, v in pairs(sendSigs) do
if a == "\r" then if control then
if a == 99 then
v("telnet", "\xFF\xF4")
end
elseif a == "\r" then
v("data", "\r\n") v("data", "\r\n")
elseif a then elseif a then
v("data", a) v("data", a)
end end
end end
else elseif not control then
-- Line Editing active -- Line Editing active and control isn't involved
if c == 200 or c == 208 then if c == 200 or c == 208 then
-- History cursor up (history down) -- History cursor up (history down)
leText = leHistory[#leHistory] leText = leHistory[#leHistory]
leCX = unicode.len(leText) leCX = unicode.len(leText) + 1
if c == 208 then if c == 208 then
cycleHistoryUp() cycleHistoryUp()
else else
@ -296,7 +324,6 @@ local function key(a, c)
end end
end end
local control = false
while not closeNow do while not closeNow do
local e = {coroutine.yield()} local e = {coroutine.yield()}
if e[1] == "k.procdie" then if e[1] == "k.procdie" then
@ -319,18 +346,8 @@ while not closeNow do
if e[5] == 29 or e[5] == 157 then if e[5] == 29 or e[5] == 157 then
control = e[6] control = e[6]
elseif e[6] then elseif e[6] then
if not control then key(e[4] ~= 0 and unicode.char(e[4]), e[5])
key(e[4] ~= 0 and unicode.char(e[4]), e[5]) draw(#console + 1)
draw(#console + 1)
elseif e[5] == 203 and sW > 8 then
setSize(conW - 1, #console)
elseif e[5] == 200 and #console > 1 then
setSize(conW, #console - 1)
elseif e[5] == 205 then
setSize(conW + 1, #console)
elseif e[5] == 208 then
setSize(conW, #console + 1)
end
end end
elseif e[3] == "line" then elseif e[3] == "line" then
draw(e[4]) draw(e[4])