v0.4.1 - Added something in the likes of an io.read() function in OpenOS. Cursor will be added next update. Shell parser will be added in 0.5.0.
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
/halyde/core/datatools.lua
|
/halyde/core/datatools.lua
|
||||||
|
/halyde/core/fullkb.lua
|
||||||
/halyde/core/evmgr.lua
|
/halyde/core/evmgr.lua
|
||||||
/halyde/core/shell.lua
|
/halyde/core/shell.lua
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
local loadfile = ...
|
local loadfile = ...
|
||||||
local filesystem = loadfile("/halyde/lib/filesystem.lua")(loadfile)
|
local filesystem = loadfile("/halyde/lib/filesystem.lua")(loadfile)
|
||||||
|
|
||||||
_G._OSVERSION = "Halyde 0.4.0"
|
_G._OSVERSION = "Halyde 0.4.1"
|
||||||
|
|
||||||
function _G.import(module, ...)
|
function _G.import(module, ...)
|
||||||
local args = table.pack(...)
|
local args = table.pack(...)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ _G.evmgr = {}
|
|||||||
_G.evmgr.eventQueue = {}
|
_G.evmgr.eventQueue = {}
|
||||||
local maxEventQueueLength = 10 -- increase if events start getting dropped
|
local maxEventQueueLength = 10 -- increase if events start getting dropped
|
||||||
|
|
||||||
local ocelot = component.proxy(component.list("ocelot")())
|
--local ocelot = component.proxy(component.list("ocelot")())
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local args
|
local args
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
import("termlib")
|
import("termlib")
|
||||||
local event = import("event")
|
local event = import("event")
|
||||||
|
|
||||||
--local ocelot = component.proxy(component.list("ocelot")())
|
_G.shell = {}
|
||||||
|
_G.shell.workingDirectory = "/"
|
||||||
|
|
||||||
print("\n │\n │ ".._OSVERSION..'\n │ Welcome! Type "help" to get started.\n │')
|
print("\n │\n │ ".._OSVERSION..'\n │ Welcome! Type "help" to get started.\n │\n ')
|
||||||
while true do
|
while true do
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
|
print(shell.workingDirectory .. " >")
|
||||||
|
termlib.nextPosX = #(shell.workingDirectory .. " > ")
|
||||||
|
termlib.nextPosY = termlib.nextPosY - 1
|
||||||
read()
|
read()
|
||||||
--ocelot.log(tostring(args[1]))
|
termlib.nextPosX = 1
|
||||||
|
print("no shell parser yet")
|
||||||
end
|
end
|
||||||
+40
-21
@@ -1,34 +1,53 @@
|
|||||||
local event = {}
|
local event = {}
|
||||||
|
|
||||||
local ocelot = component.proxy(component.list("ocelot")())
|
--local ocelot = component.proxy(component.list("ocelot")())
|
||||||
|
function event.pull(...)
|
||||||
|
local args = {...}
|
||||||
|
local evtype, timeout
|
||||||
|
|
||||||
|
if #args == 0 then
|
||||||
|
-- No arguments, wait for any event indefinitely
|
||||||
|
evtype = nil
|
||||||
|
timeout = nil
|
||||||
|
elseif #args == 1 then
|
||||||
|
-- If one argument is provided, it could be either the event type or timeout
|
||||||
|
if type(args[1]) == "number" then
|
||||||
|
-- It's a timeout
|
||||||
|
evtype = nil
|
||||||
|
timeout = args[1]
|
||||||
|
else
|
||||||
|
-- It's an event type
|
||||||
|
evtype = args[1]
|
||||||
|
timeout = nil
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- Both event type and timeout provided
|
||||||
|
evtype = args[1]
|
||||||
|
timeout = args[2]
|
||||||
|
end
|
||||||
|
|
||||||
function event.pull(evtype, ...)
|
|
||||||
local timeout = ...
|
|
||||||
checkArg(1, evtype, "string", "nil")
|
|
||||||
checkArg(2, timeout, "number", "nil")
|
|
||||||
local startTime = computer.uptime()
|
local startTime = computer.uptime()
|
||||||
local args = {}
|
local result = {}
|
||||||
local finished = false
|
|
||||||
repeat
|
repeat
|
||||||
|
-- Check event queue for matching event
|
||||||
for i = 1, #evmgr.eventQueue do
|
for i = 1, #evmgr.eventQueue do
|
||||||
if evmgr.eventQueue[i][2] == evtype or not evtype then
|
if not evtype or evmgr.eventQueue[i][1] == evtype then
|
||||||
args = table.copy(evmgr.eventQueue[i])
|
-- Found matching event (or any event if no type specified)
|
||||||
|
result = table.copy(evmgr.eventQueue[i])
|
||||||
table.remove(evmgr.eventQueue, i)
|
table.remove(evmgr.eventQueue, i)
|
||||||
break
|
return table.unpack(result)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if evtype then
|
|
||||||
finished = args[1] == evtype
|
-- Check if we've timed out
|
||||||
|
if timeout and computer.uptime() >= startTime + timeout then
|
||||||
|
return nil -- Timed out, return nil
|
||||||
end
|
end
|
||||||
if timeout then
|
|
||||||
finished = computer.uptime() >= startTime + timeout
|
-- Yield to allow other processes to run and more events to be added
|
||||||
end
|
coroutine.yield()
|
||||||
if not finished then
|
until false -- Loop until we find an event or timeout
|
||||||
coroutine.yield()
|
|
||||||
end
|
|
||||||
until finished
|
|
||||||
ocelot.log(tostring(args[1]))
|
|
||||||
return table.unpack(args)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return event
|
return event
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
local event = import("event")
|
local event = import("event")
|
||||||
--local keyboard = import("keyboard")
|
--local keyboard = import("keyboard")
|
||||||
|
|
||||||
@@ -32,21 +31,23 @@ function _G.clear()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function _G.read()
|
function _G.read()
|
||||||
ocelot.log("reading")
|
|
||||||
local curtext = ""
|
local curtext = ""
|
||||||
local nextPosX, nextPosY = termlib.nextPosX, termlib.nextPosY
|
local nextPosX, nextPosY = termlib.nextPosX, termlib.nextPosY
|
||||||
while true do
|
while true do
|
||||||
local args = {event.pull("key_down", 0.5)}
|
local args = {event.pull("key_down", 0.5)}
|
||||||
ocelot.log(tostring(args[1]))
|
|
||||||
if args[4] then
|
if args[4] then
|
||||||
local keycode = args[4]
|
local keycode = args[4]
|
||||||
local key = keyboard.keys[keycode]
|
local key = keyboard.keys[keycode]
|
||||||
if key == "back" then
|
if args[3] >= 32 and args[3] <= 126 then
|
||||||
curtext = curtext:sub(1, #curtext-1)
|
|
||||||
elseif key == "enter" then
|
|
||||||
return curtext
|
|
||||||
else
|
|
||||||
curtext = curtext .. (unicode.char(args[3]) or "")
|
curtext = curtext .. (unicode.char(args[3]) or "")
|
||||||
|
else
|
||||||
|
if key == "back" then
|
||||||
|
curtext = curtext:sub(1, #curtext-1)
|
||||||
|
termlib.nextPosX, termlib.nextPosY = nextPosX, nextPosY
|
||||||
|
print(curtext.." ")
|
||||||
|
elseif key == "enter" then
|
||||||
|
return curtext
|
||||||
|
end
|
||||||
end
|
end
|
||||||
termlib.nextPosX, termlib.nextPosY = nextPosX, nextPosY
|
termlib.nextPosX, termlib.nextPosY = nextPosX, nextPosY
|
||||||
print(curtext)
|
print(curtext)
|
||||||
|
|||||||
Reference in New Issue
Block a user