class DSL

The configuration DSL.

Example configuration file:

widget :power
widget :uptime, on_click: -> { spawn "alacritty -e htop&" }
widget :custom,
    interval: 1,
    on_click: -> { `notify-send #{@rand}` } do
    @rand = Random.rand 100
    "random value '#{@rand}'"
end

widget :button,
    on_click: -> { `notify-send hi` },
    class: "red" do
        "CLICK ME"
end

widget :load do |_, _, _, running| "tasks: #{running}" end
widget :load do |short| "5m avg: #{short}" end

class Widgets::Spinner < Widgets::Widget
    def initialize options
        super
        init_timer
        @spinner = Gtk::Spinner.new
        append @spinner
        @spinner.start
    end
end

widget :spinner

css <<CSS
box.red * {
    color: red;
}
CSS

Using instance_eval the configuration file is executed inside the context of this class.

Please check the public methods for this class for further documentation.

Entirely custom widgets

If you want a truly custom widget just make one. This code will create a spinner in your bar:

class Widgets::Spinner < Widgets::Widget
    def initialize options
        super
        init_timer
        @spinner = Gtk::Spinner.new
        append @spinner
        @spinner.start
    end
end

widget :spinner

Styling

See DSL#css.

Some implementation details

The DSL produces a hash in DSL#options.

This hash is then used to configure the bar. This hash is printed when rubybar is run in verbose mode.

The DSL#widget method also creates a hash that can then be used by Widgets::Widget::from_options to build a Widgets::Widget.