{up, down}速度图未使用 `lua_parse lua_func` 显示

{up, down}速度图未使用 `lua_parse lua_func` 显示

这是我的conkyrc

conky.config = {
    use_xft = true, -- use xft?
    font = 'DejaVuSans:size=9', -- font name
    xftalpha = 1,
    uppercase = false, -- all text in uppercase?
    pad_percents = 0,
    text_buffer_size = 2048,
    override_utf8_locale = true, -- Force UTF8? note that UTF8 support required XFT
    use_spacer = 'none', -- Add spaces to keep things from moving about?  This only affects certain objects.

    update_interval = 1, -- Update interval in seconds
    double_buffer = true, -- Use double buffering (reduces flicker, may not work for everyone)
    total_run_times = 0, -- This is the number of times Conky will update before quitting. Set to zero to run forever.

    -- Create own window instead of using desktop (required in nautilus)
    own_window = true,
    own_window_class = 'Conky',
    own_window_transparent = true,
    own_window_argb_visual = true,
    own_window_argb_value = 255,
    own_window_type = 'desktop', -- transparency seems to work without this line
    own_window_hints = 'undecorated,sticky,below,skip_taskbar,skip_pager',

    -- Minimum size of text area
    minimum_height = 50,
    minimum_width = 210,

    draw_shades = false, -- draw shades?
    draw_outline = false, -- draw outlines?
    draw_borders = false, -- draw borders around text?
    draw_graph_borders = false, -- draw borders around graphs
    stippled_borders = 0, -- stripled borders?

    imlib_cache_size = 0, -- Imlib2 image cache size, in bytes. Increase this value if you use $image lots. Set to 0 to disable the image cache.

    -- Gap between borders of screen and text. Same thing as passing -x at command line
    gap_x = 90,
    gap_y = 5,

    alignment = 'middle_right', -- alignment on {y_axis}_{x_axis}

    cpu_avg_samples = 2, -- number of cpu samples to average. set to 1 to disable averaging
    net_avg_samples = 2, -- number of net samples to average. set to 1 to disable averaging

    no_buffers = true, -- Subtract file system buffers from used memory?

    default_color = 'e0e0e0',
    default_shade_color = '000000',
    default_outline_color = '000000',

    temperature_unit = 'celsius',

    color1 = 'ff55ff', -- heading's color
    color2 = 'ffffff', -- normal text's color

    lua_load = '.conky/netdevs.lua',
};

conky.text = [[
...
${color1}NET: ${hr 2}${color2}${lua_parse conky_show_netdevs}
...
]]

这是.config/netdevs.lua

-- conky_show_netdevs : template for network
-- usage : ${lua_parse conky_show_netdevs}

prev_result = ""

function conky_show_netdevs()
    updates = tonumber(conky_parse("${updates}"))
    interval = 10
    timer = (updates % interval)

    if timer == 0 or prev_result == "" then
        local netdevs_handle = io.popen("ip -j link show up | jq -r '.[] | select(.operstate == \"UP\" and .ifname != \"lo\") | .ifname'")
        local result = ""

        for netdev in netdevs_handle:lines() do
            result = result .. "\nIP (${color1}" .. netdev .. "${color2}): ${alignr}${addr " .. netdev .. "}\n" ..
                     "${color2}Up: ${color2}${upspeed " .. netdev .. "}/s${color1}${alignr}${upspeedgraph " .. netdev .. " 10,170}\n" ..
                     "${color2}Down: ${color2}${downspeed " .. netdev .. "}/s${color1}${alignr}${downspeedgraph " .. netdev .. " 10,170}\n" ..
                     "${color2}Total Down: ${color2}${totaldown " .. netdev .. "}${alignr}Total Up: ${totalup " .. netdev .. "}\n"
        end

        netdevs_handle:close()

        if result ~= "" then
            prev_result = result
        else
            prev_result = "\n"
        end
    end

    return prev_result
end

除了函数输出中返回的upspeedgraphs 和s 之外,一切正常。downspeedgraphconky_show_netdevs()

这是我可以看到的图表图像(图像最后一部分中的小线;在出现文本“UP”和“DOWN”的行上):

康基窗


据我所知,我认为这个问题是由于每次 conky 重新加载时都会解析 lua 函数的内容而引起的,这可能会导致图形重新加载。所以,我尝试将conky的更新间隔增加到10秒。但仍然没有运气:(

答案1

不幸的是,lua_parse它将在每个更新周期运行,因此每次都会创建一个新的空图。如果您只想在开始时创建一次配置的网络部分,您可以利用该.conkyrc文件只是一个 lua 文件这一事实,因此您可以将 lua 代码放入其中。

使用它来调用生成配置字符串的修订函数,并将其连接到变量上conky.text。 (你曾经能够在 lua 中以全局方式访问它,但这似乎不再可能了)。

所以终止.conkyrc

conky.text = [[
...
${color1}NET: ${hr 2}${color2}
]]
require 'netdevs'
conky.text = conky.text .. conky_show_netdevs()

并编辑 lua 以删除任何 conky 调用,然后返回配置:

-- conky_show_netdevs : template for network
function conky_show_netdevs()
   local netdevs_handle = io.popen(...)
   local result = ""
   for netdev in netdevs_handle:lines() do
      result = result ...
   netdevs_handle:close()
   return result
end

相关内容