Advertisement
Alakazard12

IRC Client

Nov 25th, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.14 KB | None | 0 0
  1. local input = ""
  2. local nick = "unnamed"
  3. local sizex, sizey = term.getSize()
  4. local rn = 1
  5. shell.run("/api")
  6.  
  7. function loadInput()
  8.     term.setCursorPos(1, sizey)
  9.     term.clearLine()
  10.     term.setCursorPos(1, sizey)
  11.     write("> "..input)
  12.     term.setCursorBlink(true)
  13. end
  14.  
  15. function send(msg)
  16.     lan.broadcast(nick..": "..msg)
  17.     term.setCursorPos(1, rn)
  18.     print(nick..": "..msg)
  19.     local x, y = term.getCursorPos()
  20.     rn = y
  21.     loadInput()
  22. end
  23.  
  24. function rec()
  25.     while true do
  26.         local event, id, msg = os.pullEvent()
  27.         if event == "cable_message" then
  28.             return id, msg
  29.         elseif event == "char" then
  30.             input = input..id
  31.             loadInput()
  32.         elseif event == "key" then
  33.             if id == 14 then
  34.                 if #input > 0 then
  35.                     input = string.sub(input, 1, #input - 1)
  36.                     loadInput()
  37.                 end
  38.             elseif id == 28 then
  39.                 send(input)
  40.                 input = ""
  41.                 loadInput()
  42.             end
  43.         end
  44.     end
  45. end
  46.  
  47. term.clear()
  48. term.setCursorPos(1, 1)
  49. write("Nickname: ")
  50. nick = read()
  51. term.clear()
  52. term.setCursorPos(1, 1)
  53.  
  54. while true do
  55.     loadInput()
  56.     local id, msg = rec()
  57.     term.setCursorPos(1, rn)
  58.     print(msg)
  59.     local x, y = term.getCursorPos()
  60.     rn = y
  61.     loadInput()
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement