You are not logged in.

#1 2016-01-12 03:32:18

cnx
Member
Registered: 2016-01-12
Posts: 3

[SOLVED] Question about awesome vicious text widget with fixed width

Hi guys,

I'm currently configuring awesome's vicious widgets. Which bother me is that the text widgets jumping around when the number increase/decrease few digits. From cmtptr's answer from this thread, I finally found the way to get CPU and mem widgets stand still as each of them only require one argument:

-- Create a CPU usage widget
cpuwidget = wibox.widget.textbox()
vicious.register(
    cpuwidget,
    vicious.widgets.cpu,
    function (widget, args)
        return (" CPU %3d%% |"):format(args[1])
    end,
    1)

What I'm stucked with right now is the vicious.widget.net - it requires this kind of arg: ${wlp2s2 down_kb}. Currently I'm having this in my rc.lua:

-- Create a network usage widget
netwidget = wibox.widget.textbox()
vicious.register(
    netwidget,
    vicious.widgets.net,
    " DOWN ${wlp2s2 down_kb}kB | UP ${wlp2s2 up_kb}kB ",
    1)

Is there any way I can format this widget to have a certain width so that it doesn't jump around? I don't know any Lua but obviously this doesn't work:

function (widget, args)
    return (" DOWN %4skB |"):format(args[{wlp2s2 down_kb}])
end

Sorry for my bad English. Thanks in advance.

Last edited by cnx (2016-01-15 03:28:30)

Offline

#2 2016-01-12 06:27:04

esa
Member
Registered: 2011-12-29
Posts: 143
Website

Re: [SOLVED] Question about awesome vicious text widget with fixed width

There is a distinct difference between the two.
One returns a variable to work with, the other expects a variable to work with.

AFAIK: To achieve this you would need to change the vicious.netwidget itself to return its output in the proper format.
But then again, i dont know lua well enough.

As a semi-workaround, you can place that at the inner bindings or at the border of central aligned widgets.
Example: The one most right of the upper left widget group.

hth


Author of: TUI (Text User Interface for scripts), VHS (Video Handler Script, using ffmpeg) and YASSI (Yet Another Simple Script Installer)

Offline

#3 2016-01-12 10:51:45

cnx
Member
Registered: 2016-01-12
Posts: 3

Re: [SOLVED] Question about awesome vicious text widget with fixed width

Thanks for quick respond. I've already done that, but I want to have a more prefect solution.

Offline

#4 2016-01-14 15:20:01

Stepych
Member
Registered: 2013-03-28
Posts: 5

Re: [SOLVED] Question about awesome vicious text widget with fixed width

From vicious readme:
"When it comes to padding it is also useful to mention how a widget can
be configured to have a fixed width. You can set a fixed width on your
textbox widgets by changing their .width field (by default width is
automatically adapted to text width).

Example

  uptimewidget = wibox.widget.textbox()
  uptimewidget:set_align("right")
  vicious.register(uptimewidget, vicious.widgets.uptime, "$1 $2:$3", 61)
  uptimewidget = wibox.layout.constraint(uptimewidget, "exact", 50, nil)

  - forces a fixed width of 50px to the uptime widget, and aligns its
    text to the right "

Also in

args[{wlp2s2 down_kb}]

args is array, so index should be integer

Hope that helps.

Offline

#5 2016-01-15 03:25:34

cnx
Member
Registered: 2016-01-12
Posts: 3

Re: [SOLVED] Question about awesome vicious text widget with fixed width

Thanks. After reading that part of the README, I finally found the solution:

-- Create a network usage widget
netwidget = wibox.widget.textbox()
vicious.register(
    netwidget,
    vicious.widgets.net,
    function (widget, args)
        return (" DOWN %6skB | UP %6skB "):format(args["{wlp2s2 down_kb}"],
                                                  args["{wlp2s2 up_kb}"])
    end,
    1)

Last edited by cnx (2016-01-15 03:26:48)

Offline

Board footer

Powered by FluxBB