luastatus — universal status bar content generator

栏目: IT技术 · 发布时间: 5年前

内容简介:luastatusis a universal status bar content generator. It allows you to configure the way the data from event sources is processed and shown, with Lua.Its main feature is that the content can be updated immediately as some event occurs, be it a change of ke

luastatusis a universal status bar content generator. It allows you to configure the way the data from event sources is processed and shown, with Lua.

Its main feature is that the content can be updated immediately as some event occurs, be it a change of keyboard layout, active window title, volume or a song in your favorite music player (provided that there is a plugin for it) — a thing rather uncommon for tiling window managers.

Its motto is:

No more heavy-forking, second-lagging shell-script status bar generators!

Screenshot

Above is i3bar with luastatus with Bitcoin price, time, volume, and keyboard layout widgets.

Key concepts

luastatus — universal status bar content generator

In short:

  • plugin is a thing that decides when to call the callback function widget.cb and what to pass to it;
  • barlib ( bar lib rary) is a thing that decides what to with values that widget.cb function returns;
  • there are also derived plugins , which are plugins written in Lua that use regular plugins.

Examples

ALSA volume widget:

widget = {
    plugin = 'alsa',
    opts = {
        channel = 'PCM'
    },
    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
}

GMail widget (uses the derived plugin imap ):

--[[
-- 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
    ]]
}

See more examples here .

Installation

cmake . && make && sudo make install

You can specify a Lua library to build with: cmake -DWITH_LUA_LIBRARY=luajit .

You can disable building certain barlibs and plugins, e.g. cmake -DBUILD_PLUGIN_XTITLE=OFF .

You can disable building man pages: cmake -DBUILD_DOCS=OFF .

Getting started

It is recommended to first have a look at the luastatus' man page .

Then, read the barlib's and plugins' documentation, either via directly viewing barlibs/<name>/README.rst and plugins/<name>/README.rst files, or via installing the man pages and reading luastatus-barlib-<name>(7) and luastatus-plugin-<name>(7) .

Barlib-specific notes on usage follow.

i3

luastatus-i3-wrapper should be specified as the i3bar's status command in the i3 config, e.g.:

bar {
    status_command cd ~/.config/luastatus && exec luastatus-i3-wrapper -B no_separators time-battery-combined.lua alsa.lua xkb.lua

See also README for i3 and examples for i3 .

dwm

luastatus should simply be launched with -b dwm , e.g.:

luastatus -b dwm -B separator=' • ' alsa.lua time-battery-combined.lua

See also README for dwm and examples for dwm .

lemonbar

lemonbar should be launched with luastatus-lemonbar-launcher , e.g.:

luastatus-lemonbar-launcher -p -B#111111 -p -f'Droid Sans Mono for Powerline:pixelsize=12:weight=Bold' -- -Bseparator=' ' alsa.lua time-date.lua

See also README for lemonbar and examples for lemonbar .

stdout

luastatus should be launched with luastatus-stdout-wrapper ; or write your own wrapper, see e.g. the wrapper for launching dvtm with luastatus .

See also README for stdout and and examples for stdout .

Supported Lua versions

  • 5.1
  • LuaJIT, which is currently 5.1-compatible with "some language and library extensions from Lua 5.2"
  • 5.2
  • 5.3
  • 5.4 ( work1 , work2 pre-release versions)

Reporting bugs, requesting features, suggesting patches

Feel free to open an issue or a pull request.

Migrating from older versions

See the Migration Guide .

Acknowledgements

  • I would like to thank wm4 for developing mpv , which, also being a “platform” for running Lua scripts, served as an inspiration for this project.

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

算法详解(卷1)——算法基础

算法详解(卷1)——算法基础

[美]蒂姆·拉夫加登(Tim Roughgarden) / 徐波 / 人民邮电出版社 / 2019-1-1 / 49

算法是计算机科学领域最重要的基石之一。算法是程序的灵魂,只有掌握了算法,才能轻松地驾驭程序开发。 算法详解系列图书共有4卷,本书是第1卷——算法基础。本书共有6章,主要介绍了4个主题,它们分别是渐进性分析和大O表示法、分治算法和主方法、随机化算法以及排序和选择。附录A和附录B简单介绍了数据归纳法和离散概率的相关知识。本书的每一章均有小测验、章末习题和编程题,这为读者的自我检查以及进一步学习提......一起来看看 《算法详解(卷1)——算法基础》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具