You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 the mem-usage-linux plugin into 1 file: a new mem-usage widget that "requires" the timer plugin.
Here's what I have so far:
widget = {
plugin = './plugins/timer/plugin-timer.so',
opts = {period = 2},
cb = function()
local f = assert(io.open('/proc/meminfo', 'r'))
local r = {}
for line in f:lines() do
local key, value, unit = line:match('(%w+):%s+(%w+)%s+(%w+)')
if key == 'MemTotal' then
r.total = {value = tonumber(value), unit = unit}
elseif key == 'MemAvailable' then
r.avail = {value = tonumber(value), unit = unit}
end
end
f:close()
local used_kb = r.total.value - r.avail.value
return string.format('[%3.2f GiB]', used_kb / 1024 / 1024)
end
}
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
The text was updated successfully, but these errors were encountered:
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.")
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:
Hi.
At the moment:
The
mem-usage
widget "requires"the
mem-usage-linux
plugin which "requires"the
timer
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
The text was updated successfully, but these errors were encountered: