Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local input = ""
- local nick = "unnamed"
- local sizex, sizey = term.getSize()
- local rn = 1
- shell.run("/api")
- function loadInput()
- term.setCursorPos(1, sizey)
- term.clearLine()
- term.setCursorPos(1, sizey)
- write("> "..input)
- term.setCursorBlink(true)
- end
- function send(msg)
- lan.broadcast(nick..": "..msg)
- term.setCursorPos(1, rn)
- print(nick..": "..msg)
- local x, y = term.getCursorPos()
- rn = y
- loadInput()
- end
- function rec()
- while true do
- local event, id, msg = os.pullEvent()
- if event == "cable_message" then
- return id, msg
- elseif event == "char" then
- input = input..id
- loadInput()
- elseif event == "key" then
- if id == 14 then
- if #input > 0 then
- input = string.sub(input, 1, #input - 1)
- loadInput()
- end
- elseif id == 28 then
- send(input)
- input = ""
- loadInput()
- end
- end
- end
- end
- term.clear()
- term.setCursorPos(1, 1)
- write("Nickname: ")
- nick = read()
- term.clear()
- term.setCursorPos(1, 1)
- while true do
- loadInput()
- local id, msg = rec()
- term.setCursorPos(1, rn)
- print(msg)
- local x, y = term.getCursorPos()
- rn = y
- loadInput()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement