barr 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +276 -14
- data/examples/README.md +31 -0
- data/examples/all_in.rb +69 -0
- data/examples/barr_example.rb +32 -0
- data/examples/fizzbuzz.rb +37 -0
- data/examples/i3_cpu_mem.rb +18 -0
- data/examples/rhythm.rb +19 -0
- data/examples/time_and_date.rb +14 -0
- data/examples/two_temperatures.rb +24 -0
- data/exe/barr_example +32 -0
- data/lib/barr/block.rb +10 -4
- data/lib/barr/blocks/who_am_i.rb +1 -1
- data/lib/barr/manager.rb +24 -4
- data/lib/barr/version.rb +1 -1
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52846bb83c6e265578a031aff81ee89da3abab61
|
4
|
+
data.tar.gz: 3d3cc3ca30e310f0fe75f12541132b3e789598d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa6b17a9d3bc91fe8f64347f821182297f98ffe682e6ec51749d633a09b508191e3d7e6b1fa016eee66bb1936ae3ed3b2e289eef27cddfd4c03a4b0bda2ee43d
|
7
|
+
data.tar.gz: a2b7ed1d4433931b823af96a9bcdce42a14ba252ff05c5b7fbaa660aa3d52340110ae0e5890c25cb41c0eca82ee9d1ac42fcb22a8af92ce4493daa4e2b8a6c00
|
data/README.md
CHANGED
@@ -1,39 +1,301 @@
|
|
1
1
|
# Barr
|
2
2
|
|
3
|
-
|
3
|
+

