r3status 0.1.0 → 0.1.1
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/lib/r3status.rb +16 -5
- data/lib/r3status/async_block.rb +24 -0
- data/lib/r3status/block.rb +12 -3
- data/lib/r3status/blocks.rb +4 -0
- data/lib/r3status/shell_block.rb +32 -0
- data/lib/r3status/static_block.rb +8 -3
- data/lib/r3status/time_block.rb +4 -5
- data/lib/r3status/volume_block.rb +5 -5
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c2c2e2a5985350fdd7009f16224f8d0ce2aa225
|
4
|
+
data.tar.gz: cdfe3f6a14611a3159ff9c362809e77fe62e224c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6671a6a365fff74396378124de0da333ecf9bec77a1f78fed5fdf54bbf3e70ac79a2662d211814d31eb83ef34f3943d69dff37e5d3e6e25dd4d9d939bea149e3
|
7
|
+
data.tar.gz: 6ee838c35dd8b83b2900eff0cdd522d1a9e3cb239e4e389869978459c643840abb0afee8ae2dd01379d47c5fad2a755386658fa1acef1ca530109a337a2a27c4
|
data/lib/r3status.rb
CHANGED
@@ -2,6 +2,7 @@ require_relative './r3status/blocks.rb'
|
|
2
2
|
require 'json'
|
3
3
|
|
4
4
|
module R3Status
|
5
|
+
|
5
6
|
def loop_with_interval secs
|
6
7
|
loop do
|
7
8
|
start = Time.now
|
@@ -29,28 +30,37 @@ module R3Status
|
|
29
30
|
@blocks.map { |i| i.to_s(postfix: @postfix, prefix: @prefix) }.
|
30
31
|
reject { |i| i.nil? }.inject { |i, j| i << ",#{j}"}
|
31
32
|
end
|
33
|
+
|
32
34
|
def parse str
|
33
35
|
return if str.length < 2
|
34
36
|
obj = nil
|
37
|
+
str = str.strip.sub(/\A\,/ , "")
|
35
38
|
|
36
|
-
str = str.sub(/\A\,/ , "")
|
37
|
-
File.open("input.txt", 'a') {|f| f.puts str }
|
38
39
|
begin
|
39
40
|
obj = JSON.parse(str)
|
40
41
|
rescue Exception => e
|
41
|
-
File.open("log.txt", 'a') {|f| f.puts e.to_s }
|
42
42
|
return
|
43
43
|
end
|
44
|
+
|
44
45
|
block = @blocks.find { |b| b.name == obj["name"] }
|
45
46
|
block.clicked(obj["button"], obj["x"], obj["y"]) unless block.nil?
|
46
47
|
end
|
47
|
-
def run
|
48
48
|
|
49
|
-
|
49
|
+
def run
|
50
|
+
@reader_thread = Thread.new do
|
51
|
+
begin
|
50
52
|
loop do
|
51
53
|
s = gets.chomp
|
52
54
|
parse s
|
53
55
|
end
|
56
|
+
rescue Exception => e
|
57
|
+
File.open("log.txt", 'a') {|f| f.puts e.backtrace }
|
58
|
+
end
|
59
|
+
end.run
|
60
|
+
|
61
|
+
at_exit do
|
62
|
+
@reader_thread.kill
|
63
|
+
@blocks.each { |b| b.terminate }
|
54
64
|
end
|
55
65
|
|
56
66
|
puts "{\"version\":1, \"click_events\":true}["
|
@@ -58,6 +68,7 @@ module R3Status
|
|
58
68
|
@blocks.each {|b| b.update }
|
59
69
|
puts "[#{transmission}],"
|
60
70
|
end
|
71
|
+
|
61
72
|
end
|
62
73
|
end
|
63
74
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module R3Status
|
2
|
+
class AsyncBlock < Block
|
3
|
+
attr_accessor :update_interval, :updater_thread
|
4
|
+
|
5
|
+
def initialize(**args)
|
6
|
+
args = {update_interval: 3}.merge(args)
|
7
|
+
super(args)
|
8
|
+
end
|
9
|
+
|
10
|
+
def update
|
11
|
+
@full_text
|
12
|
+
return if @updater_pid.is_a? Fixnum
|
13
|
+
@updater_thread = Thread.new do
|
14
|
+
loop_with_interval(update_interval) { async_update }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def terminate
|
19
|
+
@updater_thread.kill
|
20
|
+
end
|
21
|
+
|
22
|
+
def async_update; end
|
23
|
+
end
|
24
|
+
end
|
data/lib/r3status/block.rb
CHANGED
@@ -6,16 +6,18 @@ module R3Status
|
|
6
6
|
attr_accessor :full_text, :text_color, :name, :formats, :colors
|
7
7
|
|
8
8
|
def initialize(**args)
|
9
|
+
self.colors ||= {}
|
10
|
+
self.formats ||= Hash.new(DEFAULT_FORMAT)
|
9
11
|
args.each do |k, v|
|
10
12
|
v.default = v[:default] if (v.is_a? Hash) && (v.key? :default)
|
11
13
|
send "#{k}=", v
|
12
14
|
end
|
13
|
-
|
14
|
-
self.colors ||= {}
|
15
|
-
self.formats ||= Hash.new(DEFAULT_FORMAT)
|
16
15
|
end
|
17
16
|
|
18
17
|
def update; end
|
18
|
+
|
19
|
+
def terminate; end
|
20
|
+
|
19
21
|
def clicked(button, x, y); end
|
20
22
|
|
21
23
|
def to_s(prefix: nil, postfix: nil)
|
@@ -24,5 +26,12 @@ module R3Status
|
|
24
26
|
"separator": false})
|
25
27
|
end
|
26
28
|
|
29
|
+
def format
|
30
|
+
formats.default
|
31
|
+
end
|
32
|
+
|
33
|
+
def format=(fmt)
|
34
|
+
@formats.default = fmt
|
35
|
+
end
|
27
36
|
end
|
28
37
|
end
|
data/lib/r3status/blocks.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
module R3Status
|
2
|
+
class ShellBlock < StaticBlock
|
3
|
+
attr_accessor :command, :click_commands
|
4
|
+
|
5
|
+
def initialize(**args, &block)
|
6
|
+
super(args, &block)
|
7
|
+
end
|
8
|
+
|
9
|
+
def update
|
10
|
+
return if command.nil?
|
11
|
+
|
12
|
+
cmd = `#{command}`.split.map {|str| str.chomp}
|
13
|
+
return if cmd.length == 0
|
14
|
+
|
15
|
+
@full_text = cmd[0]
|
16
|
+
@text_color = cmd[1] if cmd.length >= 2
|
17
|
+
end
|
18
|
+
|
19
|
+
def clicked(button, x, y)
|
20
|
+
super(button, x, y)
|
21
|
+
|
22
|
+
case click_commands.class
|
23
|
+
when String
|
24
|
+
`#{click_commands}`
|
25
|
+
when Array
|
26
|
+
`#{click_commands[button - 1]}`
|
27
|
+
when Hash
|
28
|
+
`#{click_commands[button]}`
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
1
3
|
module R3Status
|
2
4
|
class StaticBlock < Block
|
3
5
|
attr_accessor :clicked_block
|
@@ -6,12 +8,15 @@ module R3Status
|
|
6
8
|
@clicked_block = block
|
7
9
|
|
8
10
|
super(args)
|
11
|
+
|
12
|
+
@full_text ||= format
|
13
|
+
@name ||= SecureRandom.uuid
|
9
14
|
end
|
10
15
|
|
11
16
|
def clicked(button, x, y)
|
12
|
-
return if clicked_block.nil?
|
13
|
-
args = [self, button, x, y].take(clicked_block.arity)
|
14
|
-
clicked_block.
|
17
|
+
return if @clicked_block.nil?
|
18
|
+
args = [self, button, x, y].take(@clicked_block.arity)
|
19
|
+
@clicked_block.(*args)
|
15
20
|
end
|
16
21
|
end
|
17
22
|
end
|
data/lib/r3status/time_block.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
module R3Status
|
2
2
|
class TimeBlock < Block
|
3
|
-
attr_accessor :format
|
4
3
|
|
5
|
-
def initialize(
|
6
|
-
|
7
|
-
|
8
|
-
super()
|
4
|
+
def initialize(**args)
|
5
|
+
args = {format: "%H:%m @ %e/%M/%Y"}.merge(args)
|
6
|
+
super(args)
|
9
7
|
end
|
8
|
+
|
10
9
|
def update
|
11
10
|
self.full_text = Time.now.strftime(format)
|
12
11
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module R3Status
|
2
2
|
class VolumeBlock < Block
|
3
|
-
attr_accessor :
|
3
|
+
attr_accessor :step
|
4
4
|
|
5
5
|
def initialize(**args)
|
6
6
|
args = {formats: {muted: " %{volume}%", unmuted: " %{volume}%"},
|
@@ -19,11 +19,11 @@ module R3Status
|
|
19
19
|
|
20
20
|
def clicked button, x, y
|
21
21
|
case button
|
22
|
-
when
|
22
|
+
when 4
|
23
23
|
increase
|
24
24
|
when 2
|
25
25
|
toggle_mute
|
26
|
-
when
|
26
|
+
when 5
|
27
27
|
decrease
|
28
28
|
end
|
29
29
|
end
|
@@ -33,10 +33,10 @@ module R3Status
|
|
33
33
|
`amixer -q set Master toggle`
|
34
34
|
end
|
35
35
|
def increase
|
36
|
-
`amixer -c 0 set Master #{step}
|
36
|
+
`amixer -c 0 set Master #{step}%+ unmute`
|
37
37
|
end
|
38
38
|
def decrease
|
39
|
-
`amixer -c 0 set Master #{step}
|
39
|
+
`amixer -c 0 set Master #{step}%- unmute`
|
40
40
|
end
|
41
41
|
def volume
|
42
42
|
`amixer -c 0 get Master | grep Mono: | cut -d " " -f6 | tr -d [,],%`.to_i
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r3status
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gilad Naaman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: r3status is ruby implmentation of the i3bar protocol, and is an alternative
|
14
14
|
to the default i3status.
|
@@ -18,14 +18,16 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- lib/r3status.rb
|
21
|
+
- lib/r3status/async_block.rb
|
21
22
|
- lib/r3status/battery_block.rb
|
22
23
|
- lib/r3status/block.rb
|
23
24
|
- lib/r3status/blocks.rb
|
24
25
|
- lib/r3status/keyboard_layout_block.rb
|
26
|
+
- lib/r3status/shell_block.rb
|
25
27
|
- lib/r3status/static_block.rb
|
26
28
|
- lib/r3status/time_block.rb
|
27
29
|
- lib/r3status/volume_block.rb
|
28
|
-
homepage: https://
|
30
|
+
homepage: https://github.com/Gilnaa/R3Status
|
29
31
|
licenses:
|
30
32
|
- LGPL3
|
31
33
|
metadata: {}
|