Class: Fusuma::LibinputCommand
- Inherits:
-
Object
- Object
- Fusuma::LibinputCommand
- Defined in:
- lib/fusuma/libinput_command.rb
Overview
Execute libinput command
Constant Summary collapse
- NEW_CLI_OPTION_VERSION =
‘libinput-list-devices` and `libinput-debug-events` are deprecated, use `libinput list-devices` and `libinput debug-events` from 1.8.
"1.8"
Instance Method Summary collapse
-
#debug_events(writer) ⇒ Integer
Return a latest line libinput debug-events.
- #debug_events_command ⇒ Object
- #debug_events_with_options ⇒ Object
-
#initialize(libinput_options: [], commands: {}) ⇒ LibinputCommand
constructor
A new instance of LibinputCommand.
- #list_devices {|gives| ... } ⇒ Object
- #list_devices_command ⇒ Object
- #new_cli_option_available? ⇒ Boolean
- #version ⇒ String
-
#version_command ⇒ String
Command.
Constructor Details
#initialize(libinput_options: [], commands: {}) ⇒ LibinputCommand
Returns a new instance of LibinputCommand.
8 9 10 11 12 |
# File 'lib/fusuma/libinput_command.rb', line 8 def initialize(libinput_options: [], commands: {}) @debug_events_command = commands[:debug_events_command] @list_devices_command = commands[:list_devices_command] @libinput_options = end |
Instance Method Details
#debug_events(writer) ⇒ Integer
Return a latest line libinput debug-events
41 42 43 |
# File 'lib/fusuma/libinput_command.rb', line 41 def debug_events(writer) Open3.pipeline_start([], ["grep -v POINTER_ --line-buffered"], out: writer, in: "/dev/null") end |
#debug_events_command ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/fusuma/libinput_command.rb', line 70 def debug_events_command if @debug_events_command @debug_events_command elsif new_cli_option_available? "libinput debug-events" else "libinput-debug-events" end end |
#debug_events_with_options ⇒ Object
80 81 82 83 |
# File 'lib/fusuma/libinput_command.rb', line 80 def prefix = "stdbuf -oL --" "#{prefix} #{debug_events_command} #{@libinput_options.join(" ")}".strip end |
#list_devices {|gives| ... } ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/fusuma/libinput_command.rb', line 30 def list_devices(&block) cmd = list_devices_command MultiLogger.debug(list_devices: cmd) i, o, e, _w = Open3.popen3(cmd) MultiLogger.error(e.read) if o.eof? i.close e.close o.each(&block) end |
#list_devices_command ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/fusuma/libinput_command.rb', line 60 def list_devices_command if @list_devices_command @list_devices_command elsif new_cli_option_available? "libinput list-devices" else "libinput-list-devices" end end |
#new_cli_option_available? ⇒ Boolean
19 20 21 |
# File 'lib/fusuma/libinput_command.rb', line 19 def new_cli_option_available? Gem::Version.new(version) >= Gem::Version.new(NEW_CLI_OPTION_VERSION) end |
#version ⇒ String
24 25 26 27 |
# File 'lib/fusuma/libinput_command.rb', line 24 def version # version_command prints "1.6.3\n" @version ||= `#{version_command}`.strip end |
#version_command ⇒ String
Returns command.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fusuma/libinput_command.rb', line 47 def version_command if @debug_events_command && @list_devices_command "#{@list_devices_command} --version" elsif which("libinput") "libinput --version" elsif which("libinput-list-devices") "libinput-list-devices --version" else MultiLogger.error "Please install libinput-tools" exit 1 end end |