Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --TODO: Add a read() that specifies the broadcast channel (for privacy), if left empty, use the standard
- local MaxX,MaxY = term.getSize()
- local msg = ""
- local shift = false
- term.clear()
- term.setCursorPos(1, 1)
- print("Choose a name:")
- local user = read()
- peripheral.find("modem", rednet.open)
- term.clear()
- while(true) do
- parallel.waitForAny(function()
- local id, message = rednet.receive()
- term.setTextColor(colors.white)
- local cY,cY = term.getCursorPos()
- term.setCursorPos(1, cY)
- print(message)
- term.setCursorPos(1, MaxY)
- write(msg)
- sleep(1)
- end,
- function()
- local event, key, is_held = os.pullEvent("key")
- sKey = keys.getName(key)
- if (sKey == "enter") then
- term.setTextColor(colors.green)
- local cY,cY = term.getCursorPos()
- term.setCursorPos(1, cY)
- print(msg)
- rednet.broadcast(user .. "> " .. msg)
- msg = ""
- elseif (sKey == "backspace") then
- msg = string.sub(msg, 1, string.len(msg)-1)
- elseif (sKey == "space") then
- msg = msg .. " "
- elseif (sKey == "leftShift" or sKey == "rightShift") then
- shift = true
- elseif (key >=48 and key <= 57) then
- sKey = key-48
- msg = msg .. sKey
- elseif (sKey ~= nil) then
- if (shift) then
- sKey = string.upper(sKey)
- shift = false
- end
- msg = msg .. sKey
- end
- term.setCursorPos(1, MaxY)
- term.clearLine()
- term.setTextColor(colors.white)
- write(msg)
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment