Skip to content

Instantly share code, notes, and snippets.

@payonel
Last active September 17, 2018 15:27
local ccore = require("core/cursor")
local term = require("term")
local text = require("text")
local thread = require("thread")
local event = require("event")
local cursor = ccore.new()
local MAIL_SIGNAL = "you_have_mail"
local mail_t = thread.create(function()
while true do
local _, who, data = event.pull(MAIL_SIGNAL)
-- record current cursor location
local previous_cursor_position = cursor.index
-- move to start of cursor
cursor:move(-math.huge)
-- move above
io.write("\27[1A")
-- store exact cursor position
io.write("\0277")
-- move cursor to left
io.write("\27[1000D")
-- print status
io.write("\27[?7l", "[new mail] ", who, ": ", data, "\27[K\27[?7h")
-- restore cursor position
io.write("\0278")
-- move back down
io.write("\27[1B")
-- move back to old cursor position
cursor:move(previous_cursor_position)
end
end)
local debug_fake_mail_t = thread.create(function()
os.sleep(1)
event.push(MAIL_SIGNAL, "Izaya", "mail data")
end)
while true do
io.write("prompt> ")
local input = text.trim(term.read(cursor) or "")
if input == "quit" then
break
end
end
mail_t:kill()
debug_fake_mail_t:kill()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment