Skip to content

Instantly share code, notes, and snippets.

@IgorTimofeev
Created May 27, 2023 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IgorTimofeev/724992e8641245a51cef57ac883f541f to your computer and use it in GitHub Desktop.
Save IgorTimofeev/724992e8641245a51cef57ac883f541f to your computer and use it in GitHub Desktop.
TunnelChat.lua
local GUI = require("GUI")
local system = require("System")
local fs = require("Filesystem")
local tunnel = component.tunnel
---------------------------------------------------------------------------------
local workspace, window, menu = system.addWindow(GUI.filledWindow(1, 1, 50, 20, 0xE1E1E1))
local layout = window:addChild(GUI.layout(1, 4, window.width, window.height - 3, 1, 1))
local history = layout:addChild(GUI.textBox(1, 1, layout.width, layout.height - 8, 0xEEEEEE, 0x2D2D2D, {}, 1, 1, 0))
local channel = layout:addChild(GUI.input(1, 1, layout.width, 3, 0xEEEEEE, 0x555555, 0x999999, 0xFFFFFF, 0x2D2D2D, nil, "Remote channel"))
local message = layout:addChild(GUI.input(1, 1, layout.width, 3, 0xEEEEEE, 0x555555, 0x999999, 0xFFFFFF, 0x2D2D2D, nil, "Message"))
local function log(color, text)
table.insert(history.lines, {color = color, text = text})
history:scrollToEnd()
end
message.onInputFinished = function()
if channel.text:len() > 4 then
log(0x888888, "To " .. channel.text:sub(1, 4) .. ": " .. message.text)
tunnel.send(channel.text, message.text)
message.text = ""
end
end
layout.eventHandler = function(workspace, object, ...)
local e = {...}
if e[1] == "modem_message" and e[6] and e[7] then
log(0x444444, "From " .. e[6]:sub(1, 4) .. ": " .. e[7])
end
end
---------------------------------------------------------------------------------
workspace:draw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment