36 lines
782 B
Plaintext
36 lines
782 B
Plaintext
local json = require("json")
|
|
local fb = require("framebuffer")
|
|
local ENDPOINT <const> = "http://localhost:8000/monitoring"
|
|
|
|
local orig_native = term.native
|
|
|
|
local buffer = fb.wrap(orig_native())
|
|
|
|
term.native = function(): term.Redirect
|
|
return buffer.target
|
|
end
|
|
|
|
term.redirect(buffer.target as term.Redirect)
|
|
|
|
local function report()
|
|
while true do
|
|
local body = json.encode({
|
|
screen = buffer.serialize()
|
|
})
|
|
local headers = {
|
|
["Content-Type"] = "application/json"
|
|
}
|
|
local r = { pcall(http.post, ENDPOINT .. "/ping", body, headers) }
|
|
sleep(1)
|
|
end
|
|
end
|
|
|
|
local function run_shell()
|
|
shell.run("shell")
|
|
end
|
|
|
|
parallel.waitForAny(report, run_shell)
|
|
|
|
term.native = orig_native
|
|
term.redirect(term.native())
|