-- A live tile in Lua: how busy the PC is, and how long it has been up. -- The shell runs it for the tile (see load-tile.widget) with the tile's -- id as the first argument, and it leaves by itself when the tile is -- unpinned or the shell goes. local c8 = require "c8" local function read(path, what) local file = io.open(path) if not file then return nil end local value = file:read(what) file:close() return value end c8.provider { tile = c8.args[1] or "lua-load", every = 10, -- seconds, while Start shows hidden_every = 300, -- and while it doesn't update = function() local load = read("/proc/loadavg", "n") or 0 local up = read("/proc/uptime", "n") or 0 local hours = up // 3600 return { template = "block", block = string.format("%.1f", load), text1 = "load", text2 = hours >= 24 and string.format("up %d days", hours // 24) or string.format("up %d h %d min", hours, up % 3600 // 60), } end, }