ENH make all modules take point and return y

This commit is contained in:
Nathan Dwarshuis 2022-07-14 20:13:29 -04:00
parent c5df3172a6
commit 3f6047d05d
13 changed files with 98 additions and 104 deletions

2
core

@ -1 +1 @@
Subproject commit 1cc356773a496d9abd0a400094b7b732c390201d
Subproject commit 387195607eb3a481596b6da45ec0b12b5f3c97d1

View File

@ -671,9 +671,10 @@ M.reduce_blocks_inner = function(f, y, blocks)
local r = pure.reduce(_combine_blocks, {y = y, objs = {}}, blocks)
local us, ss, ds = table.unpack(pure.unzip(r.objs))
return {
updater = f(table.unpack(non_false(pure.reverse(us)))),
static_drawer = pure.sequence(table.unpack(ss)),
dynamic_drawer = pure.sequence(table.unpack(non_false(ds)))
y = r.y,
update = f(table.unpack(non_false(pure.reverse(us)))),
static = pure.sequence(table.unpack(ss)),
dynamic = pure.sequence(table.unpack(non_false(ds)))
}
end

View File

@ -4,8 +4,7 @@ local geometry = require 'geometry'
local pure = require 'pure'
local impure = require 'impure'
return function(pathspecs)
local MODULE_Y = 170
return function(pathspecs, point)
local SPACING = 20
local BAR_PAD = 100
local SEPARATOR_SPACING = 20
@ -17,7 +16,7 @@ return function(pathspecs)
common.mk_header,
'FILE SYSTEMS',
geometry.SECTION_WIDTH,
geometry.RIGHT_X
point.x
)
-----------------------------------------------------------------------------
@ -25,7 +24,7 @@ return function(pathspecs)
local mk_smart = function(y)
local obj = common.make_text_row(
geometry.RIGHT_X,
point.x,
y,
geometry.SECTION_WIDTH,
'SMART Daemon'
@ -47,7 +46,7 @@ return function(pathspecs)
local mk_sep = pure.partial(
common.mk_seperator,
geometry.SECTION_WIDTH,
geometry.RIGHT_X
point.x
)
-----------------------------------------------------------------------------
@ -60,7 +59,7 @@ return function(pathspecs)
paths
)
local obj = common.make_compound_bar(
geometry.RIGHT_X,
point.x,
y,
geometry.SECTION_WIDTH,
BAR_PAD,
@ -88,8 +87,8 @@ return function(pathspecs)
-----------------------------------------------------------------------------
-- main functions
local rbs = common.reduce_blocks_(
MODULE_Y,
return common.reduce_blocks_(
point.y,
{
common.mk_block(mk_header, true, 0),
common.mk_block(mk_smart, true, 0),
@ -97,10 +96,4 @@ return function(pathspecs)
common.mk_block(mk_bars, true, SEPARATOR_SPACING),
}
)
return {
static = rbs.static_drawer,
dynamic = rbs.dynamic_drawer,
update = rbs.updater
}
end

View File

@ -3,8 +3,7 @@ local i_o = require 'i_o'
local common = require 'common'
local geometry = require 'geometry'
return function(update_freq)
local MODULE_Y = 145
return function(update_freq, point)
local SEPARATOR_SPACING = 20
local TEXT_SPACING = 20
local PLOT_SEC_BREAK = 20
@ -28,7 +27,7 @@ return function(update_freq)
local _mk_plot = function(label, getter, y)
local obj = common.make_tagged_maybe_percent_timeseries(
geometry.LEFT_X,
point.x,
y,
geometry.SECTION_WIDTH,
PLOT_HEIGHT,
@ -53,7 +52,7 @@ return function(update_freq)
common.mk_header,
'NVIDIA GRAPHICS',
geometry.SECTION_WIDTH,
geometry.LEFT_X
point.x
)
-----------------------------------------------------------------------------
@ -61,7 +60,7 @@ return function(update_freq)
local mk_status = function(y)
local obj = common.make_text_row(
geometry.LEFT_X,
point.x,
y,
geometry.SECTION_WIDTH,
'Status'
@ -81,7 +80,7 @@ return function(update_freq)
local mk_sep = pure.partial(
common.mk_seperator,
geometry.SECTION_WIDTH,
geometry.LEFT_X
point.x
)
-----------------------------------------------------------------------------
@ -89,7 +88,7 @@ return function(update_freq)
local mk_temp = function(y)
local obj = common.make_threshold_text_row(
geometry.LEFT_X,
point.x,
y,
geometry.SECTION_WIDTH,
'Internal Temperature',
@ -113,7 +112,7 @@ return function(update_freq)
local mk_clock = function(y)
local obj = common.make_text_rows(
geometry.LEFT_X,
point.x,
y,
geometry.SECTION_WIDTH,
TEXT_SPACING,
@ -223,7 +222,7 @@ return function(update_freq)
-- main drawing functions
local rbs = common.reduce_blocks_(
MODULE_Y,
point.y,
{
common.mk_block(mk_header, true, 0),
common.mk_block(mk_status, true, 0),
@ -237,10 +236,5 @@ return function(update_freq)
common.mk_block(mk_vid_util, true, PLOT_SEC_BREAK)
}
)
return {
static = rbs.static_drawer,
dynamic = rbs.dynamic_drawer,
update = function() rbs.updater(update_state()) end
}
return pure.map_at("update", function(f) return function() f(update_state()) end end, rbs)
end

View File

@ -5,8 +5,7 @@ local common = require 'common'
local geometry = require 'geometry'
local pure = require 'pure'
return function(update_freq)
local MODULE_Y = 712
return function(update_freq, point)
local DIAL_THICKNESS = 8
local DIAL_RADIUS = 32
local DIAL_SPACING = 40
@ -28,18 +27,18 @@ return function(update_freq)
common.mk_header,
'MEMORY',
geometry.SECTION_WIDTH,
geometry.RIGHT_X
point.x
)
-----------------------------------------------------------------------------
-- mem stats (dial + text)
local mk_stats = function(y)
local MEM_X = geometry.RIGHT_X + DIAL_RADIUS + DIAL_THICKNESS / 2
local MEM_X = point.x + DIAL_RADIUS + DIAL_THICKNESS / 2
local DIAL_DIAMETER = DIAL_RADIUS * 2 + DIAL_THICKNESS
local SWAP_X = MEM_X + DIAL_DIAMETER + DIAL_SPACING
local CACHE_X = SWAP_X + CACHE_X_OFFSET + DIAL_DIAMETER / 2
local CACHE_WIDTH = geometry.RIGHT_X + geometry.SECTION_WIDTH - CACHE_X
local CACHE_WIDTH = point.x + geometry.SECTION_WIDTH - CACHE_X
local format_percent = function(x)
return string.format('%i%%', x)
end
@ -98,7 +97,7 @@ return function(update_freq)
local mk_plot = function(y)
local obj = common.make_percent_timeseries(
geometry.RIGHT_X,
point.x,
y,
geometry.SECTION_WIDTH,
PLOT_HEIGHT,
@ -127,7 +126,7 @@ return function(update_freq)
end,
NUM_ROWS)
local obj = common.make_text_table(
geometry.RIGHT_X,
point.x,
y,
geometry.SECTION_WIDTH,
TABLE_HEIGHT,
@ -190,7 +189,7 @@ return function(update_freq)
-- main functions
local rbs = common.reduce_blocks_(
MODULE_Y,
point.y,
{
common.mk_block(mk_header, true, 0),
common.mk_block(mk_stats, true, 0),
@ -198,10 +197,5 @@ return function(update_freq)
common.mk_block(mk_tbl, true, TABLE_SECTION_BREAK),
}
)
return {
static = rbs.static_drawer,
dynamic = rbs.dynamic_drawer,
update = function() rbs.updater(read_state()) end,
}
return pure.map_at("update", function(f) return function() f(read_state()) end end, rbs)
end

View File

@ -4,7 +4,7 @@ local common = require 'common'
local geometry = require 'geometry'
local sys = require 'sys'
return function(update_freq)
return function(update_freq, point)
local PLOT_SEC_BREAK = 20
local PLOT_HEIGHT = 56
local INTERFACE_PATHS = sys.get_net_interface_paths()
@ -33,7 +33,7 @@ return function(update_freq)
local make_plot = function(y, label, init)
return common.make_rate_timeseries(
geometry.CENTER_RIGHT_X,
point.x,
y,
geometry.SECTION_WIDTH,
PLOT_HEIGHT,
@ -51,8 +51,8 @@ return function(update_freq)
-- header
local header = common.make_header(
geometry.CENTER_RIGHT_X,
geometry.TOP_Y,
point.x,
point.y,
geometry.SECTION_WIDTH,
'NETWORK'
)

View File

@ -1,21 +1,21 @@
local common = require 'common'
local geometry = require 'geometry'
return function()
return function(point)
local TEXT_SPACING = 20
local __string_match = string.match
local __string_gmatch = string.gmatch
local header = common.make_header(
geometry.RIGHT_X,
geometry.TOP_Y,
point.x,
point.y,
geometry.SECTION_WIDTH,
'PACMAN'
)
local rows = common.make_text_rows(
geometry.RIGHT_X,
point.x,
header.bottom_y,
geometry.SECTION_WIDTH,
TEXT_SPACING,

View File

@ -4,8 +4,7 @@ local common = require 'common'
local geometry = require 'geometry'
local sys = require 'sys'
return function(update_freq, battery)
local MODULE_Y = 380
return function(update_freq, battery, point)
local TEXT_SPACING = 20
local PLOT_SEC_BREAK = 20
local PLOT_HEIGHT = 56
@ -41,7 +40,7 @@ return function(update_freq, battery)
local mk_rate_plot = function(label, read, y)
local obj = common.make_rate_timeseries(
geometry.RIGHT_X,
point.x,
y,
geometry.SECTION_WIDTH,
PLOT_HEIGHT,
@ -68,7 +67,7 @@ return function(update_freq, battery)
common.mk_header,
'POWER',
geometry.SECTION_WIDTH,
geometry.RIGHT_X
point.x
)
-----------------------------------------------------------------------------
@ -94,7 +93,7 @@ return function(update_freq, battery)
local mk_bat = function(y)
local obj = common.make_tagged_scaled_timeseries(
geometry.RIGHT_X,
point.x,
y,
geometry.SECTION_WIDTH,
PLOT_HEIGHT,
@ -118,8 +117,8 @@ return function(update_freq, battery)
-----------------------------------------------------------------------------
-- main functions
local rbs = common.reduce_blocks_(
MODULE_Y,
return common.reduce_blocks_(
point.y,
{
common.mk_block(mk_header, true, 0),
common.mk_block(mk_pkg0, true, 0),
@ -127,10 +126,4 @@ return function(update_freq, battery)
common.mk_block(mk_bat, true, TEXT_SPACING),
}
)
return {
static = rbs.static_drawer,
dynamic = rbs.dynamic_drawer,
update = rbs.updater
}
end

View File

@ -8,12 +8,11 @@ local pure = require 'pure'
local __math_floor = math.floor
return function(update_freq)
return function(update_freq, point)
-- local SHOW_DIALS = true
-- local SHOW_TIMESERIES = true
-- local SHOW_TABLE = true
local MODULE_Y = 614
local DIAL_INNER_RADIUS = 30
local DIAL_OUTER_RADIUS = 42
local DIAL_THICKNESS = 5.5
@ -31,7 +30,7 @@ return function(update_freq)
common.mk_header,
'PROCESSOR',
geometry.SECTION_WIDTH,
geometry.LEFT_X
point.x
)
-----------------------------------------------------------------------------
@ -78,7 +77,7 @@ return function(update_freq)
local cores = {}
-- TODO what happens when the number of cores changes?
for c = 1, ncores do
local dial_x = geometry.LEFT_X + DIAL_OUTER_RADIUS +
local dial_x = point.x + DIAL_OUTER_RADIUS +
(geometry.SECTION_WIDTH - 2 * DIAL_OUTER_RADIUS) * (c - 1) / 3
local dial_y = y + DIAL_OUTER_RADIUS
cores[c] = create_core(dial_x, dial_y)
@ -122,7 +121,7 @@ return function(update_freq)
local mk_hwp_freq = function(y)
local hwp_paths = cpu.get_hwp_paths()
local cpu_status = common.make_text_rows(
geometry.LEFT_X,
point.x,
y,
geometry.SECTION_WIDTH,
TEXT_SPACING,
@ -149,7 +148,7 @@ return function(update_freq)
local mk_sep = pure.partial(
common.mk_seperator,
geometry.SECTION_WIDTH,
geometry.LEFT_X
point.x
)
-----------------------------------------------------------------------------
@ -157,7 +156,7 @@ return function(update_freq)
local mk_load_plot = function(y)
local total_load = common.make_tagged_percent_timeseries(
geometry.LEFT_X,
point.x,
y,
geometry.SECTION_WIDTH,
PLOT_HEIGHT,
@ -187,7 +186,7 @@ return function(update_freq)
NUM_ROWS
)
local tbl = common.make_text_table(
geometry.LEFT_X,
point.x,
y,
geometry.SECTION_WIDTH,
TABLE_HEIGHT,
@ -214,7 +213,7 @@ return function(update_freq)
-- main functions
local rbs = common.reduce_blocks(
MODULE_Y,
point.y,
{
common.mk_block(mk_header, true, 0),
common.mk_block(mk_cores, true, 0),
@ -225,14 +224,13 @@ return function(update_freq)
}
)
local update = function(trigger)
rbs.updater(update_state(trigger, state.cpu_loads))
end
-- TODO return the bottom y/height of the entire module
return {
static = rbs.static_drawer,
dynamic = rbs.dynamic_drawer,
update = update
}
return pure.map_at(
"update",
function(f)
return function(trigger)
f(update_state(trigger, state.cpu_loads))
end
end,
rbs
)
end

View File

@ -3,7 +3,7 @@ local common = require 'common'
local geometry = require 'geometry'
local sys = require 'sys'
return function(update_freq, devices)
return function(update_freq, devices, point)
local PLOT_SEC_BREAK = 20
local PLOT_HEIGHT = 56
-- TODO currently this will find any block device
@ -18,7 +18,7 @@ return function(update_freq, devices)
local make_plot = function(y, label, init)
return common.make_rate_timeseries(
geometry.CENTER_LEFT_X,
point.x,
y,
geometry.SECTION_WIDTH,
PLOT_HEIGHT,
@ -36,8 +36,8 @@ return function(update_freq, devices)
-- header
local header = common.make_header(
geometry.CENTER_LEFT_X,
geometry.TOP_Y,
point.x,
point.y,
geometry.SECTION_WIDTH,
'INPUT / OUTPUT'
)

View File

@ -4,6 +4,24 @@ local geometry = require 'geometry'
local geom = require 'geom'
local fill_rect = require 'fill_rect'
local _combine_modules = function(acc, new)
local n = new(acc.point)
table.insert(acc.funs, n.fun)
acc.point = geom.make_point(acc.point.x, acc.point + n.y)
return acc
end
local reduce_modules_inner = function(y, mods)
local r = pure.reduce(_combine_modules, {y = y, mods = {}}, mods)
-- local us, ss, ds = table.unpack(pure.unzip(r.mods))
return pure.unzip(r.mods)
-- return {
-- updater = pure.sequence(table.unpack(us)),
-- draw_static = pure.sequence(table.unpack(ss)),
-- draw_dynamic = pure.sequence(table.unpack(ds))
-- }
end
return function(module_sets)
local __cairo_set_source_surface = cairo_set_source_surface
local __cairo_image_surface_create = cairo_image_surface_create
@ -65,6 +83,7 @@ return function(module_sets)
__cairo_paint(cr)
end
-- return a table with update, static, and dynamic components
return function(cr)
for i = 1, #cs do
draw_static_surface(cr, cs[i])

View File

@ -2,20 +2,20 @@ local i_o = require 'i_o'
local common = require 'common'
local geometry = require 'geometry'
return function()
return function(point)
local TEXT_SPACING = 20
local __string_match = string.match
local header = common.make_header(
geometry.LEFT_X,
geometry.TOP_Y,
point.x,
point.y,
geometry.SECTION_WIDTH,
'SYSTEM'
)
local rows = common.make_text_rows(
geometry.LEFT_X,
point.x,
header.bottom_y,
geometry.SECTION_WIDTH,
TEXT_SPACING,

View File

@ -17,6 +17,8 @@ package.path = ABS_PATH..'?.lua;'..
ABS_PATH..'core/widget/line/?.lua;'
local i_o = require 'i_o'
local geom = require 'geom'
local geometry = require 'geometry'
local sys = require 'sys'
local system = require 'system'
local network = require 'network'
@ -46,15 +48,15 @@ function conky_start(update_interval)
{'/tmp', 'tmpfs'}
}
local mem = memory(update_freq)
local rw = readwrite(update_freq, devices)
local net = network(update_freq)
local pwr = power(update_freq, battery)
local fs = filesystem(fs_paths)
local stm = system()
local gfx = graphics(update_freq)
local proc = processor(update_freq)
local pcm = pacman()
local mem = memory(update_freq, geom.make_point(geometry.RIGHT_X, 712))
local rw = readwrite(update_freq, devices, geom.make_point(geometry.CENTER_LEFT_X, geometry.TOP_Y))
local net = network(update_freq, geom.make_point(geometry.CENTER_RIGHT_X, geometry.TOP_Y))
local pwr = power(update_freq, battery, geom.make_point(geometry.RIGHT_X, 380))
local fs = filesystem(fs_paths, geom.make_point(geometry.RIGHT_X, 170))
local stm = system(geom.make_point(geometry.LEFT_X, geometry.TOP_Y))
local gfx = graphics(update_freq, geom.make_point(geometry.LEFT_X, 145))
local proc = processor(update_freq, geom.make_point(geometry.LEFT_X, 614))
local pcm = pacman(geom.make_point(geometry.RIGHT_X, geometry.TOP_Y))
local using_ac = sys.battery_status_reader(battery)