lib/fusuma/libinput_command.rb in fusuma-2.4.1 vs lib/fusuma/libinput_command.rb in fusuma-2.5.0
- old
+ new
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-require 'open3'
+require "open3"
module Fusuma
# Execute libinput command
class LibinputCommand
def initialize(libinput_options: [], commands: {})
@@ -11,11 +11,11 @@
@libinput_options = libinput_options
end
# `libinput-list-devices` and `libinput-debug-events` are deprecated,
# use `libinput list-devices` and `libinput debug-events` from 1.8.
- NEW_CLI_OPTION_VERSION = '1.8'
+ NEW_CLI_OPTION_VERSION = "1.8"
# @return [Boolean]
def new_cli_option_available?
Gem::Version.new(version) >= Gem::Version.new(NEW_CLI_OPTION_VERSION)
end
@@ -38,55 +38,54 @@
end
# @return [Integer] return a latest line libinput debug-events
def debug_events(writer)
@debug_events ||= begin
- pid = Process.spawn(debug_events_with_options, out: writer,
- in: '/dev/null')
- Process.detach(pid)
- pid
+ t = Open3.pipeline_start([debug_events_with_options], ["grep -v POINTER_ --line-buffered"],
+ out: writer, in: "/dev/null")
+ t[0].pid
end
end
# @return [String] command
# @raise [SystemExit]
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'
+ elsif which("libinput")
+ "libinput --version"
+ elsif which("libinput-list-devices")
+ "libinput-list-devices --version"
else
- MultiLogger.error 'Please install libinput-tools'
+ MultiLogger.error "Please install libinput-tools"
exit 1
end
end
def list_devices_command
if @list_devices_command
@list_devices_command
elsif new_cli_option_available?
- 'libinput list-devices'
+ "libinput list-devices"
else
- 'libinput-list-devices'
+ "libinput-list-devices"
end
end
def debug_events_command
if @debug_events_command
@debug_events_command
elsif new_cli_option_available?
- 'libinput debug-events'
+ "libinput debug-events"
else
- 'libinput-debug-events'
+ "libinput-debug-events"
end
end
def debug_events_with_options
- prefix = 'stdbuf -oL --'
- "#{prefix} #{debug_events_command} #{@libinput_options.join(' ')}".strip
+ prefix = "stdbuf -oL --"
+ "#{prefix} #{debug_events_command} #{@libinput_options.join(" ")}".strip
end
private
# which in ruby: Checking if program exists in $PATH from ruby
@@ -94,11 +93,11 @@
# Cross-platform way of finding an executable in the $PATH.
#
# which('ruby') #=> /usr/bin/ruby
# @return [String, nil]
def which(command)
- exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
+ exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
+ ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
exts.each do |ext|
exe = File.join(path, "#{command}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
end
end