barr 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,65 +5,60 @@ require 'barr'
5
5
 
6
6
  @man = Barr::Manager.new
7
7
 
8
+ who = Barr::Blocks::Whoami.new align: :r, icon: "\uf007"
8
9
 
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: [">","<"],
10
+ i3 = Barr::Blocks::I3.new(fgcolor: '#FFF',
11
+ bgcolor: '#145266',
12
+ focus_markers: %w(> <),
15
13
  align: :r,
16
- icon: "\uf009"
14
+ icon: "\uf009")
17
15
 
18
- artist = Barr::Blocks::Rhythmbox.new bcolor: "#466B41",
16
+ artist = Barr::Blocks::Rhythmbox.new(bgcolor: '#466B41',
19
17
  icon: "\uf028",
20
- show_title: false,
21
- show_buttons: false
18
+ title: false,
19
+ buttons: false)
22
20
 
23
- song = Barr::Blocks::Rhythmbox.new bcolor: "#1E6614",
24
- show_buttons: false,
25
- show_artist: false
21
+ song = Barr::Blocks::Rhythmbox.new(bgcolor: '#1E6614',
22
+ buttons: false,
23
+ artist: false)
26
24
 
27
- controls = Barr::Blocks::Rhythmbox.new bcolor: "#0A4D02",
28
- show_artist: false,
29
- show_title: false,
30
- align: :r
25
+ controls = Barr::Blocks::Rhythmbox.new(bgcolor: '#0A4D02',
26
+ artist: false,
27
+ title: false,
28
+ align: :r)
31
29
 
32
- clock = Barr::Blocks::Clock.new bcolor: "#371E5E",
33
- format: "%H:%M - %d %b %Y",
30
+ clock = Barr::Blocks::Clock.new(bgcolor: '#371E5E',
31
+ format: '%H:%M - %d %b %Y',
34
32
  icon: "\uf073",
35
- align: :r
33
+ align: :r)
36
34
 
37
- weather = Barr::Blocks::Temperature.new bcolor: "#4A072B",
38
- align: :l,
39
- location: "2471217",
40
- icon: "\uf0c2 Philadelphia: ",
41
- interval: 1500
35
+ weather = Barr::Blocks::Temperature.new(bgcolor: '#4A072B',
36
+ align: :l,
37
+ location: '2471217',
38
+ icon: "\uf0c2 Philadelphia: ",
39
+ interval: 1500)
42
40
 
43
- cpu = Barr::Blocks::Cpu.new icon: "\uf1fe"
41
+ cpu = Barr::Blocks::CPU.new icon: "\uf1fe"
44
42
 
45
- mem = Barr::Blocks::Mem.new bcolor: "#333333"
43
+ mem = Barr::Blocks::Mem.new bgcolor: '#333333'
46
44
 
47
- hdd = Barr::Blocks::Hdd.new bcolor: "#444444", device: "sda2", interval: 300
45
+ hdd = Barr::Blocks::HDD.new bgcolor: '#444444', device: 'sdc2', interval: 300
48
46
 
49
- local = Barr::Blocks::Ip.new bcolor: "#937739", align: :r, icon: "\uf1ce"
47
+ local = Barr::Blocks::IP.new bgcolor: '#937739', align: :r, icon: "\uf1ce"
50
48
 
51
49
  # 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
-
50
+ @man.add artist
51
+ @man.add song
52
+ @man.add weather
53
+ @man.add cpu
54
+ @man.add mem
55
+ @man.add hdd
59
56
 
60
57
  # 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
-
58
+ @man.add i3
59
+ @man.add local
60
+ @man.add who
61
+ @man.add controls
62
+ @man.add clock
68
63
 
69
- @man.run
64
+ @man.run!
@@ -8,25 +8,25 @@ require 'barr'
8
8
  # The manager is responsible for organising the blocks and delivering their output to lemonbar
9
9
  @manager = Barr::Manager.new
10
10
 
11
- # Add a 'WhoAmI' block. This just outputs logged in username
11
+ # Add a 'Whoami' block. This just outputs logged in username
12
12
  # Give it a peach background, grey text and updates every 10000 seconds
