barr 0.1.2 → 0.2.0

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.
@@ -1,9 +1,23 @@
1
+ require 'barr/block'
2
+
1
3
  module Barr
2
4
  module Blocks
3
- class Cpu < Block
4
- def update
5
- @output = `top -bn1 | grep load | awk '{print $(NF-2)+$(NF-1)+$(NF)}'`.chomp + "%"
5
+ class CPU < Block
6
+
7
+ def update!
8
+ idle = sys_cmd.scan(/(\d{1,3}\.\d) id/).flatten.first.to_f
9
+
10
+ @output = "#{(100 - idle).round(1)}%"
6
11
  end
12
+
13
+ private
14
+
15
+ def sys_cmd
16
+ `top -bn1 | grep 'Cpu(s)'`.chomp
17
+ end
18
+
7
19
  end
20
+
21
+ Cpu = CPU
8
22
  end
9
23
  end
@@ -1,21 +1,29 @@
1
+ require 'barr/block'
2
+
1
3
  module Barr
2
4
  module Blocks
3
- class Hdd < Block
4
- attr_reader :device
5
- def initialize opts={}
5
+ class HDD < Block
6
+
7
+ def initialize(opts = {})
6
8
  super
9
+
7
10
  @device = opts[:device]
8
11
  end
9
12
 
10
- def update
11
- total, used, perc = sys_cmd.chomp.split(" ")
12
- @output = "#{used} / #{total} (#{perc})"
13
+ def update!
14
+ total, used, perc = sys_cmd.split(' ')
15
+
16
+ @output = "#{used} / #{total} (#{perc})"
13
17
  end
14
18
 
19
+ private
20
+
15
21
  def sys_cmd
16
- `df -h | grep #{@device} | awk '{printf "%s %s %s", $2, $3, $5}'`
22
+ `df -h | grep #{@device} | awk '{printf "%s %s %s", $2, $3, $5}'`.chomp
17
23
  end
24
+
18
25
  end
19
26
 
27
+ Hdd = HDD
20
28
  end
21
29
  end
@@ -1,15 +1,20 @@
1
+ require 'i3ipc'
2
+ require 'barr/block'
3
+
1
4
  module Barr
2
5
  module Blocks
3
-
4
6
  class I3 < Block
7
+
5
8
  attr_reader :focus_markers, :i3, :workspaces
6
- def initialize opts={}
9
+
10
+ def initialize(opts = {})
7
11
  super
8
- @focus_markers = opts[:focus_markers] || [">", "<"]
12
+
13
+ @focus_markers = opts[:focus_markers] || %w(> <)
9
14
  @i3 = i3_connection
10
15
  end
11
16
 
12
- def update
17
+ def update!
13
18
  @workspaces = @i3.workspaces.map do |wsp|
14
19
  if wsp.focused
15
20
  "#{l_marker}#{wsp.name}#{r_marker}"
@@ -17,10 +22,11 @@ module Barr
17
22
  "%{A:barr_i3ipc workspace #{wsp.num}:} #{wsp.name} %{A}"
18
23
  end
19
24
  end
20
- @output = @workspaces.join("")
25
+
26
+ @output = @workspaces.join('')
21
27
  end
22
28
 
23
- def destroy
29
+ def destroy!
24
30
  @i3.close
25
31
  end
26
32
 
@@ -28,6 +34,8 @@ module Barr
28
34
  I3Ipc::Connection.new
29
35
  end
30
36
 
37
+ private
38
+
31
39
  def l_marker
32
40
  @focus_markers[0]
33
41
  end
@@ -35,6 +43,7 @@ module Barr
35
43
  def r_marker
36
44
  @focus_markers[1]
37
45
  end
46
+
38
47
  end
39
48
  end
40
49
  end
@@ -1,24 +1,29 @@
1
+ require 'barr/block'
2
+
1
3
  module Barr
2
4
  module Blocks
3
- class Ip < Block
5
+ class IP < Block
4
6
 
5
7
  attr_reader :device
6
-
7
- def initialize opts={}
8
+
9
+ def initialize(opts = {})
8
10
  super
9
- @device = opts[:device] || "192"
11
+ @device = opts[:device] || 'lo'
12
+ @version = opts[:ipv6] ? 'inet6' : 'inet'
10
13
  end
11
14
 
12
- def update
13
- ip, dev = sys_cmd.chomp.split(" ")
14
- ip = ip.split("/")[0]
15
-
16
- @output = "#{dev} > #{ip}"
15
+ def update!
16
+ ip = sys_cmd.split('/').first
17
+
18
+ @output = "#{@device} > #{ip}"
17
19
  end
18
-
20
+
21
+ private
22
+
19
23
  def sys_cmd
