Compare commits

..

No commits in common. "2726baa6bd38425abea1951c6fe922de05a87f6b" and "d1df4ff6a212087d4393f65c70c3bfc7514e1f65" have entirely different histories.

2 changed files with 27 additions and 60 deletions

View File

@ -1,14 +1,11 @@
default: default:
@just --list @just --list
lua_files := `find . -type f -name "*.lua" ! -path './out/*' ! -name tlconfig.lua -printf "%p "` teal_files := "main.tl framebuffer.tl ringbuffer.tl socket.tl"
teal_files := `find . -type f -name "*.tl" ! -name '*.d.tl' -printf "%p "`
build: build:
mkdir -p out mkdir -p out
for file in {{lua_files}}; do \ cp json.lua out
cp $file out; \
done
for file in {{teal_files}}; do \ for file in {{teal_files}}; do \
tl gen $file; \ tl gen $file; \
mv ${file%.tl}.lua out; \ mv ${file%.tl}.lua out; \
@ -20,11 +17,3 @@ clean:
rm -r out rm -r out
alias c := clean alias c := clean
watch:
while sleep 0.1; do \
find . -type f ! -path './out/*' | entr -d just build; \
[ $? -eq 0 ] && exit 0; \
done
alias w := watch

View File

@ -72,6 +72,10 @@ local report_task = coroutine.create(function()
end end
end) end)
local shell_task = coroutine.create(function()
shell.run("shell")
end)
-- basically parallel.waitForAny -- basically parallel.waitForAny
local record Task local record Task
@ -79,39 +83,15 @@ local record Task
filter: string | nil filter: string | nil
end end
local background_tasks: {Task} = { local tasks: {Task} = {
{coro = shell_task}, -- pid 1
{coro = ws_task}, {coro = ws_task},
{coro = report_task}, {coro = report_task},
} }
local shell_task: Task = {
coro = coroutine.create(function() shell.run("shell") end)
}
local function handle_event(e: table, pid: integer)
if e[1] == "terminate" then return end
local task = background_tasks[pid]
if task.filter == nil or task.filter == e[1] then
local ok, param = coroutine.resume(task.coro, table.unpack(e as {any}))
if not ok then
term.native = orig_native
term.redirect(term.native())
term.clear()
term.setCursorPos(1,1)
print(("OMEGABIG OOF @ PID %d"):format(pid))
error(param, 0)
else
task.filter = param as string
end
end
end
local event_queue: Ringbuffer.Ringbuffer<table> = Ringbuffer.new(64) local event_queue: Ringbuffer.Ringbuffer<table> = Ringbuffer.new(64)
event_queue:push({n = 0}) event_queue:push({n = 0})
local shell_deaths: {any} = {}
local shell_running = true local shell_running = true
while shell_running do while shell_running do
local e: table local e: table
@ -132,24 +112,26 @@ while shell_running do
socket:signal_viewer_connect(false) socket:signal_viewer_connect(false)
end end
else else
for pid = 1, #background_tasks do for pid = 1, #tasks do
handle_event(e, pid) local task = tasks[pid]
end if task.filter == nil or task.filter == e[1] or e[1] == "terminate" then
local ok, param = coroutine.resume(task.coro, table.unpack(e as {any}))
if shell_task.filter == nil or shell_task.filter == e[1] or e[1] == "terminate" then
local ok, param = coroutine.resume(shell_task.coro, table.unpack(e as {any}))
if not ok then if not ok then
-- shell died i guess? term.redirect(orig_native())
table.insert(shell_deaths, param) term.clear()
term.setCursorPos(1,1)
print("OMEGABIG OOF")
print(("pid %d"):format(pid))
error(param, 0)
else else
shell_task.filter = param as string task.filter = param as string
end end
end if pid == 1 and coroutine.status(task.coro) == "dead" then
if coroutine.status(shell_task.coro) == "dead" then
shell_running = false shell_running = false
end end
end end
end
end
end end
socket:close() socket:close()
@ -158,7 +140,3 @@ term.native = orig_native
term.redirect(prev_term) term.redirect(prev_term)
term.clear() term.clear()
term.setCursorPos(1,1) term.setCursorPos(1,1)
for i = 1, #shell_deaths do
print(shell_deaths[i])
end