From d26092baa6c1a12ccc4edc51f3177bc26216578b Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Wed, 13 Feb 2019 23:45:39 -0500 Subject: [PATCH] milo stats --- milo/MiloLocal.lua | 16 +++++++++++++++- milo/plugins/statsView.lua | 24 ++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/milo/MiloLocal.lua b/milo/MiloLocal.lua index f4a8b64..c51223b 100644 --- a/milo/MiloLocal.lua +++ b/milo/MiloLocal.lua @@ -67,6 +67,7 @@ local context = { tasks = { }, queue = { }, plugins = { }, + loggers = { }, storage = Storage(), turtleInventory = { @@ -187,4 +188,17 @@ os.queueEvent( context.storage:isOnline() and 'storage_online' or 'storage_offline', context.storage:isOnline()) -UI:pullEvents() +local oldDebug = _G._debug +_G._debug = function(...) + for _,v in pairs(context.loggers) do + v(...) + end + oldDebug(...) +end + +local s, m = pcall(function() + UI:pullEvents() +end) + +_G._debug = oldDebug +if not s then error(m) end diff --git a/milo/plugins/statsView.lua b/milo/plugins/statsView.lua index 39b0030..4dd2318 100644 --- a/milo/plugins/statsView.lua +++ b/milo/plugins/statsView.lua @@ -8,6 +8,7 @@ local colors = _G.colors local context = Milo:getContext() local device = _G.device local os = _G.os +local term = _G.term --[[ Configuration Page ]]-- local template = @@ -136,7 +137,13 @@ local function createPage(node) }, sortColumn = 'name', }, - } + }, + [5] = UI.Tab { + tabTitle = 'Activity', + term = UI.Embedded { + --visible = true, + }, + }, }, timestamp = os.clock(), } @@ -145,6 +152,7 @@ local function createPage(node) local statsTab = page.tabs[2] local usageTab = page.tabs[3] local stateTab = page.tabs[4] + local activityTab = page.tabs[5] local function getStorageStats() local stats, totals = { }, { usedSlots = 0, totalSlots = 0, totalChests = 0 } @@ -302,7 +310,7 @@ Nodes : %d self:draw() self:sync() end) - Event.on({ 'milo_resume', 'milo_pause', 'storage_offline', 'storage_online' }, function() + self.ehandle = Event.on({ 'milo_resume', 'milo_pause', 'storage_offline', 'storage_online' }, function() self:draw() self:sync() end) @@ -311,8 +319,20 @@ Nodes : %d function overviewTab:disable() Event.off(self.handle) + Event.off(self.ehandle) end + table.insert(context.loggers, function(...) + local oterm = term.redirect(activityTab.term.win) + activityTab.term.win.scrollBottom() + Util.print(...) +_G._p = activityTab.term + term.redirect(oterm) + if activityTab.enabled then + activityTab:sync() + end + end) + UI:setPage(page) return page end