|
4
4
|
|
5
|
-
|
5
|
+
Barr is a status line generator for Lemonbar. It is an alternative to the common method of using shell scripts to generate the bar's content. Barr is written in, and configured with, Ruby.
|
6
|
+
|
7
|
+
Barr aims to make creating and maintaining Lemonbar scripts much easier. At its core is a suite of re-usable and configurable Blocks. These blocks can be added to your bar as-is; configured to your liking; or extended to create your own behaviour. This allows status lines to be created in a more declarative manner.
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
9
|
-
|
11
|
+
$ gem install barr
|
12
|
+
|
13
|
+
If that doesn't work, you probably don't have Ruby installed. I'd recommend you install it via [RVM](http://rvm.io) or [rbenv](https://github.com/rbenv/rbenv), though they're probably overkill if you don't already use Ruby regularly.
|
14
|
+
|
15
|
+
For a simpler install, check your distro's package manager. That should be fine.
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
See [Examples folder](http://github.com/okaydave/barr/tree/master/examples) for more detailed usage examples.
|
20
|
+
|
21
|
+
Documentation about all available blocks and their options can be found further down in this document.
|
22
|
+
|
23
|
+
### Simple Usage Example
|
10
24
|
|
25
|
+
*barr_example.rb*
|
11
26
|
```ruby
|
12
|
-
|
27
|
+
#!/usr/bin/env ruby
|
28
|
+
|
29
|
+
# pull in the Barr gem
|
30
|
+
require 'rubygems'
|
31
|
+
require 'barr'
|
32
|
+
|
33
|
+
# Create a new manager instance.
|
34
|
+
# The manager is responsible for organising the blocks and delivering their output to lemonbar
|
35
|
+
@manager = Barr::Manager.new
|
36
|
+
|
37
|
+
# Add a 'WhoAmI' block. This just outputs logged in username
|
38
|
+
# Give it a peach background, grey text and updates every 10000 seconds
|
39
|
+
# It will be aligned to the left of the bar
|
40
|
+
@manager.add_block Barr::Blocks::WhoAmI.new(bcolor: "#FFAAAA", fcolor: "#333333", interval: 10000)
|
41
|
+
|
42
|
+
# Add a 'Clock' block.
|
43
|
+
# Clocks can be formatted in the type strftime fashion. This example outputs the current Hour and Minute
|
44
|
+
# It will update every second.
|
45
|
+
# By default, the background text colour will be deferred to the Lemonbar config
|
46
|
+
# If FontAwesome font is available to lemonbar, it will be prepended with a clock icon.
|
47
|
+
@manager.add_block Barr::Blocks::Clock.new(icon: "\uf017", format: "%H:%M", align: :c, interval: 1)
|
48
|
+
|
49
|
+
|
50
|
+
# Add a 'Cpu' block. This shows the current CPU usage (averaged across all cores if present)
|
51
|
+
# It will be aligned to the right side of of the bar
|
52
|
+
# As an interval is not provided, it will update every 5 seconds.
|
53
|
+
# It will be prepended with the text 'Cpu:'
|
54
|
+
@manager.add_block Barr::Blocks::Cpu.new(icon: "Cpu:", align: :r)
|
55
|
+
|
56
|
+
|
57
|
+
# Tell the manager to run the loop. This will continue indefinitely, outputing the data ready to be piped in to lemonbar.
|
58
|
+
@manager.run
|
59
|
+
```
|
60
|
+
|
61
|
+
This can be piped in to lemonbar as usual:
|
62
|
+
|
63
|
+
```bash
|
64
|
+
#!/bin/bash
|
65
|
+
|
66
|
+
./barr_example.rb | lemonbar -g 800x30+960+00 -d -B "#333333" -f "Roboto Mono Medium:size=11" -f "Font Awesome:size=11" | sh
|
13
67
|
```
|
14
68
|
|
15
|
-
|
69
|
+
Which should have Lemonbar appear as:
|
16
70
|
|
17
|
-
|
71
|
+

|
18
72
|
|
19
|
-
Or install it yourself as:
|
20
73
|
|
21
|
-
|
74
|
+
## Block Configuration
|
75
|
+
|
76
|
+
### Common
|
77
|
+
|
78
|
+
All blocks inherit their behaviour from a base Block. This means that all blocks will respond to the following configuration options:
|
79
|
+
|
80
|
+
| Option | Value | Description | Default |
|
81
|
+
| ------ | ----- | ----------- | ------- |
|
82
|
+
| `fcolor` | RGB Hex string or `-` | Equivalent to lemonbar's `%{F}` format. Takes a hex string in the format of `#FFF`, `#FFFFFF`, or `#FFFFFFFF` (for transparency). | `"-"` |
|
83
|
+
| `bcolor` | RGB Hex string or `-` | As above. To use the configured lemonbar colors, use `"-"`. This also applies to the `fcolor` option. | `"-"` |
|
84
|
+
| `icon` | String | This is prepended to each blocks' output. It can be a normal string like `"CPU:"` or a unicode string like `"\uf164"` (thumbs up in Font Awesome | `""` |
|
85
|
+
| `interval` | Integer | How frequently the Block should perform its update method in seconds. The block is drawn to lemonbar every second, this just affects how frequently the data can change. | `5` |
|
86
|
+
| `align` | Symbol | One of `:l`, `:c`, `:r` for left, centre and right alignment respectively. | `:l` |
|
87
|
+
|
88
|
+
These are set when a Block is initialized:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
@man = Barr::Manager.new
|
92
|
+
|
93
|
+
block1 = Barr::Block.new fcolor: "#FF0000",
|
94
|
+
bcolor: "#000000",
|
95
|
+
icon: "I am:",
|
96
|
+
interval: 10,
|
97
|
+
align: :r
|
98
|
+
|
99
|
+
man.add_block block1
|
100
|
+
|
101
|
+
```
|
102
|
+
|
103
|
+
If you're unfamiliar with Ruby here's a couple of tips that might help with reading and writing your own blocks:
|
104
|
+
|
105
|
+
* Parentheses are optional most of the time. The exception is when their absense causes ambiguity as to which arguments belong to which methods.
|
106
|
+
* The arguments to `Barr::Block.new` are supplied as a `Hash`. This means that you don't need to put them in a specific order.
|
107
|
+
* If you want to use a default value, you can just omit the option altogether.
|
108
|
+
* Whitespace isn't that important, at least compared to languages like Python. Feel free to use whitespace to make your code more readable.
|
109
|
+
|
110
|
+
For example, the following code:
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
@man = Barr::Manager.new()
|
114
|
+
|
115
|
+
block1 = Barr::Blocks::WhoAmI.new({fcolor: "#FFF", bcolor: "#000", align: :c})
|
116
|
+
|
117
|
+
@man.add_block(block1)
|
118
|
+
|
119
|
+
```
|
120
|
+
|
121
|
+
Is functionally the same as this:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
@man = Barr::Manager.new
|
125
|
+
|
126
|
+
block1 = Barr::Blocks::WhoAmI.new align: :c,
|
127
|
+
fcolor: "#FFF",
|
128
|
+
bcolor: "#000"
|
129
|
+
|
130
|
+
@man.add_block block1
|
131
|
+
|
132
|
+
```
|
133
|
+
|
134
|
+
You can also add Blocks straight to the manager if you'd like to skip that step, or even mix/match:
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
@man = Barr::Manager.new
|
138
|
+
|
139
|
+
seperate_block = Barr::Blocks::WhoAmI.new
|
140
|
+
|
141
|
+
@man.add_block Barr::Blocks::WhoAmI.new bcolor: "#000", fcolor: "#FFF"
|
142
|
+
@man.add_block(Barr::Blocks::WhoAmI.new(icon: "Me!", align: :c)
|
143
|
+
@man.add_block separate_block
|
144
|
+
```
|
22
145
|
|
23
|
-
## Usage
|
24
146
|
|
25
|
-
|
147
|
+
### Block Specific Configuration
|
26
148
|
|
27
|
-
|
149
|
+
#### Clock
|
28
150
|
|
29
|
-
|
151
|
+
Shows the current date and/or time.
|
30
152
|
|
31
|
-
|
153
|
+
`clock = Barr::Blocks::Clock.new format: "%m %b %Y", icon: "Date: "`
|
32
154
|
|
155
|
+
| Option | Value | Description | Default |
|
156
|
+
| --- | --- | --- | --- |
|
157
|
+
| `format` | strftime String | This takes a [strftime](http://ruby-doc.org/core-2.2.0/Time.html#method-i-strftime) formatted string. If you're not familiar with this syntax, you could use an [online generator](http://www.foragoodstrftime.com/). | `"%H:%M %m %b %Y"` |
|
158
|
+
|
159
|
+
#### Cpu
|
160
|
+
|
161
|
+
Shows CPU load averaged across all cores.
|
162
|
+
|
163
|
+
`cpu = Barr::Blocks::Cpu.new`
|
164
|
+
|
165
|
+
There are no `Cpu` block specific configurable options.
|
166
|
+
|
167
|
+
#### Hdd
|
168
|
+
|
169
|
+
Shows selected filesystem's used and free space.
|
170
|
+
|
171
|
+
`hdd = Barr::Blocks::Hdd.new device: "sda2"`
|
172
|
+
|
173
|
+
| Option | Value | Description | Default |
|
174
|
+
| --- | --- | --- | --- |
|
175
|
+
| `device` | String | This is the name of the device for which you'd like to see free/used space. Something like `/dev/sda2`. Run `df -h` in your terminal and look at the first column. | **REQUIRED** |
|
176
|
+
|
177
|
+
#### I3
|
178
|
+
|
179
|
+
**Requires i3wm**. Shows the current workspaces and highlights the active one. You can click a workspace name to change to there.
|
180
|
+
|
181
|
+
`i3 = Barr::Blocks::I3.new focus_markers: ["\u",""]`
|
182
|
+
|
183
|
+
| Option | Value | Description | Default |
|
184
|
+
| --- | --- | --- | --- |
|
185
|
+
| `focus_markers` | 2 element Array | These are used to 'highlight' the active workspace. The first element is used on the left of the active workspace, the second element on the right. | [">", "<"] |
|
186
|
+
|
187
|
+
#### ip
|
188
|
+
|
189
|
+
Shows the selected adaptor's IPv4 address. If no device is specified, it will make a guess.
|
190
|
+
|
191
|
+
`ip = Barr::Blocks::Ip.new device: "enp3s0"`
|
192
|
+
|
193
|
+
| Option | Value | Description | Default |
|
194
|
+
| --- | --- | --- | --- |
|
195
|
+
| `device` | String | The name of the device | `192` |
|
196
|
+
|
197
|
+
#### Mem
|
198
|
+
|
199
|
+
Shows current RAM usage.
|
200
|
+
|
201
|
+
`mem = Barr::Blocks::Mem.new`
|
202
|
+
|
203
|
+
There are no `Mem` block specific configurable options.
|
204
|
+
|
205
|
+
#### Rhythmbox
|
206
|
+
|
207
|
+
**Requires Rhythmbox and rhythmbox-client**. Shows currently playing artist and/or track, as well as control buttons.
|
208
|
+
|
209
|
+
`rb = Barr::Blocks::Rhythmbox.new show_buttons: false`
|
210
|
+
|
211
|
+
| Option | Value | Description | Default
|
212
|
+
| --- | --- | --- | --- |
|
213
|
+
| `show_artist` | bool | Set to `true` or `false` to set whether or not the currently playing artist should be shown. | `true` |
|
214
|
+
| `show_title` | bool | As above, but for the track title | `true` |
|
215
|
+
| `show_buttons` | bool | As above, but for the player control buttons | `true` |
|
216
|
+
|
217
|
+
#### Temperature
|
218
|
+
|
219
|
+
Shows the current temperature and summary of a given location ID. Clicking it will open the full report in your browser.
|
220
|
+
|
221
|
+
`temp = Barr::Blocks::Temperature.new location: "11921", unit: "F"`
|
222
|
+
|
223
|
+
| Option | Value | Description | Default |
|
224
|
+
| --- | --- | --- | --- |
|
225
|
+
| `location` | Yahoo Weather string | The ID [Yahoo Weather](https://weather.yahoo.com) uses for your chosen location. Search for your location then use the number that appears at the end of the URL. For example, New York is 2459115| **REQUIRED**
|
226
|
+
| `unit` | `'C'` or `'F'` | Choose between Celcius and Fahrenheit. | `'C'`
|
227
|
+
|
228
|
+
|
229
|
+
#### WhoAmI
|
230
|
+
|
231
|
+
Shows the currently logged in user.
|
232
|
+
|
233
|
+
`who = Barr::Blocks::WhoAmI.new`
|
234
|
+
|
235
|
+
There are no `WhoAmI` block specific configurable options.
|
236
|
+
|
237
|
+
## Create Your Own Block
|
238
|
+
|
239
|
+
It's reasonably simple to add your own block to your script. Create a `class` that inherits from `Barr::Block` and add your custom `initialize` and `update` methods. The `Barr::Manager` object will read your block's `@output` on each update.
|
240
|
+
|
241
|
+
For example, a block which increments an integer might look like this:
|
242
|
+
|
243
|
+
```ruby
|
244
|
+
#!/usr/bin/env ruby
|
245
|
+
|
246
|
+
require 'rubygems'
|
247
|
+
require 'barr'
|
248
|
+
|
249
|
+
class Incrementer < Barr::Block
|
250
|
+
|
251
|
+
def initialize opts={} # Don't forget to accept your options hash!
|
252
|
+
|
253
|
+
# super ensures the common configurable options can be set
|
254
|
+
super
|
255
|
+
|
256
|
+
# Accept a 'count' option, defaulting to 0 if none is provided
|
257
|
+
@count = opts[:count] || 0
|
258
|
+
|
259
|
+
end
|
260
|
+
|
261
|
+
def update
|
262
|
+
|
263
|
+
# Increment the current count
|
264
|
+
@count += 1
|
265
|
+
|
266
|
+
# Set the @output to be the current count. This is what will be sent to lemonbar
|
267
|
+
@output = @count.to_s
|
268
|
+
end
|
269
|
+
|
270
|
+
end
|
271
|
+
|
272
|
+
@man = Barr::Manager.new
|
273
|
+
|
274
|
+
block = Incrementer.new count: 1, align: :r
|
275
|
+
@man.add_block block
|
276
|
+
|
277
|
+
@man.run
|
278
|
+
```
|
279
|
+
|
280
|
+
## TODO
|
281
|
+
|
282
|
+
Here are a few things I have planned
|
283
|
+
|
284
|
+
* MPD support
|
285
|
+
* Powerline styling options
|
286
|
+
* More configuration for existing blocks
|
287
|
+
* Some form of Conky support
|
288
|
+
* Volume display / control
|
289
|
+
* Stricter option typing
|
290
|
+
* RSS support
|
291
|
+
|
33
292
|
## Contributing
|
34
293
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
294
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/OkayDave/barr. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
295
|
+
|
296
|
+
I'd love to see PRs for more blocks. If you do make any, please ensure that you've added their config options to this README and that you've written some specs for it (including stubbing / mocking out any system and/or API calls it makes).
|
36
297
|
|
298
|
+
If there's a block you'd like to see, but don't have the time, knowledge, or desire to make one then please do open a request on the [Issue Tracker](https://github.com/OkayDave/barr/issues).
|
37
299
|
|
38
300
|
## License
|
39
301
|
|
data/examples/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Examples
|
2
|
+
|
3
|
+
## all_in.rb
|
4
|
+
|
5
|
+

|
6
|
+
|
7
|
+
## barr_example.rb
|
8
|
+
|
9
|
+

|
10
|
+
|
11
|
+
## fizzbuzz.rb
|
12
|
+
|
13
|
+

|
14
|
+
|
15
|
+
## i3_cpu_mem.rb
|
16
|
+
|
17
|
+

|
18
|
+
|
19
|
+
## rhythm.rb
|
20
|
+
|
21
|
+

|
22
|
+
|
23
|
+
## time_and_date.rb
|
24
|
+
|
25
|
+

|
26
|
+
|
27
|
+
## two_temperatures.rb
|
28
|
+
|
29
|
+

|
30
|
+
|
31
|
+
|
data/examples/all_in.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'barr'
|
5
|
+
|
6
|
+
@man = Barr::Manager.new
|
7
|
+
|
8
|
+
|
9
|
+
who = Barr::Blocks::WhoAmI.new align: :r, icon: "\uf007"
|
10
|
+
|
11
|
+
|
12
|
+
i3 = Barr::Blocks::I3.new fcolor: "#FFF",
|
13
|
+
bcolor: "#145266",
|
14
|
+
focus_markers: [">","<"],
|
15
|
+
align: :r,
|
16
|
+
icon: "\uf009"
|
17
|
+
|
18
|
+
artist = Barr::Blocks::Rhythmbox.new bcolor: "#466B41",
|
19
|
+
icon: "\uf028",
|
20
|
+
show_title: false,
|
21
|
+
show_buttons: false
|
22
|
+
|
23
|
+
song = Barr::Blocks::Rhythmbox.new bcolor: "#1E6614",
|
24
|
+
show_buttons: false,
|
25
|
+
show_artist: false
|
26
|
+
|
27
|
+
controls = Barr::Blocks::Rhythmbox.new bcolor: "#0A4D02",
|
28
|
+
show_artist: false,
|
29
|
+
show_title: false,
|
30
|
+
align: :r
|
31
|
+
|
32
|
+
clock = Barr::Blocks::Clock.new bcolor: "#371E5E",
|
33
|
+
format: "%H:%M - %d %b %Y",
|
34
|
+
icon: "\uf073",
|
35
|
+
align: :r
|
36
|
+
|
37
|
+
weather = Barr::Blocks::Temperature.new bcolor: "#4A072B",
|
38
|
+
align: :l,
|
39
|
+
location: "2471217",
|
40
|
+
icon: "\uf0c2 Philadelphia: ",
|
41
|
+
interval: 1500
|
42
|
+
|
43
|
+
cpu = Barr::Blocks::Cpu.new icon: "\uf1fe"
|
44
|
+
|
45
|
+
mem = Barr::Blocks::Mem.new bcolor: "#333333"
|
46
|
+
|
47
|
+
hdd = Barr::Blocks::Hdd.new bcolor: "#444444", device: "sda2", interval: 300
|
48
|
+
|
49
|
+
local = Barr::Blocks::Ip.new bcolor: "#937739", align: :r, icon: "\uf1ce"
|
50
|
+
|
51
|
+
# Left
|
52
|
+
@man.add_block artist
|
53
|
+
@man.add_block song
|
54
|
+
@man.add_block weather
|
55
|
+
@man.add_block cpu
|
56
|
+
@man.add_block mem
|
57
|
+
@man.add_block hdd
|
58
|
+
|
59
|
+
|
60
|
+
# Right
|
61
|
+
@man.add_block i3
|
62
|
+
@man.add_block local
|
63
|
+
@man.add_block who
|
64
|
+
@man.add_block controls
|
65
|
+
@man.add_block clock
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
@man.run
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# pull in the Barr gem
|
4
|
+
require 'rubygems'
|
5
|
+
require 'barr'
|
6
|
+
|
7
|
+
# Create a new manager instance.
|
8
|
+
# The manager is responsible for organising the blocks and delivering their output to lemonbar
|
9
|
+
@manager = Barr::Manager.new
|
10
|
+
|
11
|
+
# Add a 'WhoAmI' block. This just outputs logged in username
|
12
|
+
# Give it a peach background, grey text and updates every 10000 seconds
|
13
|
+
# It will be aligned to the left of the bar
|
14
|
+
@manager.add_block Barr::Blocks::WhoAmI.new(bcolor: "#FFAAAA", fcolor: "#333333", interval: 10000)
|
15
|
+
|
16
|
+
# Add a 'Clock' block.
|
17
|
+
# Clocks can be formatted in the type strftime fashion. This example outputs the current Hour and Minute
|
18
|
+
# It will update every second.
|
19
|
+
# By default, the background text colour will be deferred to the Lemonbar config
|
20
|
+
# If FontAwesome font is available to lemonbar, it will be prepended with a clock icon.
|
21
|
+
@manager.add_block Barr::Blocks::Clock.new(icon: "\uf017", format: "%H:%M", align: :c, interval: 1)
|
22
|
+
|
23
|
+
|
24
|
+
# Add a 'Cpu' block. This shows the current CPU usage (averaged across all cores if present)
|
25
|
+
# It will be aligned to the right side of of the bar
|
26
|
+
# As an interval is not provided, it will update every 5 seconds.
|
27
|
+
# It will be prepended with the text 'Cpu:'
|
28
|
+
@manager.add_block Barr::Blocks::Cpu.new(icon: "Cpu:", align: :r)
|
29
|
+
|
30
|
+
|
31
|
+
# Tell the manager to run the loop. This will continue indefinitely, outputing the data ready to be piped in to lemonbar.
|
32
|
+
@manager.run
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'barr'
|
5
|
+
|
6
|
+
class FizzBuzz < Barr::Block
|
7
|
+
def initialize opts={}
|
8
|
+
super
|
9
|
+
@count = opts[:count] || 0
|
10
|
+
end
|
11
|
+
|
12
|
+
def update
|
13
|
+
@count += 1
|
14
|
+
|
15
|
+
@output = if (@count % 3 == 0) && (@count % 5 == 0)
|
16
|
+
"FizzBuzz"
|
17
|
+
elsif @count % 3 == 0
|
18
|
+
"Fizz"
|
19
|
+
elsif @count % 5 == 0
|
20
|
+
"Buzz"
|
21
|
+
else
|
22
|
+
@count.to_s
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
clock = Barr::Blocks::Clock.new align: :r
|
30
|
+
counter = FizzBuzz.new align: :l, bcolor: "#8CB8FF", fcolor: "#333333", icon: "\uf1ec", interval: 1
|
31
|
+
|
32
|
+
@man = Barr::Manager.new
|
33
|
+
|
34
|
+
@man.add_block clock
|
35
|
+
@man.add_block counter
|
36
|
+
|
37
|
+
@man.run
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'barr'
|
5
|
+
|
6
|
+
@man = Barr::Manager.new
|
7
|
+
|
8
|
+
i3 = Barr::Blocks::I3.new icon: "\uf108", bcolor: "#114152", fcolor: "#DAC1DE", align: :l, focus_markers: ["\uf0a4",""]
|
9
|
+
cpu = Barr::Blocks::Cpu.new icon: "\uf108 CPU:", bcolor: "#491A5E", align: :r
|
10
|
+
mem = Barr::Blocks::Mem.new icon: "RAM:", align: :r, bcolor: "#2F113D"
|
11
|
+
disk = Barr::Blocks::Hdd.new icon: "SSD:", align: :r, bcolor: "#380B4D", device: "sda2"
|
12
|
+
|
13
|
+
@man.add_block i3
|
14
|
+
@man.add_block cpu
|
15
|
+
@man.add_block mem
|
16
|
+
@man.add_block disk
|
17
|
+
|
18
|
+
@man.run
|
data/examples/rhythm.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'barr'
|
5
|
+
|
6
|
+
@man = Barr::Manager.new
|
7
|
+
|
8
|
+
artist = Barr::Blocks::Rhythmbox.new align: :l, show_title: false, show_buttons: false, bcolor: "#266623", icon: "\uf028"
|
9
|
+
title = Barr::Blocks::Rhythmbox.new align: :l, show_artist: false, show_buttons: false, bcolor: "#0D450A"
|
10
|
+
btns = Barr::Blocks::Rhythmbox.new align: :r, show_artist: false, show_title: false, bcolor: "#033B00", interval: 10000
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
@man.add_block artist
|
15
|
+
@man.add_block title
|
16
|
+
@man.add_block btns
|
17
|
+
|
18
|
+
@man.run
|
19
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'barr'
|
5
|
+
|
6
|
+
@man = Barr::Manager.new
|
7
|
+
|
8
|
+
time = Barr::Blocks::Clock.new format: "%H:%M", icon: "\uf017", bcolor: "#114152", fcolor: "#DAC1DE", align: :l
|
9
|
+
date = Barr::Blocks::Clock.new format: "%m of %b %Y", bcolor: "#570B7A", fcolor: "#FFFFFF", align: :r, icon: "\uf073"
|
10
|
+
|
11
|
+
@man.add_block time
|
12
|
+
@man.add_block date
|
13
|
+
|
14
|
+
@man.run
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'barr'
|
5
|
+
|
6
|
+
@man = Barr::Manager.new
|
7
|
+
|
8
|
+
nyc = Barr::Blocks::Temperature.new bcolor: "#42C7AA",
|
9
|
+
fcolor: "#FFF",
|
10
|
+
icon: "New York: ",
|
11
|
+
location: "2459115",
|
12
|
+
interval: 1800
|
13
|
+
|
14
|
+
sanfran = Barr::Blocks::Temperature.new bcolor: "#92A084",
|
15
|
+
fcolor: "#FFF",
|
16
|
+
icon: "San Francisco: ",
|
17
|
+
location: "2487956",
|
18
|
+
align: :r,
|
19
|
+
interval: 1800
|
20
|
+
|
21
|
+
@man.add_block nyc
|
22
|
+
@man.add_block sanfran
|
23
|
+
|
24
|
+
@man.run
|
data/exe/barr_example
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# pull in the Barr gem
|
4
|
+
require 'rubygems'
|
5
|
+
require 'barr'
|
6
|
+
|
7
|
+
# Create a new manager instance.
|
8
|
+
# The manager is responsible for organising the blocks and delivering their output to lemonbar
|
9
|
+
@manager = Barr::Manager.new
|
10
|
+
|
11
|
+
# Add a 'WhoAmI' block. This just outputs logged in username
|
12
|
+
# Give it a peach background, grey text and updates every 10000 seconds
|
13
|
+
# It will be aligned to the left of the bar
|
14
|
+
@manager.add_block Barr::Blocks::WhoAmI.new(bcolor: "#FFAAAA", fcolor: "#333333", interval: 10000)
|
15
|
+
|
16
|
+
# Add a 'Clock' block.
|
17
|
+
# Clocks can be formatted in the type strftime fashion. This example outputs the current Hour and Minute
|
18
|
+
# It will update every second.
|
19
|
+
# By default, the background text colour will be deferred to the Lemonbar config
|
20
|
+
# If FontAwesome font is available to lemonbar, it will be prepended with a clock icon.
|
21
|
+
@manager.add_block Barr::Blocks::Clock.new(icon: "\uf017", format: "%H:%M", align: :c, interval: 1)
|
22
|
+
|
23
|
+
|
24
|
+
# Add a 'Cpu' block. This shows the current CPU usage (averaged across all cores if present)
|
25
|
+
# It will be aligned to the right side of of the bar
|
26
|
+
# As an interval is not provided, it will update every 5 seconds.
|
27
|
+
# It will be prepended with the text 'Cpu:'
|
28
|
+
@manager.add_block Barr::Blocks::Cpu.new(icon: "Cpu:", align: :r)
|
29
|
+
|
30
|
+
|
31
|
+
# Tell the manager to run the loop. This will continue indefinitely, outputing the data ready to be piped in to lemonbar.
|
32
|
+
@manager.run
|
data/lib/barr/block.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Barr
|
2
2
|
class Block
|
3
3
|
attr_reader :output, :align, :fcolor, :bcolor, :interval, :icon
|
4
|
+
|
4
5
|
|
5
6
|
def align; @align; end
|
6
7
|
def fcolor; @fcolor; end
|
@@ -15,10 +16,15 @@ module Barr
|
|
15
16
|
|
16
17
|
def initialize(opts={})
|
17
18
|
@align = opts[:align] || :l
|
18
|
-
@fcolor = opts[:fcolor] || "
|
19
|
-
@bcolor = opts[:bcolor] || "
|
19
|
+
@fcolor = opts[:fcolor] || "-"
|
20
|
+
@bcolor = opts[:bcolor] || "-"
|
20
21
|
@interval = opts[:interval] || 5
|
21
|
-
@icon = opts[:icon] || ""
|
22
|
-
|
22
|
+
@icon = opts[:icon] || ""
|
23
|
+
@output = ""
|
24
|
+
end
|
25
|
+
|
26
|
+
def append_output str
|
27
|
+
@output += str
|
28
|
+
end
|
23
29
|
end
|
24
30
|
end
|
data/lib/barr/blocks/who_am_i.rb
CHANGED
data/lib/barr/manager.rb
CHANGED
@@ -1,19 +1,28 @@
|
|
1
1
|
module Barr
|
2
2
|
class Manager
|
3
3
|
attr_reader :count, :blocks
|
4
|
+
ERROR_ICON = "%{F#FF0000}\uf071"
|
4
5
|
def initialize
|
5
6
|
@count = 0
|
6
7
|
@blocks = []
|
7
8
|
end
|
8
9
|
|
9
10
|
def update
|
11
|
+
# STDERR.puts "update"
|
10
12
|
@blocks.each do |block|
|
11
|
-
|
13
|
+
begin
|
14
|
+
block.update if @count == 0 || @count%block.interval==0
|
15
|
+
rescue StandardError => e
|
16
|
+
STDERR.puts e.message
|
17
|
+
block.append_output(ERROR_ICON) unless block.output.include?(ERROR_ICON)
|
18
|
+
next
|
19
|
+
end
|
12
20
|
end
|
13
21
|
@count += 1
|
14
22
|
end
|
15
23
|
|
16
24
|
def draw
|
25
|
+
# STDERR.puts "draw"
|
17
26
|
outputs = { l: [], c: [], r: []}
|
18
27
|
|
19
28
|
@blocks.each do |block|
|
@@ -25,11 +34,13 @@ module Barr
|
|
25
34
|
opr = outputs[:r].join(" ")
|
26
35
|
|
27
36
|
bar_render = ""
|
28
|
-
bar_render += "%{l}
|
29
|
-
bar_render += "
|
30
|
-
bar_render += "%{r} #{opr}%{F-}%{B-}
|
37
|
+
bar_render += "%{l}#{opl} %{F-}%{B-}" if opl.length > 0
|
38
|
+
bar_render += "%{c} #{opc} %{F-}%{B-}" if opc.length > 0
|
39
|
+
bar_render += "%{r} #{opr}%{F-}%{B-}" if opr.length > 0
|
40
|
+
bar_render.gsub!("\n","")
|
31
41
|
|
32
42
|
system("echo", "-e", bar_render.encode("UTF-8"))
|
43
|
+
# STDERR.puts bar_render
|
33
44
|
end
|
34
45
|
|
35
46
|
def destroy
|
@@ -39,5 +50,14 @@ module Barr
|
|
39
50
|
def add_block block
|
40
51
|
@blocks << block
|
41
52
|
end
|
53
|
+
|
54
|
+
def run
|
55
|
+
while true
|
56
|
+
# STDERR.puts "hello?"
|
57
|
+
self.update
|
58
|
+
self.draw
|
59
|
+
sleep 1
|
60
|
+
end
|
61
|
+
end
|
42
62
|
end
|
43
63
|
end
|
data/lib/barr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Russell
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,6 +84,7 @@ description:
|
|
84
84
|
email:
|
85
85
|
- dave.kerr@gmail.com
|
86
86
|
executables:
|
87
|
+
- barr_example
|
87
88
|
- barr_i3ipc
|
88
89
|
extensions: []
|
89
90
|
extra_rdoc_files: []
|
@@ -99,6 +100,15 @@ files:
|
|
99
100
|
- barr.gemspec
|
100
101
|
- bin/console
|
101
102
|
- bin/setup
|
103
|
+
- examples/README.md
|
104
|
+
- examples/all_in.rb
|
105
|
+
- examples/barr_example.rb
|
106
|
+
- examples/fizzbuzz.rb
|
107
|
+
- examples/i3_cpu_mem.rb
|
108
|
+
- examples/rhythm.rb
|
109
|
+
- examples/time_and_date.rb
|
110
|
+
- examples/two_temperatures.rb
|
111
|
+
- exe/barr_example
|
102
112
|
- exe/barr_i3ipc
|
103
113
|
- lib/barr.rb
|
104
114
|
- lib/barr/block.rb
|