diff --git a/sys/apis/peripheral.lua b/sys/apis/peripheral.lua index 2e3b4d1..022d2bf 100644 --- a/sys/apis/peripheral.lua +++ b/sys/apis/peripheral.lua @@ -127,6 +127,8 @@ local function getProxy(pi) error("Timed out attaching peripheral: " .. pi.uri) end + -- write the uri of the periperal we are requesting... + -- ie. type/monitor socket:write(pi.path) local proxy = socket:read(3) @@ -134,6 +136,10 @@ local function getProxy(pi) error("Timed out attaching peripheral: " .. pi.uri) end + if type(proxy) == 'string' then + error(proxy) + end + local methods = proxy.methods proxy.methods = nil @@ -166,6 +172,9 @@ local function getProxy(pi) socket:read() end) end + if not socket.connected then + error("Timed out communicating with peripheral: " .. pi.uri) + end table.insert(queue, { fn = method, @@ -222,7 +231,7 @@ end function Peripheral.lookup(uri) local pi = parse(uri) - if pi.host then + if pi.host and _G.device.wireless_modem then return getProxy(pi) end diff --git a/sys/apis/socket.lua b/sys/apis/socket.lua index fecc817..a3f3e95 100644 --- a/sys/apis/socket.lua +++ b/sys/apis/socket.lua @@ -9,7 +9,6 @@ local os = _G.os local socketClass = { } function socketClass:read(timeout) - local data, distance = _G.transport.read(self) if data then return data, distance @@ -31,6 +30,9 @@ function socketClass:read(timeout) os.cancelTimer(timerId) return data, distance end + if not self.connected then + break + end elseif e == 'timer' and id == timerId then if timeout or not self.connected then @@ -104,6 +106,9 @@ local function newSocket(isLoopback) end function Socket.connect(host, port) + if not device.wireless_modem then + return false, 'Wireless modem not found' + end local socket = newSocket(host == os.getComputerID()) socket.dhost = tonumber(host) @@ -149,7 +154,6 @@ function Socket.connect(host, port) end local function trusted(msg, port) - if port == 19 or msg.shost == os.getComputerID() then -- no auth for trust server or loopback return true @@ -172,7 +176,6 @@ local function trusted(msg, port) end function Socket.server(port) - device.wireless_modem.open(port) Logger.log('socket', 'Waiting for connections on port ' .. port) diff --git a/sys/apis/terminal.lua b/sys/apis/terminal.lua index 6b662cc..2f6addd 100644 --- a/sys/apis/terminal.lua +++ b/sys/apis/terminal.lua @@ -6,7 +6,40 @@ local _gsub = string.gsub local Terminal = { } -function Terminal.scrollable(ct, size) +function Terminal.scrollable(win, size) + local w, h = win.getSize() + local scrollPos = 0 + local scp = win.setCursorPos + + win.setCursorPos = function(x, y) + scp(x, y) + if y > scrollPos + h then + win.scrollTo(y - h) + elseif y < scrollPos then + win.scrollTo(y - 2) + end + end + + win.scrollUp = function() + win.scrollTo(scrollPos - 1) + end + + win.scrollDown = function() + win.scrollTo(scrollPos + 1) + end + + win.scrollTo = function(p) + p = math.min(math.max(p, 0), size) + if p ~= scrollPos then + scrollPos = p + win.reposition(1, -scrollPos + 1, w, h + size) + end + end + + win.reposition(1, 1, w, h + size, true) +end + +function Terminal.scrollable2(ct, size) local w, h = ct.getSize() local win = _G.window.create(ct, 1, 1, w, h + size, true) @@ -63,7 +96,6 @@ function Terminal.scrollable(ct, size) return win end - function Terminal.toGrayscale(ct) local scolors = { diff --git a/sys/apis/util.lua b/sys/apis/util.lua index 251a6b6..76ded6e 100644 --- a/sys/apis/util.lua +++ b/sys/apis/util.lua @@ -563,22 +563,23 @@ function Util.wordWrap(str, limit) end function Util.args(arg) - local tab = { remainder = { } } + local options, args = { }, { } local k = 1 while k <= #arg do local v = arg[k] if string.sub(v, 1, 1) == '-' then - local jopt = string.sub(v, 2) - tab[ jopt ] = arg[ k + 1 ] + local opt = string.sub(v, 2) + options[opt] = arg[k + 1] k = k + 1 else - table.insert(tab.remainder, v) + table.insert(args, v) end k = k + 1 end - return tab + return options, args end + -- http://lua-users.org/wiki/AlternativeGetOpt local function getopt( arg, options ) local tab = {} diff --git a/sys/apps/Lua.lua b/sys/apps/Lua.lua index 3fb6fec..a840897 100644 --- a/sys/apps/Lua.lua +++ b/sys/apps/Lua.lua @@ -1,9 +1,8 @@ -local injector = _G.requireInjector or load(http.get('https://raw.githubusercontent.com/kepler155c/opus/master/sys/apis/injector.lua').readAll())() +local injector = _G.requireInjector or load(_G.http.get('https://raw.githubusercontent.com/kepler155c/opus/master/sys/apis/injector.lua').readAll())() injector() local Event = require('event') local History = require('history') -local Peripheral = require('peripheral') local UI = require('ui') local Util = require('util') diff --git a/sys/apps/Overview.lua b/sys/apps/Overview.lua index 0bb8fe4..42b5481 100644 --- a/sys/apps/Overview.lua +++ b/sys/apps/Overview.lua @@ -128,6 +128,7 @@ function UI.VerticalTabBar:setParent() c.x = 1 c.y = k + 1 c.ox, c.oy = c.x, c.y + c.ow = 8 c.width = 8 end end diff --git a/sys/apps/multishell b/sys/apps/multishell index b702aaa..aba980b 100644 --- a/sys/apps/multishell +++ b/sys/apps/multishell @@ -20,11 +20,7 @@ local overviewId local tabsDirty = false local closeInd = Util.getVersion() >= 1.76 and '\215' or '*' -multishell.term = term.current() --deprecated - --- redirect kernel output to a window -kernel.window = window.create(parentTerm, 1, 2, w, h - 1, false) -kernel.terminal = kernel.window +multishell.term = parentTerm --deprecated local config = { standard = { @@ -156,6 +152,7 @@ function multishell.hideTab(tabId) local tab = kernel.find(tabId) if tab then tab.hidden = true + kernel.lower(tab.uid) redrawMenu() end end @@ -224,6 +221,7 @@ kernel.hook('multishell_redraw', function() local currentTab = kernel.routines[1] for _,tab in pairs(kernel.routines) do +tab.title = tab.env._APP_TITLE or tab.title if tab.hidden and tab ~= currentTab then tab.width = 0 else diff --git a/sys/apps/shell b/sys/apps/shell index 6da9069..8871493 100644 --- a/sys/apps/shell +++ b/sys/apps/shell @@ -330,7 +330,7 @@ end local tArgs = { ... } if #tArgs > 0 then local env = setmetatable(Util.shallowCopy(sandboxEnv), { __index = _G }) - return run(_ENV, ...) -- maybe _ENV + return run(env, ...) end local Config = require('config') diff --git a/sys/apps/telnet.lua b/sys/apps/telnet.lua index 16ce3a6..8a181b9 100644 --- a/sys/apps/telnet.lua +++ b/sys/apps/telnet.lua @@ -10,9 +10,9 @@ local os = _G.os local read = _G.read local term = _G.term -local args = Util.args({ ... }) +local options, args = Util.args({ ... }) -local remoteId = tonumber(table.remove(args.remainder, 1)) +local remoteId = tonumber(table.remove(args, 1) or '') if not remoteId then print('Enter host ID') remoteId = tonumber(read()) @@ -22,8 +22,8 @@ if not remoteId then error('Syntax: telnet [-title TITLE] ID [PROGRAM]') end -if args.title then - multishell.setTitle(multishell.getCurrent(), args.title) +if options.title then + multishell.setTitle(multishell.getCurrent(), options.title) end print('connecting...') @@ -43,7 +43,7 @@ socket:write({ width = w, height = h, isColor = ct.isColor(), - program = args.remainder, + program = args, }) Event.addRoutine(function() @@ -61,10 +61,10 @@ end) ct.clear() ct.setCursorPos(1, 1) -local filter = Util.transpose({ +local filter = Util.transpose { 'char', 'paste', 'key', 'key_up', 'terminate', 'mouse_scroll', 'mouse_click', 'mouse_drag', 'mouse_up', -}) +} while true do local e = { os.pullEventRaw() } diff --git a/sys/boot/opus.boot b/sys/boot/opus.boot index 3ccd0fe..4191518 100644 --- a/sys/boot/opus.boot +++ b/sys/boot/opus.boot @@ -5,43 +5,81 @@ local http = _G.http local os = _G.os local shell = _ENV.shell local term = _G.term +local window = _G.window -local w, h = term.getSize() -term.setTextColor(colors.white) -if term.isColor() then - term.setBackgroundColor(colors.black) - term.clear() - local opus = { - 'fffff00', - 'ffff07000', - 'ff00770b00 4444', - 'ff077777444444444', - 'f07777744444444444', - 'f0000777444444444', - '070000111744444', - '777770000', - '7777000000', - '70700000000', - '077000000000', - } - for k,line in ipairs(opus) do - term.setCursorPos((w - 18) / 2, k + (h - #opus) / 2) - term.blit(string.rep(' ', #line), string.rep('a', #line), line) - end -end - -term.setCursorPos((w - 18) / 2, h) -term.write('Loading Opus...') -term.setCursorPos(w, h) - -local GIT_REPO = 'kepler155c/opus/develop-1.8' +local BRANCH = 'develop-1.8' +local GIT_REPO = 'kepler155c/opus/' .. BRANCH local BASE = 'https://raw.githubusercontent.com/' .. GIT_REPO local sandboxEnv = setmetatable({ }, { __index = _G }) for k,v in pairs(_ENV) do sandboxEnv[k] = v end -sandboxEnv.multishell = _ENV.multishell or { } +sandboxEnv.multishell = { } + +_G.debug = function() end + +local terminal = term.current() +local w, h = term.getSize() +local kernelWindow = window.create(terminal, 1, 1, w, h, false) +term.redirect(kernelWindow) +local splashWindow + +local function showStatus(status, ...) + local str = string.format(status, ...) + print(str) + splashWindow.setCursorPos(1, h) + splashWindow.clearLine() + splashWindow.setCursorPos((w - #str) / 2, h) + splashWindow.write(str) + os.sleep(.1) +end + +local function splash() + splashWindow = window.create(terminal, 1, 1, w, h, false) + splashWindow.setTextColor(colors.white) + if splashWindow.isColor() then + splashWindow.setBackgroundColor(colors.black) + splashWindow.clear() + local opus = { + 'fffff00', + 'ffff07000', + 'ff00770b00 4444', + 'ff077777444444444', + 'f07777744444444444', + 'f0000777444444444', + '070000111744444', + '777770000', + '7777000000', + '70700000000', + '077000000000', + } + for k,line in ipairs(opus) do + splashWindow.setCursorPos((w - 18) / 2, k + (h - #opus) / 2) + splashWindow.blit(string.rep(' ', #line), string.rep('a', #line), line) + end + end + splashWindow.setVisible(true) + return splashWindow +end + +local function setLabel() + -- Default label + if not os.getComputerLabel() then + showStatus('Setting computer label') + + local id = os.getComputerID() + if _G.turtle then + os.setComputerLabel('turtle_' .. id) + elseif _G.pocket then + os.setComputerLabel('pocket_' .. id) + elseif _G.commands then + os.setComputerLabel('command_' .. id) + else + os.setComputerLabel('computer_' .. id) + end + end +end local function makeEnv() local env = setmetatable({ }, { __index = _G }) @@ -51,7 +89,6 @@ local function makeEnv() return env end --- os.run doesn't provide return values :( local function run(file, ...) local s, m = loadfile(file, makeEnv()) if s then @@ -77,107 +114,113 @@ local function runUrl(file, ...) error('Failed to download ' .. url) end -_G.debug = function() end +local function createUserEnvironment(Util) + showStatus('Creating user environment') --- Install require shim -if fs.exists('sys/apis/injector.lua') then - _G.requireInjector = run('sys/apis/injector.lua') -else - -- not local, run the file system directly from git - _G.requireInjector = runUrl('/sys/apis/injector.lua') - runUrl('sys/extensions/vfs.lua') - - -- install file system - fs.mount('', 'gitfs', GIT_REPO) -end - -_G.requireInjector() -local Util = require('util') - --- Default label -if not os.getComputerLabel() then - local id = os.getComputerID() - if _G.turtle then - os.setComputerLabel('turtle_' .. id) - elseif _G.pocket then - os.setComputerLabel('pocket_' .. id) - elseif _G.commands then - os.setComputerLabel('command_' .. id) - else - os.setComputerLabel('computer_' .. id) + if not fs.exists('usr/apps') then + fs.makeDir('usr/apps') + end + if not fs.exists('usr/autorun') then + fs.makeDir('usr/autorun') + end + if not fs.exists('usr/etc/fstab') then + Util.writeFile('usr/etc/fstab', 'usr gitfs kepler155c/opus-apps/' .. BRANCH) end end --- user environment -if not fs.exists('usr/apps') then - fs.makeDir('usr/apps') -end -if not fs.exists('usr/autorun') then - fs.makeDir('usr/autorun') -end -if not fs.exists('usr/etc/fstab') then - Util.writeFile('usr/etc/fstab', 'usr gitfs kepler155c/opus-apps/develop-1.8') -end -if not fs.exists('usr/config/shell') then - Util.writeTable('usr/config/shell', { - aliases = shell.aliases(), - path = 'usr/apps:sys/apps:' .. shell.path(), - lua_path = '/sys/apis:/usr/apis', - }) +local function createShellEnvironment(Util) + showStatus('Creating shell environment') + + if not fs.exists('usr/config/shell') then + Util.writeTable('usr/config/shell', { + aliases = shell.aliases(), + path = 'usr/apps:sys/apps:' .. shell.path(), + lua_path = '/sys/apis:/usr/apis', + }) + end + + local config = Util.readTable('usr/config/shell') + if config.aliases then + for k in pairs(shell.aliases()) do + shell.clearAlias(k) + end + for k,v in pairs(config.aliases) do + shell.setAlias(k, v) + end + end + shell.setPath(config.path) + sandboxEnv.LUA_PATH = config.lua_path end --- shell environment -local config = Util.readTable('usr/config/shell') -if config.aliases then - for k in pairs(shell.aliases()) do - shell.clearAlias(k) - end - for k,v in pairs(config.aliases) do - shell.setAlias(k, v) +local function loadExtensions(Util) + local dir = 'sys/extensions' + for _,file in ipairs(fs.list(dir)) do + showStatus('Loading ' .. file) + local s, m = Util.run(makeEnv(), 'sys/apps/shell', fs.combine(dir, file)) + if not s then + error(m) + end end end -shell.setPath(config.path) -sandboxEnv.LUA_PATH = config.lua_path - -Util.run(makeEnv(), 'sys/kernel.lua') - --- extensions -local dir = 'sys/extensions' -for _,file in ipairs(fs.list(dir)) do - local s, m = Util.run(makeEnv(), 'sys/apps/shell', fs.combine(dir, file)) - if not s then - error(m) - end -end - --- install user file systems -fs.loadTab('usr/etc/fstab') local args = { ... } -if args[1] then - term.setBackgroundColor(colors.black) - term.clear() - term.setCursorPos(1, 1) -end -local cterm = term.current() +splash() +local s, m = pcall(function() + showStatus('Loading Opus OS...') -args[1] = args[1] or 'sys/apps/multishell' -local routine = kernel.newRoutine({ - path = 'sys/apps/shell', - args = args - }) -kernel.run(routine) -local s, m = pcall(kernel.start) + -- Install require shim + if fs.exists('sys/apis/injector.lua') then + _G.requireInjector = run('sys/apis/injector.lua') + else + -- not local, run the file system directly from git + _G.requireInjector = runUrl('sys/apis/injector.lua') + runUrl('sys/extensions/vfs.lua') + + -- install file system + fs.mount('', 'gitfs', GIT_REPO) + end + + _G.requireInjector() + local Util = require('util') + + setLabel() + createUserEnvironment(Util) + createShellEnvironment(Util) + + showStatus('Reticulating splines') + Util.run(makeEnv(), 'sys/kernel.lua') + + loadExtensions(Util) + + showStatus('Mounting file systems') + fs.loadTab('usr/etc/fstab') + + splashWindow.setVisible(false) + if args[1] then + kernelWindow.setVisible(true) + end + --term.clear() + --term.redirect(terminal) + + _G.kernel.run(_G.kernel.newRoutine({ + path = 'sys/apps/shell', + args = args[1] and args or { 'sys/apps/multishell' }, + terminal = terminal, + })) +end) -term.redirect(cterm) -term.setBackgroundColor(colors.black) -term.setTextColor(colors.white) -term.clear() -term.setCursorPos(1, 1) if not s then - print('\nCrash detected\n') - _G.printError(m) + splashWindow.setVisible(false) + kernelWindow.setVisible(true) + print('\nError loading Opus OS\n') + _G.printError(m .. '\n') +else + if _G.kernel.routines[1] then + _G.kernel.start(terminal, kernelWindow) + end end -fs.restore() +if fs.restore then + fs.restore() +end diff --git a/sys/etc/app.db b/sys/etc/app.db index f96b432..81e2a41 100644 --- a/sys/etc/app.db +++ b/sys/etc/app.db @@ -167,9 +167,9 @@ [ "2a4d562b1d9a9c90bdede6fac8ce4f7402462b86" ] = { title = "Tasks", category = "System", - icon = "\0307 \0303\0317__\0307\031 \ -\0303 \ -\0303 ", + icon = "\030f\031f \0315/\ +\030f\031f \0315/\\/ \ +\030f\0315/\031f ", run = "Tabs.lua", }, [ "114edfc04a1ab03541bdc80ce064f66a7cfcedbb" ] = { @@ -215,9 +215,9 @@ bdc1fd5d3c0f3dcfd55d010426e61bf9451e680d = { title = "Shell", category = "Apps", - icon = "\0304 \030 \ -\0304 \030f\0314> \0310_\031 \ -\0304 \030f \030 ", + icon = "\030f\0314\151\131\131\131\131\ +\030f\0314\149\030f\0314> \0310_ \ +\030f\0314\149\030f ", run = "shell", }, [ "131f0b008f44298812221d120d982940609be781" ] = { diff --git a/sys/extensions/device.lua b/sys/extensions/device.lua index 28db335..5c593ec 100644 --- a/sys/extensions/device.lua +++ b/sys/extensions/device.lua @@ -83,7 +83,9 @@ kernel.hook({ 'mouse_click', 'mouse_up', 'mouse_drag' }, function(event, eventDa if not mouse.state[button] then return true -- ensure mouse ups are only generated if a mouse down was sent end - mouse.state[button] = nil + if event == 'mouse_up' then + mouse.state[button] = nil + end end end) diff --git a/sys/kernel.lua b/sys/kernel.lua index 8b7f1ed..2313f4b 100644 --- a/sys/kernel.lua +++ b/sys/kernel.lua @@ -24,6 +24,12 @@ local focusedRoutineEvents = Util.transpose { 'paste', 'terminate', } +_G.debug = function(pattern, ...) + local oldTerm = term.redirect(kernel.terminal) + Util.print(pattern, ...) + term.redirect(oldTerm) +end + -- any function that runs in a kernel hook does not run in -- a separate coroutine or have a window. an error in a hook -- function will crash the system. @@ -151,6 +157,13 @@ function kernel.lower(uid) local routine = Util.find(kernel.routines, 'uid', uid) if routine and #kernel.routines > 1 then + if routine == kernel.routines[1] then + local nextRoutine = kernel.routines[2] + if nextRoutine then + kernel.raise(nextRoutine.uid) + end + end + Util.removeByValue(kernel.routines, routine) table.insert(kernel.routines, routine) return true @@ -172,12 +185,7 @@ function kernel.event(event, eventData) local eventHooks = kernel.hooks[event] if eventHooks then for i = #eventHooks, 1, -1 do - local s, m = pcall(function() - stopPropagation = eventHooks[i](event, eventData) - end) - if not s then - error(m) - end + stopPropagation = eventHooks[i](event, eventData) if stopPropagation then break end @@ -199,10 +207,23 @@ function kernel.event(event, eventData) end end -function kernel.start() - repeat - local eventData = { os.pullEventRaw() } - local event = table.remove(eventData, 1) - kernel.event(event, eventData) - until event == 'kernel_halt' or not kernel.routines[1] +function kernel.start(terminal, kernelWindow) + kernel.window = kernelWindow + kernel.terminal = kernel.window + + local s, m = pcall(function() + repeat + local eventData = { os.pullEventRaw() } + local event = table.remove(eventData, 1) + kernel.event(event, eventData) + until event == 'kernel_halt' or not kernel.routines[1] + end) + + kernel.window.setVisible(true) + if not s then + term.redirect(kernel.window) + print('\nCrash detected\n') + _G.printError(m) + end + term.redirect(terminal) end diff --git a/sys/network/peripheral.lua b/sys/network/peripheral.lua index 8f5e300..3f10411 100644 --- a/sys/network/peripheral.lua +++ b/sys/network/peripheral.lua @@ -22,6 +22,7 @@ Event.addRoutine(function() -- need to prevent multiple shares if not peripheral then print('peripheral: invalid peripheral ' .. uri) + socket:write('Invalid peripheral: ' .. uri) else print('peripheral: proxing ' .. uri) local proxy = { @@ -62,6 +63,11 @@ Event.addRoutine(function() print('peripheral: lost connection from ' .. socket.dhost) break end + if not _G.device[peripheral.name] then + print('periperal: detached') + socket:close() + break + end if peripheral[data.fn] then socket:write({ peripheral[data.fn](table.unpack(data.args)) }) end diff --git a/sys/network/samba.lua b/sys/network/samba.lua index e4d156d..6469015 100644 --- a/sys/network/samba.lua +++ b/sys/network/samba.lua @@ -1,6 +1,8 @@ local Event = require('event') local Socket = require('socket') +local fs = _G.fs + local fileUid = 0 local fileHandles = { } @@ -46,10 +48,10 @@ local function sambaConnection(socket) end local ret local s, m = pcall(function() - ret = fn(unpack(msg.args)) + ret = fn(unpack(msg.args)) end) if not s and m then - printError('samba: ' .. m) + _G.printError('samba: ' .. m) end socket:write({ response = ret }) end @@ -58,7 +60,6 @@ local function sambaConnection(socket) end Event.addRoutine(function() - print('samba: listening on port 139') while true do @@ -72,11 +73,11 @@ Event.addRoutine(function() end end) -Event.on('network_attach', function(e, computer) +Event.on('network_attach', function(_, computer) fs.mount(fs.combine('network', computer.label), 'netfs', computer.id) end) -Event.on('network_detach', function(e, computer) +Event.on('network_detach', function(_, computer) print('samba: detaching ' .. computer.label) fs.unmount(fs.combine('network', computer.label)) end) diff --git a/sys/network/snmp.lua b/sys/network/snmp.lua index 3eeb919..1cefede 100644 --- a/sys/network/snmp.lua +++ b/sys/network/snmp.lua @@ -15,7 +15,6 @@ local gpsLastPoint local gpsLastRequestTime local function snmpConnection(socket) - while true do local msg = socket:read() if not msg then @@ -98,7 +97,6 @@ local function snmpConnection(socket) end Event.addRoutine(function() - print('snmp: listening on port 161') while true do @@ -137,7 +135,6 @@ local info = { local infoTimer = os.clock() local function sendInfo() - if os.clock() - infoTimer >= 1 then -- don't flood infoTimer = os.clock() info.label = os.getComputerLabel() diff --git a/sys/services/transort.lua b/sys/network/transport.lua similarity index 84% rename from sys/services/transort.lua rename to sys/network/transport.lua index 9651504..de17049 100644 --- a/sys/services/transort.lua +++ b/sys/network/transport.lua @@ -2,16 +2,14 @@ Low level socket protocol implementation. * sequencing - * write acknowledgements * background read buffering ]]-- +local Event = require('event') + local os = _G.os -_ENV._APP_TITLE = 'Net transport' - local computerId = os.getComputerID() - local transport = { timers = { }, sockets = { }, @@ -61,21 +59,18 @@ function transport.close(socket) transport.sockets[socket.sport] = nil end -print('Net transport started') +Event.on('timer', function(_, timerId) + local socket = transport.timers[timerId] -while true do - local e, timerId, dport, dhost, msg, distance = os.pullEvent() + if socket and socket.connected then + print('transport timeout - closing socket ' .. socket.sport) + socket:close() + transport.timers[timerId] = nil + end +end) - if e == 'timer' then - local socket = transport.timers[timerId] - - if socket and socket.connected then - debug('transport timeout - closing socket ' .. socket.sport) - socket:close() - transport.timers[timerId] = nil - end - - elseif e == 'modem_message' and dhost == computerId and msg then +Event.on('modem_message', function(_, _, dport, dhost, msg, distance) + if dhost == computerId and msg then local socket = transport.sockets[dport] if socket and socket.connected then @@ -85,6 +80,7 @@ while true do -- received disconnect from other end socket.connected = false socket:close() + os.queueEvent('transport_' .. socket.sport) elseif msg.type == 'ACK' then local ackTimerId = socket.timers[msg.seq] @@ -105,7 +101,7 @@ while true do elseif msg.type == 'DATA' and msg.data then socket.activityTimer = os.clock() if msg.seq ~= socket.rseq then - debug('transport seq error - closing socket ' .. socket.sport) + print('transport seq error - closing socket ' .. socket.sport) socket:close() else socket.rseq = socket.rseq + 1 @@ -125,4 +121,6 @@ while true do end end end -end +end) + +print('Net transport started') diff --git a/sys/network/vnc.lua b/sys/network/vnc.lua index e5474c2..c1dcb84 100644 --- a/sys/network/vnc.lua +++ b/sys/network/vnc.lua @@ -2,16 +2,18 @@ local Event = require('event') local Socket = require('socket') local Util = require('util') +local os = _G.os +local terminal = _ENV.multishell.term + local function vncHost(socket) local methods = { 'blit', 'clear', 'clearLine', 'setCursorPos', 'write', 'setTextColor', 'setTextColour', 'setBackgroundColor', 'setBackgroundColour', 'scroll', 'setCursorBlink', } - socket.term = multishell.term - socket.oldTerm = Util.shallowCopy(socket.term) + local oldTerm = Util.shallowCopy(terminal) for _,k in pairs(methods) do - socket.term[k] = function(...) + terminal[k] = function(...) if not socket.queue then socket.queue = { } Event.onTimeout(0, function() @@ -23,7 +25,7 @@ local function vncHost(socket) f = k, args = { ... }, }) - socket.oldTerm[k](...) + oldTerm[k](...) end end @@ -35,17 +37,17 @@ local function vncHost(socket) end if data.type == 'shellRemote' then - os.queueEvent(unpack(data.event)) + os.queueEvent(table.unpack(data.event)) elseif data.type == 'termInfo' then - socket.term.getSize = function() + terminal.getSize = function() return data.width, data.height end os.queueEvent('term_resize') end end - for k,v in pairs(socket.oldTerm) do - socket.term[k] = v + for k,v in pairs(oldTerm) do + terminal[k] = v end os.queueEvent('term_resize') end diff --git a/sys/services/log.lua b/sys/services/log.lua index 1ba194c..f5f4181 100644 --- a/sys/services/log.lua +++ b/sys/services/log.lua @@ -1,7 +1,10 @@ _G.requireInjector() +--[[ + Adds the control-d hotkey to view the kernel log. +]] + local Terminal = require('terminal') -local Util = require('util') local kernel = _G.kernel local keyboard = _G.device.keyboard @@ -9,19 +12,20 @@ local multishell = _ENV.multishell local os = _G.os local term = _G.term -_ENV._APP_TITLE = 'Debug' +if multishell and multishell.setTitle then + multishell.setTitle(multishell.getCurrent(), 'System Log') +end -term.redirect(Terminal.scrollable(term.current(), 50)) - -local tabId = multishell.getCurrent() +local routine = kernel.getCurrent() local previousId -_G.debug = function(pattern, ...) - local oldTerm = term.current() - term.redirect(kernel.terminal) - Util.print(pattern, ...) - term.redirect(oldTerm) -end +kernel.window.reposition(1, 2) +Terminal.scrollable(kernel.window, 50) + +routine.terminal = kernel.window +routine.window = kernel.window + +term.redirect(routine.window) kernel.hook('mouse_scroll', function(_, eventData) local dir, y = eventData[1], eventData[3] @@ -38,22 +42,15 @@ kernel.hook('mouse_scroll', function(_, eventData) end end) -print('Debug started') -print('Press ^d to activate debug window') - keyboard.addHotkey('control-d', function() - local currentId = multishell.getFocus() - if currentId ~= tabId then - previousId = currentId - multishell.setFocus(tabId) + local current = kernel.getFocused() + if current.uid ~= routine.uid then + previousId = current.uid + kernel.raise(routine.uid) elseif previousId then - multishell.setFocus(previousId) + kernel.raise(previousId) end end) os.pullEventRaw('terminate') - -print('Debug stopped') - -_G.debug = function() end keyboard.removeHotkey('control-d') diff --git a/sys/services/network.lua b/sys/services/network.lua index 3f32c0b..378e3f8 100644 --- a/sys/services/network.lua +++ b/sys/services/network.lua @@ -5,6 +5,7 @@ local Util = require('util') local device = _G.device local fs = _G.fs +local multishell = _ENV.multishell local network = _G.network local os = _G.os local printError = _G.printError @@ -13,7 +14,9 @@ if not device.wireless_modem then return end -_ENV._APP_TITLE = 'Net Daemon' +if multishell and multishell.setTitle then + multishell.setTitle(multishell.getCurrent(), 'Net Daemon') +end print('Net daemon started')