ENH I caved and used "mvar" for main thread state reference

This commit is contained in:
Nathan Dwarshuis 2022-07-16 00:27:27 -04:00
parent 9bb16d80d3
commit 3046cad9bc
7 changed files with 34 additions and 32 deletions

View File

@ -4,7 +4,7 @@ local geometry = require 'geometry'
local pure = require 'pure'
local impure = require 'impure'
return function(pathspecs, point)
return function(pathspecs, main_state, point)
local SPACING = 20
local BAR_PAD = 100
local SEPARATOR_SPACING = 20
@ -19,8 +19,8 @@ return function(pathspecs, point)
geometry.SECTION_WIDTH,
'SMART Daemon'
)
local update = function(state)
if state.trigger10 == 0 then
local update = function()
if main_state.trigger10 == 0 then
local pid = i_o.execute_cmd('pidof smartd', nil, '*n')
common.text_row_set(obj, (pid == '') and 'Error' or 'Running')
end
@ -62,8 +62,8 @@ return function(pathspecs, point)
local read_fs = function(index, cmd)
common.compound_bar_set(obj, index, i_o.conky_numeric(cmd))
end
local update = function(state)
if state.trigger10 == 0 then
local update = function()
if main_state.trigger10 == 0 then
impure.ieach(read_fs, CONKY_CMDS)
end
end

View File

@ -2,7 +2,7 @@ local common = require 'common'
local pure = require 'pure'
local geometry = require 'geometry'
return function(point)
return function(main_state, point)
local TEXT_SPACING = 20
local __string_match = string.match
@ -16,9 +16,9 @@ return function(point)
TEXT_SPACING,
{'Total', 'Explicit', 'Outdated', 'Orphaned', 'Local'}
)
local update = function(state)
local update = function()
local stats = __string_match(
state.pacman_stats,
main_state.pacman_stats,
'%d+%s+[^%s]+%s+[^%s]+%s+(.*)$'
)
if stats then

View File

@ -4,7 +4,7 @@ local common = require 'common'
local geometry = require 'geometry'
local sys = require 'sys'
return function(update_freq, battery, point)
return function(update_freq, battery, main_state, point)
local TEXT_SPACING = 20
local PLOT_SEC_BREAK = 20
local PLOT_HEIGHT = 56
@ -98,8 +98,11 @@ return function(update_freq, battery, point)
return common.mk_acc(
geometry.SECTION_WIDTH,
PLOT_HEIGHT + PLOT_SEC_BREAK,
function(state)
common.tagged_scaled_timeseries_set(obj, read_battery_power(state.is_using_ac))
function()
common.tagged_scaled_timeseries_set(
obj,
read_battery_power(main_state.is_using_ac
))
end,
mk_static(obj),
mk_dynamic(obj)

View File

@ -8,7 +8,7 @@ local pure = require 'pure'
local __math_floor = math.floor
return function(update_freq, point)
return function(update_freq, main_state, point)
-- local SHOW_DIALS = true
-- local SHOW_TIMESERIES = true
-- local SHOW_TABLE = true
@ -27,15 +27,15 @@ return function(update_freq, point)
-- cores (loads and temps)
-- this totally is not supposed to be a state monad (ssssh...)
local update_state = function(trigger, cpu_loads)
local update_state = function(cpu_loads)
return {
cpu_loads = cpu.read_cpu_loads(cpu_loads),
load_sum = 0,
trigger = trigger
trigger = main_state.trigger10
}
end
local state = update_state(0, cpu.init_cpu_loads())
local state = update_state(cpu.init_cpu_loads())
local ncpus = cpu.get_cpu_number()
local ncores = cpu.get_core_number()
local nthreads = ncpus / ncores
@ -242,8 +242,8 @@ return function(update_freq, point)
return pure.map_at(
"update",
function(f)
return function(main_state)
f(update_state(main_state.trigger10, state.cpu_loads))
return function()
f(update_state(state.cpu_loads))
end
end,
rbs

View File

@ -72,7 +72,7 @@ local build_surface = function(box, fs)
return {x = cs_x, y = cs_y, s = cs}
end
local reduce_static = function(y, margins, spacing, acc, panel_mods)
local reduce_static = function(y, margins, acc, panel_mods)
if type(panel_mods) == "number" then
acc.next_x = acc.next_x + panel_mods
else
@ -97,8 +97,7 @@ return function(point, module_sets)
pure.partial(
reduce_static,
point.y,
{x = geometry.PANEL_MARGIN_X, y = geometry.PANEL_MARGIN_Y},
20
{x = geometry.PANEL_MARGIN_X, y = geometry.PANEL_MARGIN_Y}
),
{next_x = point.x, static = {}, update = {}, dynamic = {}},
module_sets

View File

@ -3,7 +3,7 @@ local pure = require 'pure'
local common = require 'common'
local geometry = require 'geometry'
return function(point)
return function(main_state, point)
local TEXT_SPACING = 20
local __string_match = string.match
@ -16,11 +16,11 @@ return function(point)
TEXT_SPACING,
{'Kernel', 'Uptime', 'Last Upgrade', 'Last Sync'}
)
local update = function(state)
local update = function()
local last_update, last_sync
if state.pacman_stats then
if main_state.pacman_stats then
last_update, last_sync = __string_match(
state.pacman_stats,
main_state.pacman_stats,
"^%d+%s+([^%s]+)%s+([^%s]+).*"
)
end

View File

@ -33,8 +33,6 @@ local static = require 'static'
local draw_dynamic
local main_state = {}
function conky_start(update_interval)
conky_set_update_interval(update_interval)
@ -50,15 +48,17 @@ function conky_start(update_interval)
{'/tmp', 'tmpfs'}
}
local main_state = {}
local mem = pure.partial(memory, update_freq)
local rw = pure.partial(readwrite, update_freq, devices)
local net = pure.partial(network, update_freq)
local pwr = pure.partial(power, update_freq, battery)
local fs = pure.partial(filesystem, fs_paths)
local stm = system
local pwr = pure.partial(power, update_freq, battery, main_state)
local fs = pure.partial(filesystem, fs_paths, main_state)
local stm = pure.partial(system, main_state)
local gfx = pure.partial(graphics, update_freq)
local proc = pure.partial(processor, update_freq)
local pcm = pacman
local proc = pure.partial(processor, update_freq, main_state)
local pcm = pure.partial(pacman, main_state)
local using_ac = sys.battery_status_reader(battery)
@ -81,7 +81,7 @@ function conky_start(update_interval)
main_state.is_using_ac = using_ac()
compiled.static(cr)
compiled.update(main_state)
compiled.update()
compiled.dynamic(cr)
end
end