Open jaimet opened 4 years ago
and it appears to only produce new output when the value changes (which, I think, is like the other widgets),
I've just discovered that the "no duplicate output lines" "thing" is built into the barlibs ("Temporary buffer for secondary buffering, to avoid unneeded redraws.
")
I'll get my coat! :laughing:
Could somebody who possesses more lua-fu than me please have a look at this code and confirm whether or not it is functionally equivalent to the original source,
It seems to be, except for this line:
plugin = './plugins/timer/plugin-timer.so'
Note that it now depends on the current directory (the directory that the luastatus binary was launched at).
and also whether or not it can be made more simple/easier to understand?
Probably by getting rid of the r
table and using two local variables instead:
cb = function()
local f = assert(io.open('/proc/meminfo', 'r'))
local total_kb, avail_kb
for line in f:lines() do
local key, value, unit = line:match('(%w+):%s+(%w+)%s+(%w+)')
if key == 'MemTotal' then
total_kb = tonumber(value)
elseif key == 'MemAvailable' then
avail_kb = tonumber(value)
end
end
f:close()
local used_kb = total_kb - avail_kb
return string.format('[%3.2f GiB]', used_kb / 1024 / 1024)
end
Hi.
At the moment: The
mem-usage
widget "requires" themem-usage-linux
plugin which "requires" thetimer
plugin.But for me, personally, this middle layer of indirection (the
mem-usage-linux
plugin) doesn't help me. For me, it just makes the code harder to understand and follow (this might be because I am new to lua and luastatus).So, I am trying to combine the
mem-usage
widget and themem-usage-linux
plugin into 1 file: a newmem-usage
widget that "requires" thetimer
plugin.Here's what I have so far:
I can "successfully" run this new widget and it produces what appears to be correct output, thus:
and it appears to only produce new output when the value changes (which, I think, is like the other widgets), so I think this is correct. But... I am new to lua and luastatus, so I don't feel sure that my code is functionally equivalent. Could somebody who possesses more lua-fu than me please have a look at this code and confirm whether or not it is functionally equivalent to the original source, and also whether or not it can be made more simple/easier to understand?
Thank you! Jaime