diskusage

This commit is contained in:
kepler155c@gmail.com 2019-07-02 14:25:17 -04:00
parent 6ba458646f
commit 2f5aea912b
1 changed files with 24 additions and 17 deletions

View File

@ -1,8 +1,12 @@
local UI = require('opus.ui') local UI = require('opus.ui')
local Event = require('opus.event') local Event = require('opus.event')
local Util = require('opus.util')
local NFT = require('opus.nft') local NFT = require('opus.nft')
local colors = _G.colors
local fs = _G.files
local os = _G.os
local peripheral = _G.peripheral
local NftImages = { local NftImages = {
blank = '\30\56\31\55\153\153\153\153\153\153\153\153\10\30\55\31\56\153\153\153\153\153\153\153\153\10\30\56\31\55\153\153\153\153\153\153\153\153\10\30\55\31\56\153\153\153\153\153\153\153\153\10\30\56\31\55\153\153\153\153\153\153\153\153', blank = '\30\56\31\55\153\153\153\153\153\153\153\153\10\30\55\31\56\153\153\153\153\153\153\153\153\10\30\56\31\55\153\153\153\153\153\153\153\153\10\30\55\31\56\153\153\153\153\153\153\153\153\10\30\56\31\55\153\153\153\153\153\153\153\153',
drive = '', drive = '',
@ -11,40 +15,42 @@ local NftImages = {
} }
local tab = UI.Tab { local tab = UI.Tab {
tabTitle = '1.Disks Usage', tabTitle = 'Disks Usage',
description = 'Visualise HDD and disks usage', description = 'Visualise HDD and disks usage',
drives = UI.ScrollingGrid { drives = UI.ScrollingGrid {
y = 2, ey = 9, x = 2, ex = '47%', x = 2, y = 1,
ex = '47%', ey = 8,
columns = { columns = {
{ heading = 'Drive', key = 'name' }, { heading = 'Drive', key = 'name' },
{ heading = 'Side' ,key = 'side', textColor = colors.yellow } { heading = 'Side' ,key = 'side', textColor = colors.yellow }
}, },
sortColumn = 'name', sortColumn = 'name',
}, },
infos = UI.Grid { infos = UI.Grid {
x = '52%', y = 3, ex = -2, ey = 9, x = '52%', y = 2,
ex = -2, ey = 8,
disableHeader = true, disableHeader = true,
unfocusedBackgroundSelectedColor = colors.black, unfocusedBackgroundSelectedColor = colors.black,
inactive = true, inactive = true,
backgroundSelectedColor = colors.black, --?? backgroundSelectedColor = colors.black,
columns = { columns = {
{key = 'name' }, { key = 'name' },
{key = 'value', align = 'right', textColor = colors.yellow }, { key = 'value', align = 'right', textColor = colors.yellow },
} }
}, },
progress = UI.ProgressBar { progress = UI.ProgressBar {
x = 11, y = 11, ex = -2, x = 11, y = 10,
barChar = '\127', ex = -2,
textColor = colors.blue,
backgroundColor = colors.black,
}, },
percentage = UI.Text { percentage = UI.Text {
x = 11, y = 12, ex = -2, x = 11, y = 11,
ex = -2,
align = 'center', align = 'center',
}, },
icon = UI.NftImage { icon = UI.NftImage {
x = 2, y = 11, x = 2, y = 10,
image = NFT.parse(NftImages.blank) image = NFT.parse(NftImages.blank)
}, },
} }
@ -96,7 +102,8 @@ local function getDriveInfo(p)
end end
end end
recurse(p) recurse(p)
local info = {} local info = {}
table.insert(info, { name = 'Type', value = peripheral.getType(drive) or drive }) table.insert(info, { name = 'Type', value = peripheral.getType(drive) or drive })
table.insert(info, { name = 'Used', value = total }) table.insert(info, { name = 'Used', value = total })
@ -113,7 +120,7 @@ function tab:updateInfo()
local info, percent = getDriveInfo(selected and selected.name or self.drives.values[1].name) local info, percent = getDriveInfo(selected and selected.name or self.drives.values[1].name)
self.infos:setValues(info) self.infos:setValues(info)
self.progress.value = percent self.progress.value = percent
self.percentage.value = ('%#3d%% used'):format(percent) self.percentage.value = ('%#3d%%'):format(percent)
self:draw() self:draw()
end end
@ -137,7 +144,7 @@ function tab:eventHandler(event)
end end
Event.on({ 'disk', 'disk_eject' }, function() Event.on({ 'disk', 'disk_eject' }, function()
sleep(1) os.sleep(1)
tab:updateDrives() tab:updateDrives()
tab:updateInfo() tab:updateInfo()
tab:sync() tab:sync()