r3status 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bafcfeb5316e7a7e409f3a17553495aa16c245ba
4
- data.tar.gz: 23b1bdd423b22a0477455529117a6ff345580a11
3
+ metadata.gz: b8a154a3255e9e8e5cdfe31306e1c98866379c8c
4
+ data.tar.gz: 6c40ceb70d47ed22db148730b9d7b53a0c258fb3
5
5
  SHA512:
6
- metadata.gz: 617319555169430b21f652e533283527b259fad49d806bc11ac2bdf5543efb57187ebf350880640b3abe270aef48586f47208dd9deb0ef77f286de505295eca3
7
- data.tar.gz: f3dc133d86ae42da95eb48d895f2ea1933265262dc561447cf33fb3a7e6939cc0102e182124169fe120dae54d5beccef8e06bd9d9ee1cfa674dc22cb45f66eee
6
+ metadata.gz: 5c120c143b1c4b60b19a061da45cbe5b30661a009882eec58ecf1722b371e03d5fa010cf97f23ea9868859e91a4d45406c5fa9bb8afda6747836c69e2170cf3c
7
+ data.tar.gz: 318fa6bea9e738df75e67c3ba040e8231d107974c9f069c66415e35bc63b17fbdb819de041dcf0ecda0e9f0610efe1565cd208ab1a4eeeff4bfa7891860c8b3c
@@ -74,9 +74,8 @@ module R3Status
74
74
  private
75
75
  # Generates a single transmission.
76
76
  def transmission
77
- @blocks.map { |i| i.to_s(postfix: @postfix, prefix:
78
- @prefix) }.
79
- reject { |i| i.nil? }.inject { |i, j| i << ",#{j}"}
77
+ @blocks.map { |i| i.to_s(postfix: @postfix, prefix: @prefix) }
78
+ .reject(&:nil?).inject { |i, j| i << ",#{j}"}
80
79
  end
81
80
 
82
81
  # Parses a single input from i3bar.
@@ -91,7 +90,14 @@ module R3Status
91
90
  return
92
91
  end
93
92
 
94
- block = @blocks.find { |b| b.name == obj["name"] }
93
+ block = @blocks.map do |b|
94
+ if b.respond_to? :blocks
95
+ b.blocks
96
+ else
97
+ b
98
+ end
99
+ end.flatten.find { |b| b.name == obj["name"] }
100
+
95
101
  block.clicked(obj["button"], obj["x"], obj["y"]) unless block.nil?
96
102
  end
97
103
  end
@@ -14,6 +14,13 @@ require_relative './blocks/shell.rb'
14
14
 
15
15
  require_relative './blocks/async.rb'
16
16
 
17
+ require_relative './blocks/memory.rb'
18
+
19
+ require_relative './blocks/block_group.rb'
20
+
21
+ require_relative './blocks/disk.rb'
22
+
23
+ require_relative './blocks/playerctl.rb'
17
24
  module R3Status
18
25
  # Alias for Blocks::Base
19
26
  Block = Blocks::Base
@@ -14,21 +14,26 @@ module R3Status::Blocks
14
14
  # The default format. Will be used if no format was supplied, or +nil+ was given.
15
15
  DEFAULT_FORMAT = '%{val}'
16
16
 
17
- attr_accessor(
18
- :full_text,
19
- :text_color,
20
- :name,
21
- :formats,
22
- :colors,
23
- :clicked_block
24
- )
17
+ # The maximum length of the block's text. Longer texts will be truncated. Ignored if 0 or lower.
18
+ attr_accessor :max_length
19
+ # The block's current text. Might be overwritten by #update.
20
+ attr_accessor :full_text
21
+ # The block's current text color. Might be overwritten by #update.
22
+ attr_accessor :text_color
23
+ # The name of the block. Used for click handling. Will be assigned automatically if empty.
24
+ attr_accessor :name
25
+ # A hash of formats to be used by the block.
26
+ attr_accessor :formats
27
+ # A hash of colors to be used by the block.
28
+ attr_accessor :colors
29
+ # A proc that will be invoked when the block is clicked.
30
+ attr_accessor :clicked_block
25
31
 
26
32
  # Creates a new instance of this class.
27
33
  # If a block is passed, it will be stored and yielded when the block is clicked.
28
34
  def initialize(**args, &block)
