luastatus(1)
π Name π
okay so bestie, this is luastatus(1) from the General Commands Manual, and the name line is literally: luastatus - universal status bar content generator π
. It is, no cap, a universal status bar content generator π«Ά.
π SYNOPSIS π
Two invocation shapes, fr fr:
luastatus -b barlib [-B barlib_option]... [-l loglevel] [-e]
widget_file...
luastatus -v
π DESCRIPTION π
luastatus is a universal status bar content generator β¨. It lets you configure the way the data from event sources is processed and shown, with Lua π. Thatβs the whole main character energy of it.
β¨ OPTIONS β¨
-bbarlibβ specify a barlib to load π. Ifbarlibcontains a slash, it is treated as a path to a shared library. If it does not, the program tries to loadbarlib-barlib.sofrom the directory configured at the build time.-Bbarlib_optionβ pass an option tobarlibπ. May be specified multiple times.-lloglevelβ specify a log level.loglevelis one of:fatalerrorwarninginfoverbosedebugtrace. Default isinfo.-eβ do not hang, but exit normally whenbarlibβs event watcher and all pluginsβrun()have returned π¦. Default behaviour is to hang, because there are status bars that require their generator process not to terminate (namelyi3bar). Useful for testing.-vβ show version and exit π.
π§ WIDGETS π§
A widget is a Lua program with a table named widget defined. The widget table must contain the following entries:
plugin: string β name or the path to a plugin (see PLUGINS) the widget wants to receive data from. If it contains a slash, it is treated as a path to a shared library. If it does not,luastatustries to loadplugin-<plugin>.sofrom the directory configured at the build time (CMakePLUGINS_DIRvariable, defaults to${CMAKE_INSTALL_FULL_LIBDIR}/luastatus/plugins).cb: function β the callback that converts the data received from a plugin to the format a barlib (see BARLIBS) understands. It should take one argument and return one value. (Although in Lua one can omit the argument if you donβt care about its value, and not returning anything is the same as returningnil.)
The widget table may contain the following entries:
opts: table β table with pluginβs options. If undefined, an empty table will be substituted.event: function or string β- If it is a function, it will be called by the barlib whenever some event with the widget occurs (typically a click). It should take one argument and not return anything.
- If it is a string, it is compiled as a function in a separate state (see SEPARATE STATE).
π PLUGINS π
A plugin is a thing that knows when to call the cb function and what to pass to. Plugins are shared libraries. These plugins are also referred to as proper plugins, as opposed to derived plugins.
𧬠DERIVED PLUGINS π§¬
Starting with version 0.3.0, luastatus features derived plugins, which are wrappers around proper plugins (or even other derived plugins) written in Lua π§. Derived plugins are loaded by calling luastatus.require_plugin(name) (see LUA LIBRARIES).
π BARLIBS π
A barlib (bar library) is a thing that knows:
- what to do with values the
cbfunction returns; - when to call the
eventfunction and what to pass to; - how to indicate an error, should one happen.
Barlibs are shared libraries, too. Barlibs are capable of taking options.
ποΈ ARCHITECTURE ποΈ
Each widget runs in its own thread and has its own Lua interpreter instance. While Lua does support multiple interpreters running in separate threads, it does not support multithreading within one interpreter, which means cb() and event() of the same widget never overlap (a widget-local mutex is acquired before calling any of these functions, and is released afterwards).
Also, due to luastatusβ architecture, no two event() functions, even from different widgets, can overlap. (Note that cb() functions from different widgets can overlap.)
The takeaway is that the event() function should not block, or bad things will happen π.
π LUA LIBRARIES π
πΈ The luastatus module πΈ
luastatus provides the luastatus module, which currently contains only one function:
luastatus.require_plugin(name)is like therequirefunction, except that it loads a file named<name>.luafromluastatusβ plugins directory.
π«Ά Plugins' and barlib's Lua functions π«Ά
Plugins and barlibs can register Lua functions. They appear in luastatus.plugin and luastatus.barlib submodules, correspondingly.
π Limitations π
In luastatus, os.setlocale always fails as it is inherently not thread-safe.
π¦ SEPARATE STATE π¦
If widget.cb field has string type, it gets compiled as a function in a separate state (as if with Luaβs loadstring function). Whenever an event on such a widget occurs, the compiled function will be called in that state (not in the widgetβs state, in which cb gets called).
This is useful for widgets that want not to receive data from plugin, but to generate it themselves (possibly using some external modules). Such a widget may want to specify
widget = {
plugin = 'timer',
opts = {period = 0},
and block in cb until it wants to update. The problem is that in this case, widgetβs Lua mutex is almost always being acquired by cb, and there is very little chance for event to get called. A separate-state event function solves that.
π EXAMPLES π
luastatus-i3-wrapper alsa.lua time.lua
where alsa.lua is:
widget = {
plugin = 'alsa',
cb = function(t)
if t.mute then
return {full_text = '[mute]', color = '#e03838'}
else
local percent = (t.vol.cur - t.vol.min)
/ (t.vol.max - t.vol.min)
* 100
return {full_text = string.format('[%3d%%]', math.floor(0.5 + percent)),
color = '#718ba6'}
end
end,
event = function(t)
if t.button == 1 then -- left mouse button
os.execute('urxvt -e alsamixer &')
end
end
}
and time.lua is:
widget = {
plugin = 'timer',
opts = {period = 2},
cb = function()
return {full_text = os.date('[%H:%M]')}
end,
}
luastatus -b dwm gmail.lua
where gmail.lua is:
--[[
-- Expects 'credentials.lua' to be present in the current directory; it may contain, e.g.,
-- return {
-- gmail = {
-- login = 'john.smith',
-- password = 'qwerty'
-- }
-- }
--]]
credentials = require 'credentials'
widget = luastatus.require_plugin('imap').widget{
host = 'imap.gmail.com',
port = 993,
mailbox = 'Inbox',
use_ssl = true,
timeout = 2 * 60,
handshake_timeout = 10,
login = credentials.gmail.login,
password = credentials.gmail.password,
error_sleep_period = 60,
cb = function(unseen)
if unseen == nil then
return nil
elseif unseen == 0 then
return {full_text = '[-]', color = '#595959'}
else
return {full_text = string.format('[%d unseen]', unseen)}
end
end,
event = [[ -- separate-state event function
local t = ... -- obtain argument of this implicit function
if t.button == 1 then -- left mouse button
os.execute('xdg-open https://gmail.com &')
end
]]
}
More examples can be found in the examples/ directory in the luastatusβ git repository (<https://github.com/shdown/luastatus>).
π CHANGELOG π
See <https://github.com/shdown/luastatus/releases>.
Β©οΈ Copyright Β©οΈ
LGPLv3
~ fin ~ that was luastatus(1) from the General Commands Manual, bestie β no extra date/version footer on this page, just LGPLv3 and bye ππ
π¦ where this page comes from
- nixos 26.05: luastatus 0.6.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms