1
0
mirror of https://github.com/kepler155c/opus synced 2025-10-22 11:17:40 +00:00

friendlier networking + adding tabs

This commit is contained in:
kepler155c@gmail.com
2017-10-09 13:08:38 -04:00
parent f5b99d91e5
commit 05c99b583a
7 changed files with 124 additions and 40 deletions

View File

@@ -3,8 +3,9 @@ _G.requireInjector()
local UI = require('ui')
local Util = require('util')
local colors = _G.colors
local help = _G.help
local colors = _G.colors
local help = _G.help
local multishell = _ENV.multishell
multishell.setTitle(multishell.getCurrent(), 'Help')
UI:configure('Help', ...)
@@ -55,10 +56,6 @@ local topicPage = UI.Page {
},
}
function topicPage.helpText:focus()
-- let the help text get focused so we consume key strokes
end
function topicPage:eventHandler(event)
if event.type == 'back' then
UI:setPreviousPage()

View File

@@ -28,10 +28,17 @@ end
local page = UI.Page {
menuBar = UI.MenuBar {
buttons = {
{ text = 'Telnet', event = 'telnet' },
{ text = 'VNC', event = 'vnc' },
{ text = 'Trust', event = 'trust' },
{ text = 'Reboot', event = 'reboot' },
{ text = 'Connect', dropdown = {
{ text = 'Telnet t', event = 'telnet' },
{ text = 'VNC v', event = 'vnc' },
UI.MenuBar.spacer,
{ text = 'Reboot r', event = 'reboot' },
} },
{ text = 'Trust', dropdown = {
{ text = 'Establish', event = 'trust' },
{ text = 'Remove', event = 'untrust' },
} },
{ text = 'Help', event = 'help' },
},
},
grid = UI.ScrollingGrid {
@@ -43,6 +50,9 @@ local page = UI.Page {
},
notification = UI.Notification { },
accelerators = {
t = 'telnet',
v = 'vnc',
r = 'reboot',
q = 'quit',
c = 'clear',
},
@@ -85,20 +95,62 @@ function page:eventHandler(event)
args = { t.id },
title = t.label,
})
elseif event.type == 'clear' then
Util.clear(network)
page.grid:update()
page.grid:draw()
elseif event.type == 'trust' then
shell.openForegroundTab('trust ' .. t.id)
elseif event.type == 'untrust' then
local trustList = Util.readTable('usr/.known_hosts') or { }
trustList[t.id] = nil
Util.writeTable('usr/.known_hosts', trustList)
elseif event.type == 'reboot' then
sendCommand(t.id, 'reboot')
elseif event.type == 'shutdown' then
sendCommand(t.id, 'shutdown')
end
end
if event.type == 'quit' then
if event.type == 'help' then
UI:setPage(UI.Dialog {
title = 'Network Help',
height = 10,
backgroundColor = colors.white,
text = UI.TextArea {
x = 2, y = 2,
backgroundColor = colors.white,
value = [[
In order to connect to another computer:
1. The target computer must have a password set (run 'password' from the shell prompt).
2. From this computer, click trust and enter the password for that computer.
This only needs to be done once.
]],
},
accelerators = {
q = 'cancel',
}
})
elseif event.type == 'quit' then
Event.exitPullEvents()
end
UI.Page.eventHandler(self, event)
end
function page.menuBar:getActive(menuItem)
local t = page.grid:getSelected()
if menuItem.event == 'untrust' then
local trustList = Util.readTable('usr/.known_hosts') or { }
return t and trustList[t.id]
end
return not not t
end
function page.grid:getRowTextColor(row, selected)
if not row.active then
return colors.orange

View File

@@ -13,6 +13,14 @@ local shell = _ENV.shell
multishell.setTitle(multishell.getCurrent(), 'System')
UI:configure('System', ...)
local mcVersion = _G._MC_VERSION or 'unknown'
if _G._HOST then
local version = _G._HOST:match('%S+ %S+ %((%S.+)%)')
if version then
mcVersion = version:match('Minecraft (%S+)') or version
end
end
local env = {
path = shell.path(),
aliases = shell.aliases(),
@@ -89,7 +97,7 @@ local systemPage = UI.Page {
{ name = '', value = '' },
{ name = 'CC version', value = Util.getVersion() },
{ name = 'Lua version', value = _VERSION },
{ name = 'MC version', value = _G._MC_VERSION or 'unknown' },
{ name = 'MC version', value = mcVersion },
{ name = 'Disk free', value = Util.toBytes(fs.getFreeSpace('/')) },
{ name = 'Computer ID', value = tostring(os.getComputerID()) },
{ name = 'Day', value = tostring(os.day()) },
@@ -123,7 +131,7 @@ if settings then
grid = UI.Grid {
y = 1,
values = values,
--autospace = true,
autospace = true,
sortColumn = 'name',
columns = {
{ heading = 'Setting', key = 'name' },

View File

@@ -23,10 +23,10 @@ if not remoteId then
end
print('connecting...')
local socket = Socket.connect(remoteId, 23)
local socket, msg = Socket.connect(remoteId, 23)
if not socket then
error('Unable to connect to ' .. remoteId .. ' on port 23')
error(msg)
end
local ct = Util.shallowCopy(term.current())

View File

@@ -25,10 +25,10 @@ end
multishell.setTitle(multishell.getCurrent(), 'VNC-' .. remoteId)
print('connecting...')
local socket = Socket.connect(remoteId, 5900)
local socket, msg = Socket.connect(remoteId, 5900)
if not socket then
error('Unable to connect to ' .. remoteId .. ' on port 5900')
error(msg)
end
local function writeTermInfo()