barr 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52846bb83c6e265578a031aff81ee89da3abab61
4
- data.tar.gz: 3d3cc3ca30e310f0fe75f12541132b3e789598d7
3
+ metadata.gz: 185b5db5b041d0198cd6832e6da6c279e52b49f9
4
+ data.tar.gz: 8c2105ccfc2ba40f1e72c7813281d87ddc23653a
5
5
  SHA512:
6
- metadata.gz: fa6b17a9d3bc91fe8f64347f821182297f98ffe682e6ec51749d633a09b508191e3d7e6b1fa016eee66bb1936ae3ed3b2e289eef27cddfd4c03a4b0bda2ee43d
7
- data.tar.gz: a2b7ed1d4433931b823af96a9bcdce42a14ba252ff05c5b7fbaa660aa3d52340110ae0e5890c25cb41c0eca82ee9d1ac42fcb22a8af92ce4493daa4e2b8a6c00
6
+ metadata.gz: d5b0bbaf1b4b58c55bae9246f3b597f9fbda345fda3069be30057a090e63b6ce0a710df64ffe38d8dddcd8b72a29a5a4e6a385aa539cb6f1ca761075cdf15cc1
7
+ data.tar.gz: 884669dd60977c7549dbeb9b5ef907531de052ff40c6bb186b98cb9275d4f5308979ebe39c7a557b746e948c6f66fbdd731ab4d575ed7a402b0457d862331fff
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --format documentation
2
2
  --color
3
+ --require spec_helper
data/README.md CHANGED
@@ -4,7 +4,7 @@
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
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.
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.
8
8
 
9
9
  ## Installation
10
10
 
