class R3Status::Blocks::KeyboardLayoutBlock

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.

Public Class Methods

new(**args, &block) click to toggle source

Creates a new instance of this class. If a block is passed, it will be stored and yielded when the block is clicked.

Calls superclass method R3Status::Blocks::Base::new
# File lib/r3status/blocks/keyboard_layout.rb, line 14
def initialize(**args, &block)
  super(args, &block)
end

Public Instance Methods

command?(command) click to toggle source

Determines if a shell command exists.

# File lib/r3status/blocks/keyboard_layout.rb, line 35
def command?(command)
   system("which #{command} > /dev/null 2>&1")
end
state() click to toggle source

Returns the current state of the block.

# 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() click to toggle source

Updates the text and color of this block.

# 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