Class: R3Status::Blocks::KeyboardLayout
- Defined in:
- lib/r3status/blocks/keyboard_layout.rb
Overview
A block that acts as a keyboard layout indicator.
States
There are no constant states. A state is the current keyboard layout,
as specified by the system. (e.g. :us for US English, :ru for Russian)
Format values
8 %{val}, %{sym}: The current language symbol.
Constant Summary
Constants inherited from Base
Base::DEFAULT_COLOR, Base::DEFAULT_FORMAT
Instance Attribute Summary
Attributes inherited from Base
#clicked_block, #colors, #formats, #full_text, #max_length, #name, #text_color
Instance Method Summary collapse
-
#command?(command) ⇒ Boolean
Determines if a shell command exists.
-
#initialize(**args, &block) ⇒ KeyboardLayout
constructor
Creates a new instance of this class.
-
#state ⇒ Object
Returns the current state of the block.
-
#update ⇒ Object
Updates the text and color of this block.
Methods inherited from Base
#clicked, #color, #color=, #format, #format=, #terminate, #to_s
Constructor Details
#initialize(**args, &block) ⇒ KeyboardLayout
Creates a new instance of this class. If a block is passed, it will be stored and yielded when the block is clicked.
14 15 16 |
# File 'lib/r3status/blocks/keyboard_layout.rb', line 14 def initialize(**args, &block) super(args, &block) end |
Instance Method Details
#command?(command) ⇒ Boolean
Determines if a shell command exists.
35 36 37 |
# File 'lib/r3status/blocks/keyboard_layout.rb', line 35 def command?(command) system("which #{command} > /dev/null 2>&1") end |
#state ⇒ Object
Returns the current state of the block.
26 27 28 29 30 31 32 |
# File 'lib/r3status/blocks/keyboard_layout.rb', line 26 def state if command? "xkblayout-state" `xkblayout-state print %s` else `setxkbmap -query | awk -F"(|[ ]+)" '/layout:/ { print $2 }'` end.chomp.to_sym end |
#update ⇒ Object
Updates the text and color of this block.
19 20 21 22 23 |
# File 'lib/r3status/blocks/keyboard_layout.rb', line 19 def update sym = state @full_text = formats[sym] % {val: sym, sym: sym} @text_color = colors[sym] end |