13
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)
14
+ @manager.add Barr::Blocks::Whoami.new(bgcolor: '#FFAAAA', fgcolor: '#333333', interval: 10000)
15
15
 
16
16
  # Add a 'Clock' block.
17
17
  # Clocks can be formatted in the type strftime fashion. This example outputs the current Hour and Minute
18
18
  # It will update every second.
19
19
  # By default, the background text colour will be deferred to the Lemonbar config
20
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)
21
+ @manager.add Barr::Blocks::Clock.new(icon: "\uf017", format: '%H:%M', align: :c, interval: 1)
22
22
 
23
23
 
24
- # Add a 'Cpu' block. This shows the current CPU usage (averaged across all cores if present)
24
+ # Add a 'CPU' block. This shows the current CPU usage (averaged across all cores if present)
25
25
  # It will be aligned to the right side of of the bar
26
26
  # As an interval is not provided, it will update every 5 seconds.
27
27
  # It will be prepended with the text 'Cpu:'
28
- @manager.add_block Barr::Blocks::Cpu.new(icon: "Cpu:", align: :r)
28
+ @manager.add Barr::Blocks::CPU.new(icon: 'Cpu:', align: :r)
29
29
 
30
30
 
31
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
32
+ @manager.run!
@@ -4,34 +4,33 @@ require 'rubygems'
4
4
  require 'barr'
5
5
 
6
6
  class FizzBuzz < Barr::Block
7
- def initialize opts={}
7
+ def initialize(opts = {})
8
8
  super
9
9
  @count = opts[:count] || 0
10
10
  end
11
11
 
12
- def update
12
+ def update!
13
13
  @count += 1
14
14
 
15
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
16
+ 'FizzBuzz'
17
+ elsif @count % 3 == 0
18
+ 'Fizz'
19
+ elsif @count % 5 == 0
20
+ 'Buzz'
21
+ else
22
+ @count.to_s
23
+ end
25
24
  end
26
25
  end
27
26
 
28
27
 
29
28
  clock = Barr::Blocks::Clock.new align: :r
30
- counter = FizzBuzz.new align: :l, bcolor: "#8CB8FF", fcolor: "#333333", icon: "\uf1ec", interval: 1
29
+ counter = FizzBuzz.new align: :l, bgcolor: '#8CB8FF', fgcolor: '#333333', icon: "\uf1ec", interval: 1
31
30
 
32
31
  @man = Barr::Manager.new
33
32
 
34
- @man.add_block clock
35
- @man.add_block counter
33
+ @man.add clock
34
+ @man.add counter
36
35
 
37
- @man.run
36
+ @man.run!
@@ -5,14 +5,17 @@ require 'barr'
5
5
 
6
6
  @man = Barr::Manager.new
7
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"
8
+ i3 = Barr::Blocks::I3.new icon: "\uf108", bgcolor: '#114152', fgcolor: '#DAC1DE', align: :l, focus_markers: ["\uf0a4",'']
12
9
 
13
- @man.add_block i3
14
- @man.add_block cpu
15
- @man.add_block mem
16
- @man.add_block disk
10
+ cpu = Barr::Blocks::CPU.new icon: "\uf108 CPU:", bgcolor: '#491A5E', align: :r
17
11
 
18
- @man.run
12
+ mem = Barr::Blocks::Mem.new icon: 'RAM:', align: :r, bgcolor: '#2F113D'
13
+
14
+ disk = Barr::Blocks::HDD.new icon: 'SSD:', align: :r, bgcolor: '#380B4D', device: 'sda2'
15
+
16
+ @man.add i3
17
+ @man.add cpu
18
+ @man.add mem
19
+ @man.add disk
20
+
21
+ @man.run!
@@ -5,15 +5,14 @@ require 'barr'
5
5
 
6
6
  @man = Barr::Manager.new
7
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
8
+ artist = Barr::Blocks::Rhythmbox.new align: :l, title: false, buttons: false, bgcolor: '#266623', icon: "\uf028"
11
9
 
10
+ title = Barr::Blocks::Rhythmbox.new align: :l, artist: false, buttons: false, bgcolor: '#0D450A'
12
11
 
