Class: R3Status::Blocks::Shell

Inherits:
Base
  • Object
show all
Defined in:
lib/r3status/blocks/shell.rb

Constant Summary

Constants inherited from Base

Base::DEFAULT_COLOR, Base::DEFAULT_FORMAT

Instance Attribute Summary collapse

Attributes inherited from Base

#clicked_block, #colors, #formats, #full_text, #max_length, #name, #text_color

Instance Method Summary collapse

Methods inherited from Base

#color, #color=, #format, #format=, #state, #terminate, #to_s

Constructor Details

#initialize(**args, &block) ⇒ Shell

Returns a new instance of Shell.



5
6
7
# File 'lib/r3status/blocks/shell.rb', line 5

def initialize(**args, &block)
  super(args, &block)
end

Instance Attribute Details

#click_commandsObject

Returns the value of attribute click_commands.



3
4
5
# File 'lib/r3status/blocks/shell.rb', line 3

def click_commands
  @click_commands
end

#commandObject

Returns the value of attribute command.



3
4
5
# File 'lib/r3status/blocks/shell.rb', line 3

def command
  @command
end

Instance Method Details

#clicked(button, x, y) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/r3status/blocks/shell.rb', line 19

def clicked(button, x, y)
  super(button, x, y)
  
  case click_commands.class
  when String
    `#{click_commands}`
  when Array
    `#{click_commands[button - 1]}`
  when Hash
    `#{click_commands[button]}`
  end
end

#updateObject



9
10
11
12
13
14
15
16
17
# File 'lib/r3status/blocks/shell.rb', line 9

def update
  return if command.nil?
  
  cmd = `#{command}`.split.map {|str| str.chomp}
  return if cmd.length == 0
  
  @full_text = cmd[0]
  @text_color = cmd[1] if cmd.length >= 2
end