greshake / i3status-rust

Very resourcefriendly and feature-rich replacement for i3status, written in pure Rust
GNU General Public License v3.0
2.89k stars 475 forks source link

Configuration in `lua` #1359

Open MaxVerevkin opened 3 years ago

MaxVerevkin commented 3 years ago

Using lua for configuration gives a lot of flexibility and control: conditional blocks, click handlers in lua, custom formatting in lua, dynamic themes/icons and a lot more. Here is an example of a lua config (it actually works):

-- Returns command's output
local function cmd(c)
    local proc = io.popen(c)
    local output = proc:read()
    proc:close()
    return output
end

-- Set icons and theme
config.icons = "material-nf"
config.theme = {
    name = "slick",
    overrides = {
        alternating_tint_bg = "#0C0C0C00",
        alternating_tint_fg = "#0C0C0C00",
    }
}

-- Simple, unconditional block (`block` function just appends to the `config.block` table)
block {
    block = "disk_space",
    info_type = "available",
    alert_unit = "GB",
    alert = 10.0,
    warning = 15.0,
    format = "$available"
}

-- As an example, add kbd layout block only if more than one layout is available
local layouts_cnt = cmd("swaymsg -t get_inputs | jq '.[].xkb_layout_names | length | select(. > 0)' | head -n1")
if (layouts_cnt ~= "1") 
then
    block {
        block = "sway_kbd",
        mappings = {
            ["English (Workman)"] = "EN",
            ["Russian"] = "RU"
        }
    }
end

-- It's possible to schedule functions. In this example "hello" is printed to stderr every second.
add_timer(1000, function()
    io.stderr:write("hello")
end)
ghost commented 1 year ago

please keep this optional.

MaxVerevkin commented 1 year ago

@deepaknegilachu don't worry, TOML config isn't going anywhere.