From 0ac49235685a74cd7f186ee56c2744d5b5a39d79 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Wed, 18 Mar 2020 01:57:05 +1100 Subject: [PATCH] added a free function to shutil --- lib/shutil.lua | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/shutil.lua b/lib/shutil.lua index f7abd4f..0de93ef 100644 --- a/lib/shutil.lua +++ b/lib/shutil.lua @@ -3,6 +3,17 @@ local fs = require "fs" local shell = require "shell" local shutil = {} +local function wrapUnits(n) + local scale = {"K","M","G","T","P"} + local count = 0 + while n >= 1024 do + count = count + 1 + if not scale[count] then return "inf" end + n = n / 1024 + end + return tostring(math.floor(n))..(scale[count] or "") +end + function shutil.import(lib) local cE = os.getenv("INCLUDE") or shell.include local nE = {} @@ -51,16 +62,6 @@ function shutil.df() ml = v:len() end end - local scale = {"K","M","G","T","P"} - local function wrapUnits(n) - local count = 0 - while n > 1024 do - count = count + 1 - if not scale[count] then return "inf" end - n = n / 1024 - end - return tostring(math.floor(n))..(scale[count] or "") - end local fstr = "%-"..tostring(ml).."s %5s %5s" print("fs"..(" "):rep(ml-2).." size used") for k,v in pairs(mt) do @@ -94,6 +95,11 @@ function shutil.mount(addr,path) end end +function shutil.free() + print("Total Used Free") + print(string.format("%5s %5s %5s",wrapUnits(computer.totalMemory()),wrapUnits(computer.totalMemory()-computer.freeMemory()),wrapUnits(computer.freeMemory()))) +end + shutil.cd = os.chdir shutil.mkdir = fs.makeDirectory shutil.cp = fs.copy