Compare commits
2 Commits
d1df4ff6a2
...
2726baa6bd
Author | SHA1 | Date | |
---|---|---|---|
2726baa6bd | |||
36427a41a4 |
15
lua/justfile
15
lua/justfile
@ -1,11 +1,14 @@
|
||||
default:
|
||||
@just --list
|
||||
|
||||
teal_files := "main.tl framebuffer.tl ringbuffer.tl socket.tl"
|
||||
lua_files := `find . -type f -name "*.lua" ! -path './out/*' ! -name tlconfig.lua -printf "%p "`
|
||||
teal_files := `find . -type f -name "*.tl" ! -name '*.d.tl' -printf "%p "`
|
||||
|
||||
build:
|
||||
mkdir -p out
|
||||
cp json.lua out
|
||||
for file in {{lua_files}}; do \
|
||||
cp $file out; \
|
||||
done
|
||||
for file in {{teal_files}}; do \
|
||||
tl gen $file; \
|
||||
mv ${file%.tl}.lua out; \
|
||||
@ -17,3 +20,11 @@ clean:
|
||||
rm -r out
|
||||
|
||||
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
|
68
lua/main.tl
68
lua/main.tl
@ -72,10 +72,6 @@ local report_task = coroutine.create(function()
|
||||
end
|
||||
end)
|
||||
|
||||
local shell_task = coroutine.create(function()
|
||||
shell.run("shell")
|
||||
end)
|
||||
|
||||
-- basically parallel.waitForAny
|
||||
|
||||
local record Task
|
||||
@ -83,15 +79,39 @@ local record Task
|
||||
filter: string | nil
|
||||
end
|
||||
|
||||
local tasks: {Task} = {
|
||||
{coro = shell_task}, -- pid 1
|
||||
local background_tasks: {Task} = {
|
||||
{coro = ws_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)
|
||||
event_queue:push({n = 0})
|
||||
|
||||
local shell_deaths: {any} = {}
|
||||
|
||||
local shell_running = true
|
||||
while shell_running do
|
||||
local e: table
|
||||
@ -112,25 +132,23 @@ while shell_running do
|
||||
socket:signal_viewer_connect(false)
|
||||
end
|
||||
else
|
||||
for pid = 1, #tasks do
|
||||
local task = tasks[pid]
|
||||
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 not ok then
|
||||
term.redirect(orig_native())
|
||||
term.clear()
|
||||
term.setCursorPos(1,1)
|
||||
print("OMEGABIG OOF")
|
||||
print(("pid %d"):format(pid))
|
||||
error(param, 0)
|
||||
else
|
||||
task.filter = param as string
|
||||
end
|
||||
if pid == 1 and coroutine.status(task.coro) == "dead" then
|
||||
shell_running = false
|
||||
end
|
||||
for pid = 1, #background_tasks do
|
||||
handle_event(e, pid)
|
||||
end
|
||||
|
||||
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
|
||||
-- shell died i guess?
|
||||
table.insert(shell_deaths, param)
|
||||
else
|
||||
shell_task.filter = param as string
|
||||
end
|
||||
end
|
||||
|
||||
if coroutine.status(shell_task.coro) == "dead" then
|
||||
shell_running = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -140,3 +158,7 @@ term.native = orig_native
|
||||
term.redirect(prev_term)
|
||||
term.clear()
|
||||
term.setCursorPos(1,1)
|
||||
|
||||
for i = 1, #shell_deaths do
|
||||
print(shell_deaths[i])
|
||||
end
|
Loading…
Reference in New Issue
Block a user