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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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