12
+ btns = Barr::Blocks::Rhythmbox.new align: :r, artist: false, title: false, bgcolor: '#033B00', interval: 10000
13
13
 
14
- @man.add_block artist
15
- @man.add_block title
16
- @man.add_block btns
17
-
18
- @man.run
14
+ @man.add artist
15
+ @man.add title
16
+ @man.add btns
19
17
 
18
+ @man.run!
@@ -5,10 +5,10 @@ require 'barr'
5
5
 
6
6
  @man = Barr::Manager.new
7
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"
8
+ time = Barr::Blocks::Clock.new format: '%H:%M', icon: "\uf017", bgcolor: '#114152', fgcolor: '#DAC1DE', align: :l
9
+ date = Barr::Blocks::Clock.new format: '%m of %b %Y', bgcolor: '#570B7A', fgcolor: '#FFFFFF', align: :r, icon: "\uf073"
10
10
 
11
- @man.add_block time
12
- @man.add_block date
11
+ @man.add time
12
+ @man.add date
13
13
 
14
- @man.run
14
+ @man.run!
@@ -5,20 +5,20 @@ require 'barr'
5
5
 
6
6
  @man = Barr::Manager.new
7
7
 
8
- nyc = Barr::Blocks::Temperature.new bcolor: "#42C7AA",
9
- fcolor: "#FFF",
10
- icon: "New York: ",
11
- location: "2459115",
8
+ nyc = Barr::Blocks::Temperature.new bgcolor: '#42C7AA',
9
+ fgcolor: '#FFF',
10
+ icon: 'New York: ',
11
+ location: '2459115',
12
12
  interval: 1800
13
13
 
14
- sanfran = Barr::Blocks::Temperature.new bcolor: "#92A084",
15
- fcolor: "#FFF",
16
- icon: "San Francisco: ",
17
- location: "2487956",
14
+ sanfran = Barr::Blocks::Temperature.new bgcolor: '#92A084',
15
+ fgcolor: '#FFF',
16
+ icon: 'San Francisco: ',
17
+ location: '2487956',
18
18
  align: :r,
19
19
  interval: 1800
20
20
 
21
- @man.add_block nyc
22
- @man.add_block sanfran
21
+ @man.add nyc
22
+ @man.add sanfran
23
23
 
24
- @man.run
24
+ @man.run!
@@ -8,25 +8,25 @@ require 'barr'
8
8
  # The manager is responsible for organising the blocks and delivering their output to lemonbar
9
9
  @manager = Barr::Manager.new
10
10
 
11
- # Add a 'WhoAmI' block. This just outputs logged in username
11
+ # Add a 'Whoami' block. This just outputs logged in username
12
12
  # Give it a peach background, grey text and updates every 10000 seconds
13
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)
14
+ @manager.add_block Barr::Blocks::Whoami.new(bcolor: '#FFAAAA', fcolor: '#333333', interval: 10000)
15
15
 
16
16
  # Add a 'Clock' block.
17
17
  # Clocks can be formatted in the type strftime fashion. This example outputs the current Hour and Minute
18
18
  # It will update every second.
19
19
  # By default, the background text colour will be deferred to the Lemonbar config
20
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)
21
+ @manager.add_block Barr::Blocks::Clock.new(icon: "\uf017", format: '%H:%M', align: :c, interval: 1)
22
22
 
23
23
 
24
- # Add a 'Cpu' block. This shows the current CPU usage (averaged across all cores if present)
24
+ # Add a 'CPU' block. This shows the current CPU usage (averaged across all cores if present)
25
25
  # It will be aligned to the right side of of the bar
26
26
  # As an interval is not provided, it will update every 5 seconds.
27
27
  # It will be prepended with the text 'Cpu:'
28
- @manager.add_block Barr::Blocks::Cpu.new(icon: "Cpu:", align: :r)
28
+ @manager.add_block Barr::Blocks::CPU.new(icon: 'Cpu:', align: :r)
29
29
 
30
30
 
31
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
32
+ @manager.run!
@@ -4,6 +4,6 @@ require 'rubygems'
4
4
  require 'i3ipc'
5
5
 
6
6
  @i3 = I3Ipc::Connection.new
