-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlchat.lua
60 lines (48 loc) · 1.64 KB
/
lchat.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
local gui = require("gui_new").create()
local event = require("event")
local thread = require("thread")
local su = require("superUtiles")
local keyboard = require("keyboard")
local computer = require("computer")
local shell = require("shell")
local networks = require("networks")
-------------------------------------------
local args = shell.parse(...)
local gpu = gui.gpu
local rx, ry = gpu.getResolution()
local userCode = args[2] or su.generateRandomID()
local appName = (args[3] and "lchat:"..args[3]) or "lchat"
if not args[1] then
print("usage:")
print("lchat network [nikname] [chat]")
return
end
local network = networks.getNetwork(args[1])
if not network then io.stderr:write("this network in not open\n") return end
-------------------------------------------
local main = gui.createScene(0, rx, ry)
local logZone = main.createLogZone(1, 1, rx, ry - 3)
local input = main.createInputBox(1, ry - 2, rx, 3, "input", nil, nil, function(str)
if str then
network.send(appName, userCode..": "..str)
logZone.add(userCode.."(you): "..str)
end
end)
thread.create(function()
while true do
local _, _, _, message = event.pull("network_message", network.name, appName)
if message then
logZone.add(message)
computer.beep()
end
end
end)
gui.select(main)
-------------------------------------------
while true do
local eventData = {event.pull()}
gui.uploadEvent(table.unpack(eventData))
if eventData[1] == "key_down" and eventData[2] == gui.keyboard and eventData[4] == 28 then
input.input()
end
end