Class: Vigilem::Evdev::System::KeymapLoaders::KmapLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/vigilem/evdev/system/keymap_loaders/kmap_loader.rb

Overview

change name to console-setup kmap

Constant Summary collapse

KeyMap =
Support::KeyMap

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cache_globString

Returns glob.

Returns:

  • (String)

    glob



66
67
68
# File 'lib/vigilem/evdev/system/keymap_loaders/kmap_loader.rb', line 66

def cache_glob
  @cache_glob ||= '/etc/console-setup/cached*.kmap*'
end

#key_mapObject

Returns:



40
41
42
# File 'lib/vigilem/evdev/system/keymap_loaders/kmap_loader.rb', line 40

def key_map
  @key_map ||= exec
end

Instance Method Details

#available?TrueClass || FalseClass

Returns:

  • (TrueClass || FalseClass)


60
61
62
# File 'lib/vigilem/evdev/system/keymap_loaders/kmap_loader.rb', line 60

def available?
  filepaths.any? {|f| File.exists? f }
end

#exec(path = nil) ⇒ KeyMap Also known as: keymap!

Parameters:

  • path (NilClass || String) (defaults to: nil)

Returns:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vigilem/evdev/system/keymap_loaders/kmap_loader.rb', line 20

def exec(path=nil)
  k = if not path
    if filepath = filepaths.find {|f| File.extname(f) !~ /\.g(un)?z(ip)?/ }
      KeyMap.load_string(File.read(filepath))
    elsif filepath = filepaths.find {|f| File.extname(f) =~ /\.g(un)?z(ip)?/ }
      KeyMap.load_string(Zlib::GzipReader.open(filepath).read)
    end
  else
    KeyMap.load_string(Zlib::GzipReader.open(path).read)
  end
  k.[:loader] = self
  @key_map = k
  key_map_info
  @key_map
end

#filepathsArray<String>

Returns:

  • (Array<String>)


54
55
56
# File 'lib/vigilem/evdev/system/keymap_loaders/kmap_loader.rb', line 54

def filepaths
  @filepaths ||= Dir[cache_glob]
end

#key_map_infoKeyMapInfo

Returns:

  • (KeyMapInfo)


46
47
48
49
50
# File 'lib/vigilem/evdev/system/keymap_loaders/kmap_loader.rb', line 46

def key_map_info
  @key_map_info ||= if DumpkeysLoader.available? 
    key_map.info(DumpkeysLoader.run_dumpkeys('l'))
  end
end