markup code samples as lua code

This commit is contained in:
J. Thalheim 2011-12-17 09:19:29 +01:00
parent c715d94471
commit 64ff3090d0
1 changed files with 34 additions and 9 deletions

View File

@ -35,12 +35,16 @@ your memory.
Then add the following to the top of your rc.lua: Then add the following to the top of your rc.lua:
require("vicious") ```Lua
require("vicious")
```
Once you create a widget (a textbox, graph or a progressbar) call Once you create a widget (a textbox, graph or a progressbar) call
vicious.register() to register it with Vicious: vicious.register() to register it with Vicious:
vicious.register(widget, wtype, format, interval, warg) ```Lua
vicious.register(widget, wtype, format, interval, warg)
```
**widget** **widget**
@ -83,13 +87,17 @@ Other functions
--------------- ---------------
**Unregister a widget**: **Unregister a widget**:
```Lua
vicious.unregister(widget, keep) vicious.unregister(widget, keep)
```
if keep is true widget will be suspended, waiting to be activated if keep is true widget will be suspended, waiting to be activated
**Suspend all widgets**: **Suspend all widgets**:
```Lua
vicious.suspend() vicious.suspend()
```
[example automation script](http://sysphere.org/~anrxc/local/sources/lmt-vicious.sh) for the "laptop-mode-tools" start-stop module: [example automation script](http://sysphere.org/~anrxc/local/sources/lmt-vicious.sh) for the "laptop-mode-tools" start-stop module:
@ -100,13 +108,17 @@ if widget is provided only that widget will be activated
**Enable caching of a widget type:** **Enable caching of a widget type:**
```Lua
vicious.cache(wtype) vicious.cache(wtype)
```
enable caching of values returned by a widget type enable caching of values returned by a widget type
**Force update of widgets:** **Force update of widgets:**
```Lua
vicious.force({ widget, }) vicious.force({ widget, })
```
widget argument is a table with one or more widgets that will be updated widget argument is a table with one or more widgets that will be updated
@ -408,25 +420,31 @@ order to actually display them.
**Date widget** **Date widget**
```Lua
datewidget = widget({ type = "textbox" }) datewidget = widget({ type = "textbox" })
vicious.register(datewidget, vicious.widgets.date, "%b %d, %R") vicious.register(datewidget, vicious.widgets.date, "%b %d, %R")
```
updated every 2 seconds (the default interval), uses standard updated every 2 seconds (the default interval), uses standard
date sequences as the format string date sequences as the format string
**Memory widget** **Memory widget**
```Lua
memwidget = widget({ type = "textbox" }) memwidget = widget({ type = "textbox" })
vicious.cache(vicious.widgets.mem) vicious.cache(vicious.widgets.mem)
vicious.register(memwidget, vicious.widgets.mem, "$1 ($2MB/$3MB)", 13) vicious.register(memwidget, vicious.widgets.mem, "$1 ($2MB/$3MB)", 13)
```
updated every 13 seconds, appends "MB" to 2nd and 3rd returned updated every 13 seconds, appends "MB" to 2nd and 3rd returned
values and enables caching of this widget type values and enables caching of this widget type
**HDD temperature widget** **HDD temperature widget**
```Lua
hddtempwidget = widget({ type = "textbox" }) hddtempwidget = widget({ type = "textbox" })
vicious.register(hddtempwidget, vicious.widgets.hddtemp, "${/dev/sda} °C", 19) vicious.register(hddtempwidget, vicious.widgets.hddtemp, "${/dev/sda} °C", 19)
```
updated every 19 seconds, requests the temperature level of the updated every 19 seconds, requests the temperature level of the
{/dev/sda} key/disk and appends "°C" to the returned value, does {/dev/sda} key/disk and appends "°C" to the returned value, does
@ -434,14 +452,16 @@ not provide the port argument so default port is used
**Mbox widget** **Mbox widget**
```Lua
mboxwidget = widget({ type = "textbox" }) mboxwidget = widget({ type = "textbox" })
vicious.register(mboxwidget, vicious.widgets.mbox, "$1", 5, "/home/user/mail/Inbox") vicious.register(mboxwidget, vicious.widgets.mbox, "$1", 5, "/home/user/mail/Inbox")
```
updated every 5 seconds, provides full path to the mbox as an updated every 5 seconds, provides full path to the mbox as an
argument argument
**Battery widget** **Battery widget**
```Lua
batwidget = awful.widget.progressbar() batwidget = awful.widget.progressbar()
batwidget:set_width(8) batwidget:set_width(8)
batwidget:set_height(10) batwidget:set_height(10)
@ -451,20 +471,21 @@ argument
batwidget:set_color("#AECF96") batwidget:set_color("#AECF96")
batwidget:set_gradient_colors({ "#AECF96", "#88A175", "#FF5656" }) batwidget:set_gradient_colors({ "#AECF96", "#88A175", "#FF5656" })
vicious.register(batwidget, vicious.widgets.bat, "$2", 61, "BAT0") vicious.register(batwidget, vicious.widgets.bat, "$2", 61, "BAT0")
```
updated every 61 seconds, requests the current battery charge updated every 61 seconds, requests the current battery charge
level and displays a progressbar, provides "BAT0" battery ID as an level and displays a progressbar, provides "BAT0" battery ID as an
argument argument
**CPU usage widget** **CPU usage widget**
```Lua
cpuwidget = awful.widget.graph() cpuwidget = awful.widget.graph()
cpuwidget:set_width(50) cpuwidget:set_width(50)
cpuwidget:set_background_color("#494B4F") cpuwidget:set_background_color("#494B4F")
cpuwidget:set_color("#FF5656") cpuwidget:set_color("#FF5656")
cpuwidget:set_gradient_colors({ "#FF5656", "#88A175", "#AECF96" }) cpuwidget:set_gradient_colors({ "#FF5656", "#88A175", "#AECF96" })
vicious.register(cpuwidget, vicious.widgets.cpu, "$1", 3) vicious.register(cpuwidget, vicious.widgets.cpu, "$1", 3)
```
updated every 3 seconds, feeds the graph with total usage updated every 3 seconds, feeds the graph with total usage
percentage of all CPUs/cores percentage of all CPUs/cores
@ -487,6 +508,7 @@ widget.
**Example** **Example**
```Lua
mpdwidget = widget({ type = "textbox" }) mpdwidget = widget({ type = "textbox" })
vicious.register(mpdwidget, vicious.widgets.mpd, vicious.register(mpdwidget, vicious.widgets.mpd,
function (widget, args) function (widget, args)
@ -495,18 +517,19 @@ widget.
args["{Artist}"]..' - '.. args["{Title}"] args["{Artist}"]..' - '.. args["{Title}"]
end end
end) end)
```
hides the mpd widget when no song is playing, updated every 2 hides the mpd widget when no song is playing, updated every 2
seconds (the default interval) seconds (the default interval)
**Example** **Example**
```Lua
uptimewidget = widget({ type = "textbox" }) uptimewidget = widget({ type = "textbox" })
vicious.register(uptimewidget, vicious.widgets.uptime, vicious.register(uptimewidget, vicious.widgets.uptime,
function (widget, args) function (widget, args)
return string.format("Uptime: %2dd %02d:%02d ", args[1], args[2], args[3]) return string.format("Uptime: %2dd %02d:%02d ", args[1], args[2], args[3])
end, 61) end, 61)
```
uses string.format for padding uptime values to a minimum amount uses string.format for padding uptime values to a minimum amount
of digits, updated every 61 seconds of digits, updated every 61 seconds
@ -517,10 +540,11 @@ automatically adapted to text width).
**Example** **Example**
```Lua
uptimewidget = widget({ type = "textbox" }) uptimewidget = widget({ type = "textbox" })
uptimewidget.width, uptimewidget.align = 50, "right" uptimewidget.width, uptimewidget.align = 50, "right"
vicious.register(uptimewidget, vicious.widgets.uptime, "$1 $2:$3", 61) vicious.register(uptimewidget, vicious.widgets.uptime, "$1 $2:$3", 61)
```
forces a fixed width of 50px to the uptime widget, and aligns its forces a fixed width of 50px to the uptime widget, and aligns its
text to the right text to the right
@ -531,6 +555,7 @@ it.
**Example** **Example**
```Lua
ctext = widget({ type = "textbox"}) ctext = widget({ type = "textbox"})
cgraph = awful.widget.graph() cgraph = awful.widget.graph()
cgraph:set_width(100):set_height(20) cgraph:set_width(100):set_height(20)
@ -543,7 +568,7 @@ it.
cgraph:add_value(args[3], 2) -- Core 2, color 2 cgraph:add_value(args[3], 2) -- Core 2, color 2
cgraph:add_value(args[4], 3) -- Core 3, color 3 cgraph:add_value(args[4], 3) -- Core 3, color 3
end, 3) end, 3)
```
enables graph stacking/multigraph and plots usage of all three CPU enables graph stacking/multigraph and plots usage of all three CPU
cores on a single graph, the textbox "ctext" is just an empty cores on a single graph, the textbox "ctext" is just an empty
placeholder, graph is updated every 3 seconds placeholder, graph is updated every 3 seconds