20
- `ip addr | grep #{@device} | tail -n1 | awk '{printf "%s %s", $2, $8}'`
24
+ `ip addr show #{@device} | grep '#{@version}\s' | awk '{print $2}'`.chomp
21
25
  end
22
26
  end
27
+ Ip = IP
23
28
  end
24
29
  end
@@ -1,13 +1,17 @@
1
+ require 'barr/block'
2
+
1
3
  module Barr
2
4
  module Blocks
3
5
  class Mem < Block
4
6
 
5
- def update
6
- @output = sys_cmd.chomp
7
+ def update!
8
+ @output = sys_cmd
7
9
  end
8
10
 
11
+ private
12
+
9
13
  def sys_cmd
10
- `free -m | grep Mem | awk '{printf "%sM / %sM", $3, $2}'`
14
+ `free -h | grep 'cache:' | awk '{printf "%s / %sG", $(NF-1), $(NF-1)+$(NF)}'`.chomp
11
15
  end
12
16
  end
13
17
  end
@@ -0,0 +1,65 @@
1
+ require 'barr/block'
2
+
3
+ module Barr
4
+ module Blocks
5
+ class Rhythmbox < Block
6
+ attr_reader :view_opts
7
+
8
+ def initialize(opts = {})
9
+ super
10
+ reassign_deprecated_option opts, :show_artist, :artist
11
+ reassign_deprecated_option opts, :show_title, :title
12
+ reassign_deprecated_option opts, :show_buttons, :buttons
13
+
14
+ @view_opts = {
15
+ artist: opts[:artist].nil? || opts[:artist],
16
+ buttons: opts[:buttons].nil? || opts[:buttons],
17
+ title: opts[:title].nil? || opts[:title]
18
+ }
19
+ end
20
+
21
+ def update!
22
+ op = []
23
+
24
+ if @view_opts[:artist] || @view_opts[:title]
25
+ if(running?)
26
+ info = sys_cmd.split(' - ')
27
+
28
+ if @view_opts[:artist] && @view_opts[:title]
29
+ op << info.join(' - ')
30
+ elsif @view_opts[:artist]
31
+ op << info[0]
32
+ elsif @view_opts[:title]
33
+ op << info[1]
34
+ end
35
+ else
36
+ op << 'None'
37
+ end
38
+ end
39
+
40
+ op << buttons if @view_opts[:buttons]
41
+
42
+ @output = op.join(' ')
43
+
44
+ end
45
+
46
+ def running?
47
+ `pgrep rhythmbox`.chomp.length != 0
48
+ end
49
+
50
+ def buttons
51
+ [
52
+ "%{A:rhythmbox-client --previous:}\uf048%{A}",
53
+ "%{A:rhythmbox-client --play-pause:}\uf04b%{A}",
54
+ "%{A:rhythmbox-client --next:}\uf051%{A}"
55
+ ].join(' ').freeze
56
+ end
57
+
58
+ private
59
+
60
+ def sys_cmd
61
+ `rhythmbox-client --print-playing`.chomp
62
+ end
63
+ end
64
+ end
65
+ end
@@ -1,26 +1,35 @@
1
1
  # coding: utf-8
2
+ require 'weather-api'
3
+ require 'barr/block'
4
+
2
5
  module Barr
3
6
  module Blocks
4
7
  class Temperature < Block
5
- attr_reader :location, :unit
6
8
 
7
- def initialize opts={}
9
+ attr_reader :location
10
+
11
+ def initialize(opts = {})
8
12
  super
13
+
9
14
  @location = opts[:location]
10
- @unit = opts[:unit] || "C"
15
+ @unit = opts[:unit] || 'C'
11
16
  end
12
17
 
13
- def update
14
- res = weather_data
15
- temp = (@unit == 'C' ? ((res.condition.temp.to_i-32)*(5/9.0)).round : res.condition.temp)
16
- action = "xdg-open weather.yahoo.com\/country\/state\/city-#{@location}\/".chomp
17
- @output = "%{A:#{action}:}#{temp}°#{@unit} #{res.condition.text}%{A}"
18
+ def update!
19
+ action = "xdg-open weather.yahoo.com\/country\/state\/city-#{@location}\/"
20
+ @output = "%{A:#{action}:}#{weather.condition.temp}°#{@unit} #{weather.condition.text}%{A}"
18
21
  end
19
22
 
20
- def weather_data
21
- Weather.lookup(@location, Weather::Units::FAHRENHEIT)
23
+ private
24
+
25
+ def weather
26
+ Weather.lookup(@location, weather_units)
22
27
  end
23
-
28
+
29
+ def weather_units
30
+ @unit == 'F' ? Weather::Units::FAHRENHEIT : Weather::Units::CELSIUS
31
+ end
32
+
24
33
  end
25
34
  end
26
35
  end