7
- cmd = ARGV.join(" ")
7
+ cmd = ARGV.join(' ')
8
8
  @i3.command(cmd)
9
9
  @i3.close
@@ -1,13 +1,16 @@
1
- require "barr/version"
2
- require "barr/manager"
3
- require "barr/block"
1
+ require 'barr/version'
2
+ require 'barr/manager'
3
+ require 'barr/block'
4
4
 
5
- require 'weather-api'
6
- require 'i3ipc'
7
-
8
- Dir[File.dirname(__FILE__) + '/barr/blocks/*.rb'].each do |file|
9
- require file
10
- end
5
+ require 'barr/blocks/clock'
6
+ require 'barr/blocks/cpu'
7
+ require 'barr/blocks/hdd'
8
+ require 'barr/blocks/i3'
9
+ require 'barr/blocks/ip'
10
+ require 'barr/blocks/mem'
11
+ require 'barr/blocks/rhythmbox'
12
+ require 'barr/blocks/temperature'
13
+ require 'barr/blocks/whoami'
11
14
 
12
15
  module Barr
13
16
  end
@@ -1,30 +1,55 @@
1
1
  module Barr
2
- class Block
3
- attr_reader :output, :align, :fcolor, :bcolor, :interval, :icon
2
+ class Block
3
+ attr_reader :align, :bgcolor, :fgcolor, :icon, :interval, :output
4
+
5
+ def initialize(opts = {})
6
+ reassign_deprecated_option opts, :fcolor, :fgcolor
7
+ reassign_deprecated_option opts, :bcolor, :bgcolor
8
+ @align = opts[:align] || :l
9
+ @bgcolor = opts[:bgcolor] || '-'
10
+ @fgcolor = opts[:fgcolor] || '-'
11
+ @icon = opts[:icon] || ''
12
+ @interval = opts[:interval] || 5
13
+
14
+ @output = ''
15
+ end
16
+
17
+ def <<(str)
18
+ @output << str
19
+ end
20
+
21
+ def colors
22
+ "%{B#{bgcolor}}%{F#{fgcolor}}"
23
+ end
24
+
25
+ def draw
26
+ "#{colors} #{icon} #{@output} #{reset_colors}"
27
+ end
28
+
29
+ def destroy!
30
+ end
31
+
32
+ def update!
33
+ end
34
+
35
+ # Backwards compatiblity methods.
36
+ # can't use alias/alias_method as they don't
37
+ # trickle down to subclasses
38
+ def update; update!; end
39
+ def destroy; destroy!; end
4
40
 
41
+ def reassign_deprecated_option opts, old, new
42
+ 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."
44
+ opts[new] = opts[old]
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def reset_colors
51
+ '%{F-}%{B-}'
52
+ end
5
53
 
6
- def align; @align; end
7
- def fcolor; @fcolor; end
8
- def bcolor; @bcolor; end
9
- def color_out; "%{B#{bcolor}}%{F#{fcolor}}"; end
10
- def interval; @interval; end
11
- def icon; @icon; end
12
-
13
- def update; @update = ""; end
14
- def draw; "#{color_out} #{icon} #{@output} "; end
15
- def destroy; true; end
16
-
17
- def initialize(opts={})
18
- @align = opts[:align] || :l
19
- @fcolor = opts[:fcolor] || "-"
20
- @bcolor = opts[:bcolor] || "-"
21
- @interval = opts[:interval] || 5
22
- @icon = opts[:icon] || ""
23
- @output = ""
24
- end
25
-
26
- def append_output str
27
- @output += str
28
- end
29
- end
54
+ end
30
55
  end
@@ -1,16 +1,18 @@
1
+ require 'barr/block'
2
+
1
3
  module Barr
2
4
  module Blocks
3
5
  class Clock < Block
4
- attr_reader :format
5
6
 
6
- def initialize opts={}
7
+ def initialize(opts = {})
7
8
  super
8
- @format = opts[:format] || "%H:%M %m %b %Y"
9
+ @format = opts[:format] || '%H:%M %d %b %Y'
9
10
  end
10
11
 
11
- def update
12
+ def update!
12
13
  @output = Time.now.strftime(@format)
13
14
  end
15
+
14
16
  end
15
17
  end
16
18
  end