29
- @colors ||= {}
30
- @formats ||= Hash.new(DEFAULT_FORMAT)
31
-
35
+ args = {colors: {}, formats: Hash.new(DEFAULT_FORMAT), max_length: 0}.merge(args)
36
+
32
37
  args.each do |k, v|
33
38
  v.default = v[:default] if (v.is_a? Hash) && (v.key? :default)
34
39
  send "#{k}=", v
@@ -37,6 +42,7 @@ module R3Status::Blocks
37
42
  @clicked_block = block
38
43
  @name ||= SecureRandom.uuid
39
44
  @full_text ||= format
45
+ formats.default ||= DEFAULT_FORMAT
40
46
  end
41
47
 
42
48
  # When implemented in derived classes, updates the text and color of this block.
@@ -47,16 +53,24 @@ module R3Status::Blocks
47
53
  # If a block was supplied to the constructor, it will be yielded.
48
54
  # button (Fixnum):: The mouse button that was used.
49
55
  # x, y (Fixnum / Float):: The pointer coordinates on the screen.
56
+ #
57
+ # Returns true if the click is handled, false otherwise.
50
58
  def clicked(button, x, y)
51
- return if @clicked_block.nil?
59
+ return false if @clicked_block.nil?
52
60
  args = [self, button, x, y].take(@clicked_block.arity)
53
61
  @clicked_block.(*args)
62
+ return true
54
63
  end
55
64
 
56
65
  # Returns the string representation of this block.
57
- # prefix::
58
66
  def to_s(prefix: nil, postfix: nil)
59
- %({"full_text": "#{prefix}#{full_text}#{postfix}",
67
+ txt = if max_length > 0 && full_text.length > max_length
68
+ "#{prefix}#{full_text[0..(max_length - 2)]}…#{postfix}"
69
+ else
70
+ "#{prefix}#{full_text}#{postfix}"
71
+ end
72
+
73
+ %({"full_text": "#{txt}",
60
74
  "color": "#{text_color || DEFAULT_COLOR}", "name": "#{name}",
61
75
  "separator": false})
62
76
  end
@@ -18,6 +18,7 @@ module R3Status::Blocks
18
18
  # Updates the text and color of this block.
19
19
  def update
20
20
  self.full_text = Time.now.strftime(formats[state])
21
+ self.text_color = colors[state]
21
22
  end
22
23
 
23
24
  # Returns the current state of the block
@@ -6,7 +6,7 @@ module R3Status::Blocks
6
6
  # as specified by the system. (e.g. +:us+ for US English, +:ru+ for Russian)
7
7
  #
8
8
  # ==== Format values
9
- # +%{val}+, +%{sym}+: The current language symbol.
9
+ # 8 <tt>%{val}</tt>, <tt>%{sym}</tt>: The current language symbol.
10
10
  class KeyboardLayout < Base
11
11
 
12
12
  # Creates a new instance of this class.
@@ -5,7 +5,7 @@ module R3Status::Blocks
5
5
  # :charging, :discharging, :full, :unknown, :no_battery
6
6
  #
7
7
  # ==== Format Values
8
- # +%{val}+, +%{capacity}+: The current battery capacity.
8
+ # * <tt>%{val}</tt>, <tt>%{capacity}</tt>: The current battery capacity.
9
9
  class Power < Base
10
10
  # The path of the battery on the disk. Examples:
11
11
  # * /sys/class/power_supply/BAT1/
@@ -7,7 +7,7 @@ module R3Status::Blocks
7
7
  # :muted, :unmuted
8
8
  #
9
9
  # ==== Format values
10
- # +%{val}+, +%{volume}+: The current system volume.
10
+ # * <tt>+%{val}</tt>, <tt>%{volume}</tt>: The current system volume.
11
11
  class Volume < Base
12
12
  # The amount of volume (in percents) to change with scroll.
13
13
  attr_accessor :step
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.2
4
+ version: 0.1.3
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-27 00:00:00.000000000 Z
11
+ date: 2014-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -16,14 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '1.8'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: iconv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: vmstat
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
27
55
  description: r3status is ruby implmentation of the i3bar protocol, and is an alternative
28
56
  to the default i3status.
29
57
  email: gilad.doom@gmail.com
@@ -65,3 +93,4 @@ signing_key:
65
93
  specification_version: 4
66
94
  summary: i3status replacement written in ruby.
67
95
  test_files: []
96
+ has_rdoc: