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.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/README.md +122 -123
- data/barr.gemspec +2 -1
- data/examples/README.md +0 -2
- data/examples/all_in.rb +39 -44
- data/examples/barr_example.rb +6 -6
- data/examples/fizzbuzz.rb +14 -15
- data/examples/i3_cpu_mem.rb +12 -9
- data/examples/rhythm.rb +7 -8
- data/examples/time_and_date.rb +5 -5
- data/examples/two_temperatures.rb +11 -11
- data/exe/barr_example +6 -6
- data/exe/barr_i3ipc +1 -1
- data/lib/barr.rb +12 -9
- data/lib/barr/block.rb +51 -26
- data/lib/barr/blocks/clock.rb +6 -4
- data/lib/barr/blocks/cpu.rb +17 -3
- data/lib/barr/blocks/hdd.rb +15 -7
- data/lib/barr/blocks/i3.rb +15 -6
- data/lib/barr/blocks/ip.rb +16 -11
- data/lib/barr/blocks/mem.rb +7 -3
- data/lib/barr/blocks/rhythmbox.rb +65 -0
- data/lib/barr/blocks/temperature.rb +20 -11
- data/lib/barr/blocks/whoami.rb +25 -0
- data/lib/barr/manager.rb +49 -36
- data/lib/barr/version.rb +1 -1
- metadata +19 -5
- data/lib/barr/blocks/rhythm_box.rb +0 -55
- data/lib/barr/blocks/who_am_i.rb +0 -15
data/examples/all_in.rb
CHANGED
@@ -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
|
-
|
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
|
16
|
+
artist = Barr::Blocks::Rhythmbox.new(bgcolor: '#466B41',
|
19
17
|
icon: "\uf028",
|
20
|
-
|
21
|
-
|
18
|
+
title: false,
|
19
|
+
buttons: false)
|
22
20
|
|
23
|
-
song = Barr::Blocks::Rhythmbox.new
|
24
|
-
|
25
|
-
|
21
|
+
song = Barr::Blocks::Rhythmbox.new(bgcolor: '#1E6614',
|
22
|
+
buttons: false,
|
23
|
+
artist: false)
|
26
24
|
|
27
|
-
controls = Barr::Blocks::Rhythmbox.new
|
28
|
-
|
29
|
-
|
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
|
33
|
-
format:
|
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
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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::
|
41
|
+
cpu = Barr::Blocks::CPU.new icon: "\uf1fe"
|
44
42
|
|
45
|
-
mem = Barr::Blocks::Mem.new
|
43
|
+
mem = Barr::Blocks::Mem.new bgcolor: '#333333'
|
46
44
|
|
47
|
-
hdd = Barr::Blocks::
|
45
|
+
hdd = Barr::Blocks::HDD.new bgcolor: '#444444', device: 'sdc2', interval: 300
|
48
46
|
|
49
|
-
local = Barr::Blocks::
|
47
|
+
local = Barr::Blocks::IP.new bgcolor: '#937739', align: :r, icon: "\uf1ce"
|
50
48
|
|
51
49
|
# Left
|
52
|
-
@man.
|
53
|
-
@man.
|
54
|
-
@man.
|
55
|
-
@man.
|
56
|
-
@man.
|
57
|
-
@man.
|
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.
|
62
|
-
@man.
|
63
|
-
@man.
|
64
|
-
@man.
|
65
|
-
@man.
|
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!
|
data/examples/barr_example.rb
CHANGED
@@ -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 '
|
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.
|
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.
|
21
|
+
@manager.add Barr::Blocks::Clock.new(icon: "\uf017", format: '%H:%M', align: :c, interval: 1)
|
22
22
|
|
23
23
|
|
24
|
-
# Add a '
|
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.
|
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!
|
data/examples/fizzbuzz.rb
CHANGED
@@ -4,34 +4,33 @@ require 'rubygems'
|
|
4
4
|
require 'barr'
|
5
5
|
|
6
6
|
class FizzBuzz < Barr::Block
|
7
|
-
def initialize
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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,
|
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.
|
35
|
-
@man.
|
33
|
+
@man.add clock
|
34
|
+
@man.add counter
|
36
35
|
|
37
|
-
@man.run
|
36
|
+
@man.run!
|
data/examples/i3_cpu_mem.rb
CHANGED
@@ -5,14 +5,17 @@ require 'barr'
|
|
5
5
|
|
6
6
|
@man = Barr::Manager.new
|
7
7
|
|
8
|
-
i3 = Barr::Blocks::I3.new icon: "\uf108",
|
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
|
-
|
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
|
-
|
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!
|
data/examples/rhythm.rb
CHANGED
@@ -5,15 +5,14 @@ require 'barr'
|
|
5
5
|
|
6
6
|
@man = Barr::Manager.new
|
7
7
|
|
8
|
-
artist = Barr::Blocks::Rhythmbox.new align: :l,
|
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.
|
15
|
-
@man.
|
16
|
-
@man.
|
17
|
-
|
18
|
-
@man.run
|
14
|
+
@man.add artist
|
15
|
+
@man.add title
|
16
|
+
@man.add btns
|
19
17
|
|
18
|
+
@man.run!
|
data/examples/time_and_date.rb
CHANGED
@@ -5,10 +5,10 @@ require 'barr'
|
|
5
5
|
|
6
6
|
@man = Barr::Manager.new
|
7
7
|
|
8
|
-
time = Barr::Blocks::Clock.new format:
|
9
|
-
date = Barr::Blocks::Clock.new format:
|
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.
|
12
|
-
@man.
|
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
|
9
|
-
|
10
|
-
icon:
|
11
|
-
location:
|
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
|
15
|
-
|
16
|
-
icon:
|
17
|
-
location:
|
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.
|
22
|
-
@man.
|
21
|
+
@man.add nyc
|
22
|
+
@man.add sanfran
|
23
23
|
|
24
|
-
@man.run
|
24
|
+
@man.run!
|
data/exe/barr_example
CHANGED
@@ -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 '
|
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::
|
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:
|
21
|
+
@manager.add_block Barr::Blocks::Clock.new(icon: "\uf017", format: '%H:%M', align: :c, interval: 1)
|
22
22
|
|
23
23
|
|
24
|
-
# Add a '
|
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::
|
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!
|
data/exe/barr_i3ipc
CHANGED
data/lib/barr.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'barr/version'
|
2
|
+
require 'barr/manager'
|
3
|
+
require 'barr/block'
|
4
4
|
|
5
|
-
require '
|
6
|
-
require '
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
data/lib/barr/block.rb
CHANGED
@@ -1,30 +1,55 @@
|
|
1
1
|
module Barr
|
2
|
-
class Block
|
3
|
-
attr_reader :
|
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
|
-
|
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
|
data/lib/barr/blocks/clock.rb
CHANGED
@@ -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
|
7
|
+
def initialize(opts = {})
|
7
8
|
super
|
8
|
-
@format = opts[:format] ||
|
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
|