From 073f4c1a6dbe97db50db0b6782ae3db6e1075f50 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Wed, 23 Jan 2019 15:28:43 -0500 Subject: [PATCH] cloud edit + logger removal --- sys/apis/logger.lua | 133 ------------------------------------------ sys/apis/socket.lua | 12 ++-- sys/apps/Overview.lua | 4 +- sys/apps/cedit.lua | 26 +++++++++ sys/apps/cshell.lua | 12 ++++ sys/autorun/apps.lua | 1 + sys/etc/app.db | 5 ++ 7 files changed, 50 insertions(+), 143 deletions(-) delete mode 100644 sys/apis/logger.lua create mode 100644 sys/apps/cedit.lua create mode 100644 sys/apps/cshell.lua diff --git a/sys/apis/logger.lua b/sys/apis/logger.lua deleted file mode 100644 index d693f4c..0000000 --- a/sys/apis/logger.lua +++ /dev/null @@ -1,133 +0,0 @@ -local Logger = { - fn = function() end, - filteredEvents = { }, -} - -function Logger.setLogger(fn) - Logger.fn = fn -end - -function Logger.disable() - Logger.setLogger(function() end) -end - -function Logger.setDaemonLogging() - Logger.setLogger(function (text) - os.queueEvent('log', { text = text }) - end) -end - -function Logger.setMonitorLogging() - local debugMon = device.monitor - - if not debugMon then - debugMon.setTextScale(.5) - debugMon.clear() - debugMon.setCursorPos(1, 1) - Logger.setLogger(function(text) - debugMon.write(text) - debugMon.scroll(-1) - debugMon.setCursorPos(1, 1) - end) - end -end - -function Logger.setScreenLogging() - Logger.setLogger(function(text) - local x, y = term.getCursorPos() - if x ~= 1 then - local sx, sy = term.getSize() - term.setCursorPos(1, sy) - --term.scroll(1) - end - print(text) - end) -end - -function Logger.setWirelessLogging() - if device.wireless_modem then - Logger.filter('modem_message') - Logger.filter('modem_receive') - Logger.filter('rednet_message') - Logger.setLogger(function(text) - device.wireless_modem.transmit(59998, os.getComputerID(), { - type = 'log', contents = text - }) - end) - Logger.debug('Logging enabled') - return true - end -end - -function Logger.setFileLogging(fileName) - fs.delete(fileName) - Logger.setLogger(function (text) - local logFile - - local mode = 'w' - if fs.exists(fileName) then - mode = 'a' - end - local file = io.open(fileName, mode) - if file then - file:write(text) - file:write('\n') - file:close() - end - end) -end - -function Logger.log(category, value, ...) - if Logger.filteredEvents[category] then - return - end - - if type(value) == 'table' then - local str - for k,v in pairs(value) do - if not str then - str = '{ ' - else - str = str .. ', ' - end - str = str .. k .. '=' .. tostring(v) - end - if str then - value = str .. ' }' - else - value = '{ }' - end - elseif type(value) == 'string' then - local args = { ... } - if #args > 0 then - value = string.format(value, unpack(args)) - end - else - value = tostring(value) - end - Logger.fn(category .. ': ' .. value) -end - -function Logger.debug(value, ...) - Logger.log('debug', value, ...) -end - -function Logger.logNestedTable(t, indent) - for _,v in ipairs(t) do - if type(v) == 'table' then - log('table') - logNestedTable(v) --, indent+1) - else - log(v) - end - end -end - -function Logger.filter( ...) - local events = { ... } - for _,event in pairs(events) do - Logger.filteredEvents[event] = true - end -end - -return Logger \ No newline at end of file diff --git a/sys/apis/socket.lua b/sys/apis/socket.lua index 7926234..a2d2d7a 100644 --- a/sys/apis/socket.lua +++ b/sys/apis/socket.lua @@ -1,5 +1,4 @@ local Crypto = require('crypto') -local Logger = require('logger') local Security = require('security') local Util = require('util') @@ -15,7 +14,6 @@ function socketClass:read(timeout) end if not self.connected then - Logger.log('socket', 'read: No connection') return end @@ -64,7 +62,6 @@ end function socketClass:close() if self.connected then - Logger.log('socket', 'closing socket ' .. self.sport) self.transmit(self.dport, self.dhost, { type = 'DISC', }) @@ -113,7 +110,6 @@ function Socket.connect(host, port) local socket = newSocket(host == os.getComputerID()) socket.dhost = tonumber(host) - Logger.log('socket', 'connecting to ' .. port) socket.transmit(port, socket.sport, { type = 'OPEN', @@ -138,8 +134,8 @@ function Socket.connect(host, port) socket.dport = dport socket.connected = true - Logger.log('socket', 'connection established to %d %d->%d', - host, socket.sport, socket.dport) + -- Logger.log('socket', 'connection established to %d %d->%d', + -- host, socket.sport, socket.dport) _G.transport.open(socket) @@ -179,7 +175,7 @@ end function Socket.server(port) device.wireless_modem.open(port) - Logger.log('socket', 'Waiting for connections on port ' .. port) + -- Logger.log('socket', 'Waiting for connections on port ' .. port) while true do local _, _, sport, dport, msg = os.pullEvent('modem_message') @@ -203,7 +199,7 @@ function Socket.server(port) dhost = socket.dhost, shost = socket.shost, }) - Logger.log('socket', 'Connection established %d->%d', socket.sport, socket.dport) + -- Logger.log('socket', 'Connection established %d->%d', socket.sport, socket.dport) _G.transport.open(socket) return socket diff --git a/sys/apps/Overview.lua b/sys/apps/Overview.lua index 309c2c1..d823928 100644 --- a/sys/apps/Overview.lua +++ b/sys/apps/Overview.lua @@ -43,7 +43,7 @@ local buttons = { } local sx, sy = term.current().getSize() local maxRecent = math.ceil(sx * sy / 62) -local function elipse(s, len) +local function ellipsis(s, len) if #s > len then s = s:sub(1, len - 2) .. '..' end @@ -253,7 +253,7 @@ function page.container:setCategory(categoryName, animate) icon = DEFAULT_ICON end - local title = elipse(program.title, 8) + local title = ellipsis(program.title, 8) local width = math.max(icon.width + 2, #title + 2) table.insert(self.children, UI.Icon({ diff --git a/sys/apps/cedit.lua b/sys/apps/cedit.lua new file mode 100644 index 0000000..d1c1295 --- /dev/null +++ b/sys/apps/cedit.lua @@ -0,0 +1,26 @@ +local multishell = _ENV.multishell +local os = _G.os +local read = _G.read +local shell = _ENV.shell + +local args = { ... } +if not args[1] then + error('Syntax: cedit ') +end + +if not _G.cloud_catcher then + print('Paste key: ') + local key = read() + if #key == 0 then + return + end + -- open an unfocused tab + local id = shell.openTab('cloud ' .. key) + print('Connecting...') + while not _G.cloud_catcher do + os.sleep(.2) + end + multishell.setTitle(id, 'Cloud') +end + +shell.run('cloud edit ' .. table.unpack({ ... })) diff --git a/sys/apps/cshell.lua b/sys/apps/cshell.lua new file mode 100644 index 0000000..9d54e84 --- /dev/null +++ b/sys/apps/cshell.lua @@ -0,0 +1,12 @@ +local read = _G.read +local shell = _ENV.shell + +if not _G.cloud_catcher then + print('Paste key: ') + local key = read() + if #key == 0 then + return + end + print('Connecting...') + shell.run('cloud ' .. key) +end diff --git a/sys/autorun/apps.lua b/sys/autorun/apps.lua index 3d711d6..c66656b 100644 --- a/sys/autorun/apps.lua +++ b/sys/autorun/apps.lua @@ -1,3 +1,4 @@ fs.mount('sys/apps/pain.lua', 'urlfs', 'http://pastebin.com/raw/wJQ7jav0') fs.mount('sys/apps/update.lua', 'urlfs', 'http://pastebin.com/raw/UzGHLbNC') fs.mount('sys/apps/Enchat.lua', 'urlfs', 'https://raw.githubusercontent.com/LDDestroier/enchat/master/enchat3.lua') +fs.mount('sys/apps/cloud.lua', 'urlfs', 'https://cloud-catcher.squiddev.cc/cloud.lua') diff --git a/sys/etc/app.db b/sys/etc/app.db index 29b2b19..f1349ff 100644 --- a/sys/etc/app.db +++ b/sys/etc/app.db @@ -7,6 +7,11 @@ \030c\0317\151\131\0310\143\0317\131\0307\031c\148\ \0307\031c\138\030f\0317\151\131\131\131", }, + [ "b2efeaa1a7d6d2185ea02473cf758203dfcea3fe" ] = { + title = "Cloud", + category = "Apps", + run = "cshell.lua", + }, [ "53ebc572b4a44802ba114729f07bdaaf5409a9d7" ] = { title = "Network", category = "Apps",