@@ -20,42 +20,42 @@ See [Examples folder](http://github.com/okaydave/barr/tree/master/examples) for
20
20
 
21
21
  Documentation about all available blocks and their options can be found further down in this document.
22
22
 
23
- ### Simple Usage Example
23
+ ### Simple Usage Example
24
24
 
25
25
  *barr_example.rb*
26
26
  ```ruby
27
- #!/usr/bin/env ruby
27
+ #!/usr/bin/env ruby
28
28
 
29
- # pull in the Barr gem
30
- require 'rubygems'
31
- require 'barr'
29
+ # pull in the Barr gem
30
+ require 'rubygems'
31
+ require 'barr'
32
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
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
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)
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 Barr::Blocks::Whoami.new(bcolor: '#FFAAAA', fcolor: '#333333', interval: 10000)
41
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)
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 Barr::Blocks::Clock.new(icon: "\uf017", format: '%H:%M', align: :c, interval: 1)
48
48
 
49
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)
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 Barr::Blocks::CPU.new(icon: 'Cpu:', align: :r)
55
55
 
56
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
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
59
  ```
60
60
 
61
61
  This can be piped in to lemonbar as usual:
@@ -66,12 +66,12 @@ This can be piped in to lemonbar as usual:
66
66
  ./barr_example.rb | lemonbar -g 800x30+960+00 -d -B "#333333" -f "Roboto Mono Medium:size=11" -f "Font Awesome:size=11" | sh
67
67
  ```
68
68
 
69
- Which should have Lemonbar appear as:
69
+ Which should have Lemonbar appear as:
70
70
 
71
71
  ![simple example](http://i.imgur.com/r4dtoqm.png)
72
72
 
73
73
 
74
- ## Block Configuration
74
+ ## Block Configuration
75
75
 
76
76
  ### Common
77
77
 
@@ -79,225 +79,224 @@ All blocks inherit their behaviour from a base Block. This means that all blocks
79
79
 
80
80
  | Option | Value | Description | Default |
81
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` |
82
+ | `fgcolor` | 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
+ | `bgcolor` | 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' data. 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
86
  | `align` | Symbol | One of `:l`, `:c`, `:r` for left, centre and right alignment respectively. | `:l` |
87
-
87
+
88
88
  These are set when a Block is initialized:
89
-
90
- ```ruby
89
+
90
+ ```ruby
91
91
  @man = Barr::Manager.new
92
92
 
93
- block1 = Barr::Block.new fcolor: "#FF0000",
94
- bcolor: "#000000",
95
- icon: "I am:",
96
- interval: 10,
93
+ block1 = Barr::Block.new fgcolor: '#FF0000',
94
+ bgcolor: '#000000',
95
+ icon: 'I am:',
96
+ interval: 10,
97
97
  align: :r
98
98
 
99
- man.add_block block1
100
-
99
+ man.add block1
100
+
101
101
  ```
102
102
 
103
103
  If you're unfamiliar with Ruby here's a couple of tips that might help with reading and writing your own blocks:
104
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.
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
107
  * If you want to use a default value, you can just omit the option altogether.
108
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
109
 
110
110
  For example, the following code:
111
111
 
112
- ```ruby
112
+ ```ruby
113
113
  @man = Barr::Manager.new()
114
114
 
115
- block1 = Barr::Blocks::WhoAmI.new({fcolor: "#FFF", bcolor: "#000", align: :c})
115
+ block1 = Barr::Blocks::Whoami.new({fgcolor: '#FFF', bgcolor: '#000', align: :c})
116
116
 
117
- @man.add_block(block1)
117
+ @man.add(block1)
118
118
 
119
119
  ```
120
-
120
+
121
121
  Is functionally the same as this:
122
122
 
123
- ```ruby
124
- @man = Barr::Manager.new
123
+ ```ruby
124
+ @man = Barr::Manager.new
125
125
 
126
- block1 = Barr::Blocks::WhoAmI.new align: :c,
127
- fcolor: "#FFF",
128
- bcolor: "#000"
126
+ block1 = Barr::Blocks::Whoami.new align: :c,
127
+ fgcolor: '#FFF',
128
+ bgcolor: '#000'
129
129
 
130
- @man.add_block block1
130
+ @man.add block1
131
131
 
132
132
  ```
133
133
 
134
134
  You can also add Blocks straight to the manager if you'd like to skip that step, or even mix/match:
135
135
 
136
- ```ruby
137
- @man = Barr::Manager.new
136
+ ```ruby
137
+ @man = Barr::Manager.new
138
138
 
139
- seperate_block = Barr::Blocks::WhoAmI.new
139
+ seperate_block = Barr::Blocks::Whoami.new
140
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
141
+ @man.add Barr::Blocks::Whoami.new bcolor: '#000', fcolor: '#FFF'
142
+ @man.add(Barr::Blocks::Whoami.new(icon: 'Me!', align: :c))
143
+ @man.add separate_block
144
144
  ```
145
145
 
146
146
 
147
147
  ### Block Specific Configuration
148
148
 
149
- #### Clock
149
+ #### Clock
150
150
 
151
151
  Shows the current date and/or time.
152
152
 
153
- `clock = Barr::Blocks::Clock.new format: "%m %b %Y", icon: "Date: "`
153
+ `clock = Barr::Blocks::Clock.new format: '%m %b %Y', icon: 'Date: '`
154
154
 
155
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"` |
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
158
 
159
- #### Cpu
159
+ #### CPU
160
160
 
161
161
  Shows CPU load averaged across all cores.
162
162
 
163
- `cpu = Barr::Blocks::Cpu.new`
164
-
165
- There are no `Cpu` block specific configurable options.
163
+ `cpu = Barr::Blocks::CPU.new`
164
+
165
+ There are no `CPU` block specific configurable options.
166
166
 
167
- #### Hdd
167
+ #### HDD
168
168
 
169
169
  Shows selected filesystem's used and free space.
170
170
 
171
- `hdd = Barr::Blocks::Hdd.new device: "sda2"`
171
+ `hdd = Barr::Blocks::HDD.new device: 'sda2'`
172
172
 
173
173
  | Option | Value | Description | Default |
174
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** |
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
176
 
177
- #### I3
177
+ #### I3
178
178
 
179
179
  **Requires i3wm**. Shows the current workspaces and highlights the active one. You can click a workspace name to change to there.
180
180
 
181
- `i3 = Barr::Blocks::I3.new focus_markers: ["\u",""]`
181
+ `i3 = Barr::Blocks::I3.new focus_markers: ["\u02C3",'']`
182
182
 
183
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. | [">", "<"] |
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
186
 
187
- #### ip
187
+ #### ip
188
188
 
189
- Shows the selected adaptor's IPv4 address. If no device is specified, it will make a guess.
189
+ Shows the selected adaptor's IP (IPv4 by default) address. If no device is specified, it will make a guess.
190
190
 
191
- `ip = Barr::Blocks::Ip.new device: "enp3s0"`
191
+ `ip = Barr::Blocks::IP.new device: 'enp3s0'`
192
192
 
193
193
  | Option | Value | Description | Default |
194
194
  | --- | --- | --- | --- |
195
- | `device` | String | The name of the device | `192` |
196
-
197
- #### Mem
195
+ | `device` | String | The name of the device | `192` |
196
+ | `ipv6` | Boolean | Get the IPv6 address of the device | `false` |
197
+
198
+ #### Mem
198
199
 
199
- Shows current RAM usage.
200
+ Shows current RAM usage.
200
201
 
201
202
  `mem = Barr::Blocks::Mem.new`
202
-
203
+
203
204
  There are no `Mem` block specific configurable options.
204
205
 
205
- #### Rhythmbox
206
+ #### Rhythmbox
206
207
 
207
- **Requires Rhythmbox and rhythmbox-client**. Shows currently playing artist and/or track, as well as control buttons.
208
+ **Requires Rhythmbox and rhythmbox-client**. Shows currently playing artist and/or track, as well as control buttons. Control buttons use FontAwesome.
208
209
 
209
- `rb = Barr::Blocks::Rhythmbox.new show_buttons: false`
210
+ `rb = Barr::Blocks::Rhythmbox.new buttons: false`
210
211
 
211
- | Option | Value | Description | Default
212
+ | Option | Value | Description | Default |
212
213
  | --- | --- | --- | --- |
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` |
214
+ | `artist` | bool | Set to `true` or `false` to set whether or not the currently playing artist should be shown. | `true` |
215
+ | `buttons` | bool | As above, but for the player control buttons | `true` |
216
+ | `title` | bool | As above, but for the track title | `true` |
216
217
 
217
218
  #### Temperature
218
219
 
219
220
  Shows the current temperature and summary of a given location ID. Clicking it will open the full report in your browser.
220
221
 
221
- `temp = Barr::Blocks::Temperature.new location: "11921", unit: "F"`
222
+ `temp = Barr::Blocks::Temperature.new location: '11921', unit: 'F'`
222
223
 
223
- | Option | Value | Description | Default |
224
+ | Option | Value | Description | Default |
224
225
  | --- | --- | --- | --- |
225
226
  | `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
227
  | `unit` | `'C'` or `'F'` | Choose between Celcius and Fahrenheit. | `'C'`
227
228
 
228
229
 
229
- #### WhoAmI
230
+ #### Whoami
230
231
 
231
- Shows the currently logged in user.
232
+ Shows the currently logged in user.
232
233
 
233
- `who = Barr::Blocks::WhoAmI.new`
234
+ `who = Barr::Blocks::Whoami.new`
234
235
 
235
- There are no `WhoAmI` block specific configurable options.
236
+ There are no `Whoami` block specific configurable options.
236
237
 
237
238
  ## Create Your Own Block
238
239
 
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
+ 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
 
241
242
  For example, a block which increments an integer might look like this:
242
243
 
243
- ```ruby
244
- #!/usr/bin/env ruby
244
+ ```ruby
245
+ #!/usr/bin/env ruby
245
246
 
246
247
  require 'rubygems'
247
248
  require 'barr'
248
249
 
249
- class Incrementer < Barr::Block
250
+ class Incrementer < Barr::Block
250
251
 
251
252
  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
-
253
+
254
+ # super ensures the common configurable options can be set
255
+ super
256
+
256
257
  # Accept a 'count' option, defaulting to 0 if none is provided
257
- @count = opts[:count] || 0
258
-
258
+ @count = opts[:count] || 0
259
259
  end
260
-
261
- def update
262
-
260
+
261
+ def update!
262
+
263
263
  # Increment the current count
264
- @count += 1
265
-
264
+ @count += 1
265
+
266
266
  # Set the @output to be the current count. This is what will be sent to lemonbar
267
267
  @output = @count.to_s
268
268
  end
269
269
 
270
270
  end
271
271
 
272
- @man = Barr::Manager.new
272
+ @man = Barr::Manager.new
273
273
 
274
274
  block = Incrementer.new count: 1, align: :r
275
- @man.add_block block
275
+ @man.add block
276
276
 
277
- @man.run
277
+ @man.run!
278
278
  ```
279
279
 
280
- ## TODO
280
+ ## TODO
281
281
 
282
282
  Here are a few things I have planned
283
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
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
290
  * RSS support
291
-
291
+
292
292
  ## Contributing
293
293
 
294
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
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).
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).
297
297
 
298
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).
299
299
 
300
300
  ## License
301
301
 
302
302
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
303
-
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Dave Russell"]
10
10
  spec.email = ["dave.kerr@gmail.com"]
11
11
 
12
- spec.summary = "Barr is a status line generate for use with Lemonbar"
12
+ spec.summary = "Barr is a status line generator for use with Lemonbar"
13
13
  spec.homepage = "https://github.com/OkayDave/barr"
14
14
  spec.license = "MIT"
15
15
 
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "bundler", "~> 1.11"
29
29
  spec.add_development_dependency "rake", "~> 10.0"
30
30
  spec.add_development_dependency "rspec", "~> 3.0"
31
+ spec.add_development_dependency "timecop", "~> 0.8.0"
31
32
 
32
33
  spec.add_runtime_dependency "i3ipc", "0.2.0"
33
34
  spec.add_runtime_dependency "weather-api", "1.2.0"
@@ -27,5 +27,3 @@
27
27
  ## two_temperatures.rb
28
28
 
29
29
  ![two_temperatures.rb](http://i.imgur.com/V2vSJBs.png)
30
-
31
-