@@ -0,0 +1,25 @@
1
+ require 'barr/block'
2
+
3
+ module Barr
4
+ module Blocks
5
+ class Whoami < Block
6
+
7
+ def initialize(opts = {})
8
+ super
9
+ end
10
+
11
+ def update!
12
+ @output = sys_cmd
13
+ end
14
+
15
+ private
16
+
17
+ def sys_cmd
18
+ `whoami`.chomp
19
+ end
20
+
21
+ end
22
+
23
+ WhoAmI = Whoami
24
+ end
25
+ end
@@ -1,63 +1,76 @@
1
+ require 'barr/block'
2
+
1
3
  module Barr
2
4
  class Manager
5
+
6
+ ERROR_ICON = "%{F#FF0000}\uf071%{F-}"
7
+
3
8
  attr_reader :count, :blocks
4
- ERROR_ICON = "%{F#FF0000}\uf071"
9
+
5
10
  def initialize
6
11
  @count = 0
7
12
  @blocks = []
8
13
  end
9
14
 
10
- def update
11
- # STDERR.puts "update"
12
- @blocks.each do |block|
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
20
- end
21
- @count += 1
15
+ def add(block)
16
+ @blocks << block
17
+ end
18
+
19
+ def destroy!
20
+ @blocks.each(&:destroy!)
22
21
  end
23
22
 
24
23
  def draw
25
- # STDERR.puts "draw"
26
- outputs = { l: [], c: [], r: []}
24
+ outputs = { l: [], c: [], r: [] }
27
25
 
28
26
  @blocks.each do |block|
29
- outputs[block.align] << block.draw
27
+ outputs[block.align] << block.draw
30
28
  end
31
29
 
32
- opl = outputs[:l].join(" ")
33
- opc = outputs[:c].join(" ")
34
- opr = outputs[:r].join(" ")
35
-
36
- bar_render = ""
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","")
30
+ left_blocks = outputs[:l].join ''
31
+ centre_blocks = outputs[:c].join ''
32
+ right_blocks = outputs[:r].join ''
41
33
 
42
- system("echo", "-e", bar_render.encode("UTF-8"))
43
- # STDERR.puts bar_render
44
- end
34
+ bar_render = ''
35
+ bar_render << "%{l}#{left_blocks} " if left_blocks.length > 0
36
+ bar_render << "%{c} #{centre_blocks} " if centre_blocks.length > 0
37
+ bar_render << "%{r} #{right_blocks}" if right_blocks.length > 0
45
38
 
46
- def destroy
47
- @blocks.each(&:destroy)
48
- end
39
+ bar_render.gsub! "\n", ''
49
40
 
50
- def add_block block
51
- @blocks << block
41
+ system('echo', '-e', bar_render.encode('UTF-8'))
52
42
  end
53
43
 
54
- def run
44
+ def run!
55
45
  while true
56
- # STDERR.puts "hello?"
57
- self.update
46
+ self.update!
58
47
  self.draw
59
48
  sleep 1
60
49
  end
61
50
  end
51
+
52
+ def update!
53
+ @blocks.each do |block|
54
+ begin
55
+ block.update! if @count == 0 || (@count % block.interval == 0)
56
+ rescue StandardError => e
57
+ STDERR.puts e.message
58
+ block << ERROR_ICON unless block.output.include?(ERROR_ICON)
59
+ next
60
+ end
61
+ end
62
+
63
+ @count += 1
64
+ end
65
+
66
+ # compatibility methods.
67
+ # alias_method would work here, but for consistency with Block
68
+ # I'll define them this way
69
+
70
+ def update; update!; end
71
+ def run; run!; end
72
+ def destroy; destroy!; end
73
+ def add_block(block); add(block); end
74
+
62
75
  end
63
76
  end
@@ -1,3 +1,3 @@
1
1
  module Barr
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
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.1.2
4
+ version: 0.2.0
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-27 00:00:00.000000000 Z
11
+ date: 2016-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: timecop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: i3ipc
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -118,9 +132,9 @@ files:
118
132
  - lib/barr/blocks/i3.rb
119
133
  - lib/barr/blocks/ip.rb
120
134
  - lib/barr/blocks/mem.rb
121
- - lib/barr/blocks/rhythm_box.rb
135
+ - lib/barr/blocks/rhythmbox.rb
122
136
  - lib/barr/blocks/temperature.rb
123
- - lib/barr/blocks/who_am_i.rb
137
+ - lib/barr/blocks/whoami.rb
124
138
  - lib/barr/manager.rb
125
139
  - lib/barr/version.rb
126
140
  homepage: https://github.com/OkayDave/barr
@@ -150,5 +164,5 @@ rubyforge_project:
150
164
  rubygems_version: 2.4.8
151
165
  signing_key:
152
166
  specification_version: 4
153
- summary: Barr is a status line generate for use with Lemonbar
167
+ summary: Barr is a status line generator for use with Lemonbar
154
168
  test_files: []