barr 0.2.2 → 0.2.3

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: 1325be83970f3c39bd02fb2cbdae88e2ba56fc06
4
- data.tar.gz: 6f538d8834b692fa2c738429affdc4ceac7d3e77
3
+ metadata.gz: ecd1764d1551147046c97126a5a04b0846da9a09
4
+ data.tar.gz: b9dd688b430745a77329f02ad1fca93b2bb0f471
5
5
  SHA512:
6
- metadata.gz: 83c7b0e7b9c402689db78859badc46f9e56af8b94e6df1450479d711ec8c5e7c8dfad064f89c9923e16a66be559ec98e5ff1b3343e71b0b5f7cff3fe2d09c606
7
- data.tar.gz: 11a34a6d9d699f5b6947eb6f32c1b836e35bf1067e3c458af7d0d619c04c18f2e335c83c1971b620cc8b43360adb9ce837f1446a642991ee247bc03532fa481e
6
+ metadata.gz: 8424e88aa276c9971652084baecc3876f53faf5b9099c86d8270dfd053b7bc7319f968b9481b8e0d56fb4f6f3054611f4a1648c82c0ff1cecdefafe0db4045b7
7
+ data.tar.gz: c586af613120ab41d5b28a651bcfb8f1a56fb9aac0cb0668b50f99cc0569fea0388559c1a2f5fd2ae3499e411254a1124e03c1708440f76bae3b86d11458b2d8
data/README.md CHANGED
@@ -14,6 +14,10 @@ If that doesn't work, you probably don't have Ruby installed. I'd recommend you
14
14
 
15
15
  For a simpler install, check your distro's package manager. That should be fine.
16
16
 
17
+ To update to the latest release of Barr:
18
+
19
+ $ gem update barr
20
+
17
21
  ## Usage
18
22
 
