v0.10.0 - Added text editor (which took me way too long) and too many other tweaks to name.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
local loadfile = ...
|
||||
local filesystem = loadfile("/halyde/lib/filesystem.lua")(loadfile)
|
||||
|
||||
_G._OSVERSION = "Halyde 0.9.0"
|
||||
_G._OSVERSION = "Halyde 0.10.0"
|
||||
|
||||
function _G.import(module, ...)
|
||||
local args = table.pack(...)
|
||||
|
||||
+30
-11
@@ -4,10 +4,25 @@ _G.cormgr.corList = {}
|
||||
--local ocelot = component.proxy(component.list("ocelot")())
|
||||
|
||||
local filesystem = import("filesystem")
|
||||
local gpu = component.proxy(component.list("gpu")())
|
||||
|
||||
function _G.cormgr.loadCoroutine(path)
|
||||
function _G.cormgr.loadCoroutine(path, ...)
|
||||
local args = {...}
|
||||
local cor = coroutine.create(function()
|
||||
import(path)
|
||||
local result, errorMessage = xpcall(function(...)
|
||||
import(...)
|
||||
end, function(errorMessage)
|
||||
return errorMessage .. "\n \n" .. debug.traceback()
|
||||
end, path, table.unpack(args))
|
||||
if not result then
|
||||
if print then
|
||||
gpu.freeAllBuffers()
|
||||
print("\n\27[91m" .. errorMessage)
|
||||
else
|
||||
error(errorMessage)
|
||||
end
|
||||
end
|
||||
--import(path, table.unpack(args))
|
||||
end)
|
||||
table.insert(_G.cormgr.corList, cor)
|
||||
end
|
||||
@@ -22,16 +37,20 @@ end
|
||||
|
||||
local function runCoroutines()
|
||||
for i = 1, #_G.cormgr.corList do
|
||||
local result, errorMessage = coroutine.resume(_G.cormgr.corList[i])
|
||||
if not result then
|
||||
handleError(errorMessage)
|
||||
if cormgr.corList[i] then
|
||||
local result, errorMessage = coroutine.resume(cormgr.corList[i])
|
||||
if cormgr.corList[i] then
|
||||
if not result then
|
||||
handleError(errorMessage)
|
||||
end
|
||||
if coroutine.status(cormgr.corList[i]) == "dead" then
|
||||
table.remove(cormgr.corList, i)
|
||||
i = i - 1
|
||||
end
|
||||
--computer.pullSignal(0)
|
||||
--coroutine.yield()
|
||||
end
|
||||
end
|
||||
if coroutine.status(_G.cormgr.corList[i]) == "dead" then
|
||||
table.remove(_G.cormgr.corList, i)
|
||||
i = i - 1
|
||||
end
|
||||
--computer.pullSignal(0)
|
||||
--coroutine.yield()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
+28
-1
@@ -2,6 +2,9 @@ _G.evmgr = {}
|
||||
_G.evmgr.eventQueue = {}
|
||||
local maxEventQueueLength = 10 -- increase if events start getting dropped
|
||||
|
||||
keyboard.ctrlDown = false
|
||||
keyboard.altDown = false
|
||||
|
||||
--local ocelot = component.proxy(component.list("ocelot")())
|
||||
|
||||
while true do
|
||||
@@ -11,6 +14,30 @@ while true do
|
||||
if args and args[1] then
|
||||
--ocelot.log("Sending signal "..args..","..computer.uptime())
|
||||
table.insert(evmgr.eventQueue, args)
|
||||
if keyboard then
|
||||
if args[1] == "key_down" then
|
||||
local keycode = args[4]
|
||||
local key = keyboard.keys[keycode]
|
||||
if key == "lcontrol" then
|
||||
keyboard.ctrlDown = true
|
||||
elseif key == "lmenu" then
|
||||
keyboard.altDown = true
|
||||
elseif key == "c" and keyboard.ctrlDown and keyboard.altDown then
|
||||
if print then
|
||||
print("\n\27[91mCoroutine "..tostring(#cormgr.corList).." killed.")
|
||||
end
|
||||
cormgr.corList[#cormgr.corList] = nil
|
||||
end
|
||||
elseif args[1] == "key_up" then
|
||||
local keycode = args[4]
|
||||
local key = keyboard.keys[keycode]
|
||||
if key == "lcontrol" then
|
||||
keyboard.ctrlDown = false
|
||||
elseif key == "lmenu" then
|
||||
keyboard.altDown = false
|
||||
end
|
||||
end
|
||||
end
|
||||
while #evmgr.eventQueue > maxEventQueueLength do
|
||||
--ocelot.log("Queue length breach, removing first signal")
|
||||
table.remove(evmgr.eventQueue, 1)
|
||||
@@ -19,4 +46,4 @@ while true do
|
||||
until not args or not args[1]
|
||||
--ocelot.log("done")
|
||||
coroutine.yield()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
_G.keyboard = {pressedChars = {}, pressedCodes = {}}
|
||||
_G.keyboard.keys = {}
|
||||
_G.keyboard = {["keys"] = {}}
|
||||
|
||||
keyboard.keys["1"] = 0x02
|
||||
keyboard.keys["2"] = 0x03
|
||||
@@ -141,4 +140,4 @@ setmetatable(keyboard.keys,
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
})
|
||||
|
||||
+17
-13
@@ -3,11 +3,22 @@ import("/halyde/core/termlib.lua")
|
||||
local event = import("event")
|
||||
--local ocelot = component.proxy(component.list("ocelot")())
|
||||
local filesystem = import("filesystem")
|
||||
local gpu = component.proxy(component.list("gpu")())
|
||||
|
||||
_G.shell = {}
|
||||
_G.shell.workingDirectory = shellcfg["defaultWorkingDirectory"]
|
||||
_G.shell.aliases = shellcfg["aliases"]
|
||||
|
||||
local function runAsCoroutine(path, ...)
|
||||
--ocelot.log("running " .. path .. " as coroutine")
|
||||
cormgr.loadCoroutine(path, ...)
|
||||
local corIndex = #cormgr.corList
|
||||
local cor = cormgr.corList[#cormgr.corList]
|
||||
repeat
|
||||
coroutine.yield()
|
||||
until cormgr.corList[corIndex] ~= cor
|
||||
end
|
||||
|
||||
function _G.shell.run(command)
|
||||
checkArg(1, command, "string")
|
||||
if shell.aliases[command:match("[^ ]+")] then
|
||||
@@ -48,14 +59,14 @@ function _G.shell.run(command)
|
||||
foundfile = true
|
||||
local path = args[1]
|
||||
table.remove(args, 1)
|
||||
import(path, table.unpack(args))
|
||||
runAsCoroutine(path, table.unpack(args))
|
||||
else
|
||||
for _, item in pairs(shellcfg["path"]) do
|
||||
if filesystem.exists(item..args[1]) then
|
||||
foundfile = true
|
||||
local path = item..args[1]
|
||||
table.remove(args, 1)
|
||||
import(path, table.unpack(args))
|
||||
runAsCoroutine(path, table.unpack(args))
|
||||
break
|
||||
else -- try to look for it without the file extension
|
||||
local files = filesystem.list(item)
|
||||
@@ -63,15 +74,7 @@ function _G.shell.run(command)
|
||||
if args[1] == file:match("(.+)%.[^%.]+$") then
|
||||
foundfile = true
|
||||
table.remove(args, 1)
|
||||
local function runCommand()
|
||||
import(item..file, table.unpack(args))
|
||||
end
|
||||
local result, reason = xpcall(runCommand, function(errMsg)
|
||||
return errMsg .. "\n\n" .. debug.traceback()
|
||||
end)
|
||||
if not result then
|
||||
print("\27[91m" .. reason)
|
||||
end
|
||||
runAsCoroutine(item..file, table.unpack(args))
|
||||
break
|
||||
end
|
||||
end
|
||||
@@ -87,9 +90,10 @@ print(shellcfg["startupMessage"])
|
||||
while true do
|
||||
coroutine.yield()
|
||||
-- print(shell.workingDirectory .. " >")
|
||||
print(shellcfg["prompt"]:format(shell.workingDirectory),false)
|
||||
--print(shellcfg["prompt"]:format(shell.workingDirectory),false)
|
||||
-- termlib.cursorPosX = #(shell.workingDirectory .. " > ")
|
||||
-- termlib.cursorPosY = termlib.cursorPosY - 1
|
||||
local shellCommand = read("shell")
|
||||
local shellCommand = read("shell", shellcfg["prompt"]:format(shell.workingDirectory))
|
||||
shell.run(shellCommand)
|
||||
gpu.freeAllBuffers()
|
||||
end
|
||||
|
||||
+43
-32
@@ -1,6 +1,7 @@
|
||||
local event = import("event")
|
||||
--local keyboard = import("keyboard")
|
||||
|
||||
--local ocelot = component.proxy(component.list("ocelot")())
|
||||
local gpu = component.proxy(component.list("gpu")()) -- replace with component.gpu once implemented
|
||||
_G.termlib = {}
|
||||
termlib.cursorPosX = 1
|
||||
@@ -41,7 +42,7 @@ gpu.setForeground(defaultForegroundColor)
|
||||
gpu.setBackground(defaultBackgroundColor)
|
||||
|
||||
local function scrollDown()
|
||||
if gpu.copy(0,1,width,height,0,-1) then
|
||||
if gpu.copy(1,1,width,height,0,-1) then
|
||||
local prevForeground = gpu.getForeground()
|
||||
local prevBackground = gpu.getBackground()
|
||||
gpu.setForeground(defaultForegroundColor)
|
||||
@@ -61,7 +62,7 @@ local function newLine()
|
||||
end
|
||||
end
|
||||
|
||||
function parseCodeNumbers(code)
|
||||
local function parseCodeNumbers(code)
|
||||
o = {}
|
||||
for num in code:sub(3,-2):gmatch("[^;]+") do
|
||||
table.insert(o,tonumber(num))
|
||||
@@ -69,13 +70,16 @@ function parseCodeNumbers(code)
|
||||
return o
|
||||
end
|
||||
|
||||
function _G.print(text,endNewLine)
|
||||
function _G.print(text, endNewLine, wordWrap)
|
||||
|
||||
-- you don't know how tiring this was just for ANSI escape code support
|
||||
|
||||
if endNewLine==nil then
|
||||
if endNewLine == nil then
|
||||
endNewLine = true
|
||||
end
|
||||
if wordWrap == nil then
|
||||
wordWrap = true
|
||||
end
|
||||
|
||||
if not text or not tostring(text) then
|
||||
return
|
||||
@@ -93,7 +97,7 @@ function _G.print(text,endNewLine)
|
||||
end
|
||||
gpu.set(termlib.cursorPosX,termlib.cursorPosY,section)
|
||||
termlib.cursorPosX = termlib.cursorPosX+unicode.wlen(section)
|
||||
if termlib.cursorPosX>width then
|
||||
if termlib.cursorPosX>width and wordWrap then
|
||||
newLine()
|
||||
end
|
||||
section=""
|
||||
@@ -162,13 +166,18 @@ end
|
||||
|
||||
function _G.clear()
|
||||
local xRes, yRes = gpu.getResolution()
|
||||
gpu.setForeground(defaultForegroundColor)
|
||||
gpu.setBackground(defaultBackgroundColor)
|
||||
gpu.fill(1,1,xRes,yRes," ")
|
||||
termlib.cursorPosX, termlib.cursorPosY = 1, 1
|
||||
end
|
||||
|
||||
function _G.read(readHistoryType)
|
||||
function _G.read(readHistoryType, prefix, defaultText)
|
||||
checkArg(1, readHistoryType, "string", "nil")
|
||||
local curtext = ""
|
||||
checkArg(2, prefix, "string", "nil")
|
||||
checkArg(3, defaultText, "string", "nil")
|
||||
local curtext = defaultText or ""
|
||||
local prefix = prefix or ""
|
||||
local RHIndex
|
||||
if readHistoryType then
|
||||
if not termlib.readHistory[readHistoryType] then
|
||||
@@ -179,13 +188,10 @@ function _G.read(readHistoryType)
|
||||
RHIndex = #termlib.readHistory[readHistoryType] -- read history index
|
||||
end
|
||||
local cursorPosX, cursorPosY = termlib.cursorPosX, termlib.cursorPosY
|
||||
print(prefix .. curtext .. "\27[107m ", false)
|
||||
local cursorWhite = true
|
||||
while true do
|
||||
if cursorWhite then
|
||||
print("\27[107m ", false)
|
||||
else
|
||||
print(" ", false)
|
||||
end
|
||||
--ocelot.log(curtext)
|
||||
termlib.cursorPosX = termlib.cursorPosX - 1
|
||||
local args = {event.pull("key_down", 0.5)}
|
||||
if args[4] then
|
||||
@@ -194,51 +200,56 @@ function _G.read(readHistoryType)
|
||||
local key = keyboard.keys[keycode]
|
||||
if key == "up" and readHistoryType then
|
||||
termlib.cursorPosX, termlib.cursorPosY = cursorPosX, cursorPosY
|
||||
print(curtext .. " ", false)
|
||||
print(prefix .. curtext .. " ", false)
|
||||
RHIndex = RHIndex - 1
|
||||
if RHIndex <= 0 then
|
||||
RHIndex = 1
|
||||
end
|
||||
termlib.cursorPosX, termlib.cursorPosY = cursorPosX, cursorPosY
|
||||
print(termlib.readHistory[readHistoryType][RHIndex] .. string.rep(" ", unicode.wlen(curtext) - unicode.wlen(termlib.readHistory[readHistoryType][RHIndex])), false)
|
||||
print(prefix .. termlib.readHistory[readHistoryType][RHIndex] .. string.rep(" ", unicode.wlen(curtext) - unicode.wlen(termlib.readHistory[readHistoryType][RHIndex])), false)
|
||||
curtext = termlib.readHistory[readHistoryType][RHIndex]
|
||||
end
|
||||
if key == "down" and readHistoryType then
|
||||
termlib.cursorPosX, termlib.cursorPosY = cursorPosX, cursorPosY
|
||||
print(curtext .. " ", false)
|
||||
print(prefix .. curtext .. " ", false)
|
||||
RHIndex = RHIndex + 1
|
||||
if RHIndex > #termlib.readHistory[readHistoryType] then
|
||||
RHIndex = #termlib.readHistory[readHistoryType]
|
||||
end
|
||||
termlib.cursorPosX, termlib.cursorPosY = cursorPosX, cursorPosY
|
||||
print(termlib.readHistory[readHistoryType][RHIndex] .. string.rep(" ", unicode.wlen(curtext) - unicode.wlen(termlib.readHistory[readHistoryType][RHIndex])), false)
|
||||
print(prefix .. termlib.readHistory[readHistoryType][RHIndex] .. string.rep(" ", unicode.wlen(curtext) - unicode.wlen(termlib.readHistory[readHistoryType][RHIndex])), false)
|
||||
curtext = termlib.readHistory[readHistoryType][RHIndex]
|
||||
end
|
||||
if key == "back" then
|
||||
curtext = curtext:sub(1, #curtext-1)
|
||||
termlib.cursorPosX, termlib.cursorPosY = cursorPosX, cursorPosY
|
||||
print(prefix .. curtext.." ", false)
|
||||
end
|
||||
if key == "enter" then
|
||||
termlib.cursorPosX, termlib.cursorPosY = cursorPosX, cursorPosY
|
||||
print(prefix .. curtext .. " ")
|
||||
if readHistoryType then
|
||||
while #termlib.readHistory[readHistoryType] > 50 do
|
||||
table.remove(termlib.readHistory[readHistoryType], 1)
|
||||
end
|
||||
end
|
||||
return curtext
|
||||
end
|
||||
if args[3] >= 32 and args[3] <= 126 then
|
||||
curtext = curtext .. (unicode.char(args[3]) or "")
|
||||
if readHistoryType then
|
||||
termlib.readHistory[readHistoryType][RHIndex] = curtext
|
||||
end
|
||||
else
|
||||
if key == "back" then
|
||||
curtext = curtext:sub(1, #curtext-1)
|
||||
termlib.cursorPosX, termlib.cursorPosY = cursorPosX, cursorPosY
|
||||
print(curtext.." ", false)
|
||||
elseif key == "enter" then
|
||||
termlib.cursorPosX, termlib.cursorPosY = cursorPosX, cursorPosY
|
||||
print(curtext .. " ")
|
||||
if readHistoryType then
|
||||
while #termlib.readHistory[readHistoryType] > 50 do
|
||||
table.remove(termlib.readHistory[readHistoryType], 1)
|
||||
end
|
||||
end
|
||||
return curtext
|
||||
end
|
||||
end
|
||||
termlib.cursorPosX, termlib.cursorPosY = cursorPosX, cursorPosY
|
||||
print(curtext, false)
|
||||
print(prefix .. curtext, false)
|
||||
else
|
||||
cursorWhite = not cursorWhite
|
||||
end
|
||||
if cursorWhite then
|
||||
print("\27[107m ", false)
|
||||
else
|
||||
print(" ", false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user