19
23
  See [Examples folder](http://github.com/okaydave/barr/tree/master/examples) for more detailed usage examples.
@@ -81,7 +85,7 @@ All blocks inherit their behaviour from a base Block. This means that all blocks
81
85
  | ------ | ----- | ----------- | ------- |
82
86
  | `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
87
  | `bgcolor` | RGB Hex string or `-` | As above. To use the configured lemonbar colors, use `'-'`. This also applies to the `fgcolor` 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 | `''` |
88
+ | `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
89
  | `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
90
  | `align` | Symbol | One of `:l`, `:c`, `:r` for left, centre and right alignment respectively. | `:l` |
87
91
 
@@ -146,7 +150,7 @@ seperate_block = Barr::Blocks::Whoami.new
146
150
 
147
151
  ### Block Specific Configuration
148
152
 
149
- #### Battery
153
+ #### Battery
150
154
 
151
155
  Show battery status.
152
156
 
@@ -156,6 +160,17 @@ Show battery status.
156
160
  | --- | --- | --- | --- |
157
161
  | `show_remaining` | bool | Show the remaining battery time | `true` |
158
162
 
163
+ #### Bspwm (Experimental)
164
+
165
+ **Requires Bspwm**. Shows desktops for selected monitor. and highlights focused one. Unfocused desktops are clickable. Could do with some optimization work and feedback from people that use BSP frequently, especially with multiple monitors.
166
+
167
+ `bsp = Barr::Blocks::Bspwm.new monitor: "DP-4", invert_focus_colors: true`
168
+
169
+ | Option | Value | Description | Default |
170
+ | --- | --- | --- | --- |
171
+ | `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. | `['>', '<']` |
172
+ | `invert_focus_colors` | bool | Should the block's `fgcolor` and `bgcolor` attributes be reversed for the workspace that is currently focused. | `false` |
173
+ | `monitor` | String | The monitor ID (e.g. from `xrandr`) that the bar should read the desktops from. | First monitor found |
159
174
 
160
175
  #### Clock
161
176
 
@@ -167,6 +182,17 @@ Shows the current date and/or time.
167
182
  | --- | --- | --- | --- |
168
183
  | `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'` |
169
184
 
185
+
186
+ #### Conky (Experimental)
187
+
188
+ **Requires Conky**. Show a conky `TEXT` formatted output. This is quite inefficient at the moment and if left running for prolonged periods will eat up your disk space. Otherwise works okay. Not all conky variables work well, will take a bit of trial and error.
189
+
190
+ `conky = Barr::Blocks::Conky.new string: "${cpu}"`
191
+
192
+ | Option | Value | Description | Default |
193
+ | --- | --- | --- | --- |
194
+ | `text` | Conky 'TEXT' string | String made up of [one or more conky variables](http://conky.sourceforge.net/variables.html), as you might find in the `TEXT` section of a conkyrc | **REQUIRED** |
195
+
170
196
  #### CPU
171
197
 
172
198
  Shows CPU load averaged across all cores.
@@ -235,6 +261,16 @@ There are no `Processes` block specific configurable options.
235
261
  | `buttons` | bool | As above, but for the player control buttons | `true` |
236
262
  | `title` | bool | As above, but for the track title | `true` |
237
263
 
264
+
265
+ #### Separator
266
+
267
+ This block is a simple string to be used as a separator between other blocks.
268
+
269
+ | Option | Value | Description | Default |
270
+ | --- | --- | --- | --- |
271
+ | `symbol` | any string | The string to use as a separator | `&#124;`
272
+
273
+
238
274
  #### Temperature
239
275
 
240
276
  Shows the current temperature and summary of a given location ID. Clicking it will open the full report in your browser.
@@ -243,8 +279,8 @@ Shows the current temperature and summary of a given location ID. Clicking it wi
243
279
 
244
280
  | Option | Value | Description | Default |
245
281
  | --- | --- | --- | --- |
246
- | `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**
247
- | `unit` | `'C'` or `'F'` | Choose between Celcius and Fahrenheit. | `'C'`
282
+ | `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** |
283
+ | `unit` | `'C'` or `'F'` | Choose between Celcius and Fahrenheit. | `'C'` |
248
284
 
249
285
 
250
286
  #### Whoami
@@ -255,6 +291,8 @@ Shows the currently logged in user.
255
291
 
256
292
  There are no `Whoami` block specific configurable options.
257
293
 
294
+
295
+
258
296
  ## Create Your Own Block
259
297
 
260
298
  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.
@@ -8,6 +8,10 @@
8
8
 
9
9
  ![barr_example.rb](http://i.imgur.com/r4dtoqm.png)
10
10
 
11
+ ## bsp.rb
12
+
13
+ ![bsp.rb](http://i.imgur.com/DDqCoeq.png)
14
+
11
15
  ## fizzbuzz.rb
12
16
 
13
17
  ![fizzbuzz.rb](http://i.imgur.com/Cy0ZdrN.png)
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'barr'
5
+
6
+ @man = Barr::Manager.new
7
+
8
+ bsp = Barr::Blocks::Bspwm.new icon: "\uf108", bgcolor: '#114152', fgcolor: '#DAC1DE', align: :l, focus_markers: ['',''], invert_focus_colors: true, interval: 1
9
+
10
+ bsp_df = Barr::Blocks::Bspwm.new align: :r, interval: 1
11
+
12
+ @man.add bsp
13
+ @man.add bsp_df
14
+
15
+ @man.run!
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'barr'
5
+
6
+ @man = Barr::Manager.new
7
+
8
+ netspeed = Barr::Blocks::Conky.new text: "${downspeedf enp3s0} ${upspeedf enp3s0}", align: :l, interval: 1
9
+ cpu = Barr::Blocks::Conky.new text: "${cpubar}", align: :c, interval: 1
10
+ swap = Barr::Blocks::Conky.new text: "${swap}", align: :r, interval: 1
11
+
12
+ @man.add netspeed
13
+ @man.add cpu
14
+ @man.add swap
15
+
16
+ @man.run!
@@ -3,7 +3,9 @@ require 'barr/manager'
3
3
  require 'barr/block'
4
4
 
5
5
  require 'barr/blocks/battery'
6
+ require 'barr/blocks/bspwm'
6
7
  require 'barr/blocks/clock'
8
+ require 'barr/blocks/conky'
7
9
  require 'barr/blocks/cpu'
8
10
  require 'barr/blocks/hdd'
9
11
  require 'barr/blocks/i3'
@@ -13,6 +15,7 @@ require 'barr/blocks/processes'
13
15
  require 'barr/blocks/rhythmbox'
14
16
  require 'barr/blocks/temperature'
15
17
  require 'barr/blocks/whoami'
18
+ require 'barr/blocks/separator'
16
19
 
17
20
  module Barr
18
21
  end
@@ -1,6 +1,7 @@
1
1
  module Barr
2
2
  class Block
3
- attr_reader :align, :bgcolor, :fgcolor, :icon, :interval, :output
3
+ attr_reader :align, :bgcolor, :fgcolor, :icon, :interval, :output
4
+ attr_accessor :manager
4
5
 
5
6
  def initialize(opts = {})
6
7
  reassign_deprecated_option opts, :fcolor, :fgcolor
@@ -32,6 +33,11 @@ module Barr
32
33
  def update!
33
34
  end
34
35
 
36
+ def tmp_filename
37
+ @tmp_filename ||= "/tmp/#{SecureRandom.uuid}-#{self.class.name.gsub(/::/, "-")}-#{SecureRandom.urlsafe_base64}"
38
+ return @tmp_filename
39
+ end
40
+
35
41
  # Backwards compatiblity methods.
36
42
  # can't use alias/alias_method as they don't
37
43
  # trickle down to subclasses
@@ -40,7 +46,7 @@ module Barr
40
46
 
41
47
  def reassign_deprecated_option opts, old, new
42
48
  if opts[new].nil? && !opts[old].nil?
43
- STDERR.puts "Warning: the '#{old}' option will soon be deprecated in favour of '#{new}'. \n Please update your script."
49
+ STDERR.puts "Warning: #{self.class.name}'s '#{old}' option will soon be deprecated in favour of '#{new}'. \n Please update your script."
44
50
  opts[new] = opts[old]
45
51
  end
46
52
  end
@@ -0,0 +1,72 @@
1
+ require 'barr/block'
2
+ require 'json'
3
+
4
+ module Barr
5
+ module Blocks
6
+
7
+ class Bspwm < Block
8
+
9
+ attr_reader :monitor, :tree, :focus_markers
10
+ attr_accessor :invert_focus_colors
11
+ def initialize opts={}
12
+ super
13
+ @monitor = opts[:monitor] || first_monitor
14
+ @invert_focus_colors = opts[:invert_focus_colors] || false
15
+ @focus_markers = opts[:focus_markers] || %w(> <)
16
+ end
17
+
18
+ def update!
19
+ @tree = nil
20
+ op = []
21
+ focused = ""
22
+
23
+ bsp_tree["monitors"].each do |monitor|
24
+ next if monitor["name"] != @monitor
25
+ focused = monitor["focusedDesktopName"]
26
+ monitor["desktops"].each do |desktop|
27
+ if desktop["name"] == focused
28
+ op << focused_desktop(desktop)
29
+ else
30
+ op << unfocused_desktop(desktop)
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ @output = op.join(" ")
37
+ end
38
+
39
+ def bsp_tree
40
+ @tree ||= JSON.parse(sys_cmd)
41
+ end
42
+
43
+ def focused_desktop desktop
44
+ op = ""
45
+ op += invert_colors if @invert_focus_colors
46
+ op += @focus_markers[0] + " "
47
+ op += desktop["name"]
48
+ op += " " + @focus_markers[1]
49
+ op += invert_colors if @invert_focus_colors
50
+
51
+ op
52
+ end
53
+
54
+ def unfocused_desktop desktop
55
+ op = ""
56
+ op += "%{A:bspc desktop -f #{desktop["name"].gsub(":","\:")}:} "
57
+ op += "#{desktop["name"]}"
58
+ op += " %{A}"
59
+
60
+ return op
61
+ end
62
+
63
+ def first_monitor
64
+ bsp_tree["primaryMonitorName"]
65
+ end
66
+
67
+ def sys_cmd
68
+ `bspc wm -d`.chomp
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,54 @@
1
+ require 'barr/block'
2
+
3
+ module Barr
4
+ module Blocks
5
+
6
+ class Conky < Block
7
+ attr_reader :text
8
+ def initialize opts={}
9
+ super
10
+ @text = opts[:text]
11
+
12
+ write_template
13
+ spawn_conky
14
+ end
15
+
16
+ def update!
17
+ @output = sys_cmd
18
+ end
19
+
20
+ def sys_cmd
21
+ `tail -n1 #{@filename_output}`.chomp.gsub("#","\u2588")
22
+ end
23
+
24
+ def write_template
25
+ @conky_template = "
26
+ out_to_x no
27
+ out_to_console yes
28
+ own_window no
29
+ update_interval #{@interval.to_f.to_s}
30
+ TEXT
31
+ #{@text}
32
+ ".gsub(/^\s+/, '').chomp!
33
+
34
+ @filename_template = tmp_filename+"-conky"
35
+ @filename_output = tmp_filename+"-output"
36
+
37
+ STDERR.puts "@conky_template: "
38
+ STDERR.puts @conky_template
39
+ File.open(@filename_template, "w") { |f| f.write(@conky_template) }
40
+ end
41
+
42
+ def spawn_conky
43
+ @process = spawn("conky -c #{@filename_template} > #{@filename_output}")
44
+ Process.detach(@process)
45
+ end
46
+
47
+ def destroy!
48
+ `rm #{@filename_template}`
49
+ `rm #{@filename_output}`
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,18 @@
1
+ require 'barr/block'
2
+
3
+ module Barr
4
+ module Blocks
5
+ class Separator < Block
6
+
7
+ def initialize(opts = {})
8
+ super
9
+ @symbol = opts[:symbol] || '|'
10
+ end
11
+
12
+ def update!
13
+ @output = @symbol
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -1,4 +1,5 @@
1
1
  require 'barr/block'
2
+ require 'securerandom'
2
3
 
3
4
  module Barr
4
5
  class Manager
@@ -13,6 +14,7 @@ module Barr
13
14
  end
14
15
 
15
16
  def add(block)
17
+ block.manager = self
16
18
  @blocks << block
17
19
  end
18
20
 
@@ -62,6 +64,10 @@ module Barr
62
64
 
63
65
  @count += 1
64
66
  end
67
+
68
+ def id
69
+ @id ||= SecureRandom.uuid
70
+ end
65
71
 
66
72
  # compatibility methods.
67
73
  # alias_method would work here, but for consistency with Block
@@ -1,3 +1,3 @@
1
1
  module Barr
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
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.2.2
4
+ version: 0.2.3
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-30 00:00:00.000000000 Z
11
+ date: 2016-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -117,6 +117,8 @@ files:
117
117
  - examples/README.md
118
118
  - examples/all_in.rb
119
119
  - examples/barr_example.rb
120
+ - examples/bsp.rb
121
+ - examples/conky.rb
120
122
  - examples/fizzbuzz.rb
121
123
  - examples/i3_cpu_mem.rb
122
124
  - examples/rhythm.rb
@@ -127,7 +129,9 @@ files:
127
129
  - lib/barr.rb
128
130
  - lib/barr/block.rb
129
131
  - lib/barr/blocks/battery.rb
132
+ - lib/barr/blocks/bspwm.rb
130
133
  - lib/barr/blocks/clock.rb
134
+ - lib/barr/blocks/conky.rb
131
135
  - lib/barr/blocks/cpu.rb
132
136
  - lib/barr/blocks/hdd.rb
133
137
  - lib/barr/blocks/i3.rb
@@ -135,6 +139,7 @@ files:
135
139
  - lib/barr/blocks/mem.rb
136
140
  - lib/barr/blocks/processes.rb
137
141
  - lib/barr/blocks/rhythmbox.rb
142
+ - lib/barr/blocks/separator.rb
138
143
  - lib/barr/blocks/temperature.rb
139
144
  - lib/barr/blocks/whoami.rb
140
145
  - lib/barr/manager.rb