fusuma 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 006b0257ed698f1e84f48003c23dbe5090ff1a77
4
- data.tar.gz: 8acb3579213176b578501b6c13be87ec2b2cef47
3
+ metadata.gz: facd335cd7fea4ee4d9c3c9a3a4e59e8d255ed77
4
+ data.tar.gz: d306dfeb6133a60222ecfb5de3538afb44f13943
5
5
  SHA512:
6
- metadata.gz: cfcbbae537901fe01b32a655a236ba665317a0f6f56193d97a8b9834efab141a5405f0d0375a091b81a493d7438787080076896aa2f92c5993a3194c9a45177f
7
- data.tar.gz: d4295e32fd124ff621d6cf180f0250fe0cedae70eb168f0e13da6117573d0270dec8ed3188b6907f93dd7df922e6c98cc37c4f70a00968529540c10623fea48a
6
+ metadata.gz: 697898bff6f3b10e9a0eb4d0d7827e938fc4e013c6095e3004b153588746de1cb9be46d05979e428460835ee7fdc7ae038f8e57b8a9d5cca4e72e52d7ce73cfc
7
+ data.tar.gz: b9bf9fd97efc18bdaebc1fdbfe3a1f5406fcf42b54bc5e20e1680a6a81f6d4c02f85e920c84b95740ef75335c21658e1c9ffdad76311650a05b622b052e6b9cc
data/README.md CHANGED
@@ -128,7 +128,7 @@ If the swipe's interval is `0.5`, shorten swipe-interval by half to recognize a
128
128
  * `-d`, `--daemon` : Daemonize process
129
129
  * `-l`, `--list-devices` : List available devices
130
130
  * `-v`, `--verbose` : Show details about the results of running fusuma
131
- * `--device=event14` : Open the given device only
131
+ * `--device="Device name"` : Open the given device only
132
132
  * `--version` : Show fusuma version
133
133
 
134
134
  ## Contributing
data/exe/fusuma CHANGED
@@ -21,7 +21,7 @@ opt.on('-l', '--list-devices',
21
21
  option[:list] = v
22
22
  end
23
23
 
24
- opt.on('--device=event14',
24
+ opt.on('--device="Device name"',
25
25
  'Open the given device only') do |v|
26
26
  option[:device] = v
27
27
  end
@@ -70,7 +70,7 @@ module Fusuma
70
70
 
71
71
  def run
72
72
  LibinputCommands.new.debug_events do |line|
73
- gesture_action = GestureAction.initialize_by(line, Device.names)
73
+ gesture_action = GestureAction.initialize_by(line, Device.ids)
74
74
  next if gesture_action.nil?
75
75
  @action_stack ||= ActionStack.new
76
76
  @action_stack << gesture_action
@@ -1,58 +1,118 @@
1
1
  module Fusuma
2
2
  # detect input device
3
3
  class Device
4
+ attr_accessor :id
5
+ attr_accessor :name
6
+ attr_accessor :available
7
+
8
+ def initialize(id: nil, name: nil, available: nil)
9
+ @id = id
10
+ @name = name
11
+ @available = available
12
+ end
13
+
4
14
  class << self
5
- attr_writer :names
15
+ # @return [Array]
16
+ def ids
17
+ available.map(&:id)
18
+ end
6
19
 
20
+ # @return [Array]
7
21
  def names
8
- return @names unless no_name?
9
- device_names = fetch_device_names
10
- MultiLogger.debug(device_names: device_names)
11
- raise 'Touchpad is not found' if device_names.empty?
12
- @names = device_names
22
+ available.map(&:name)
23
+ end
24
+
25
+ # @raise [SystemExit]
26
+ # @return [Array]
27
+ def available
28
+ @available ||= fetch_available.tap do |d|
29
+ MultiLogger.debug(available_devices: d)
30
+ raise 'Touchpad is not found' if d.empty?
31
+ end
13
32
  rescue RuntimeError => ex
14
33
  MultiLogger.error(ex.message)
15
34
  exit 1
16
35
  end
17
36
 
37
+ def reset
38
+ @available = nil
39
+ end
40
+
18
41
  # @params [String]
19
42
  def given_device=(name)
20
43
  return if name.nil?
21
- if names.include? name
22
- self.names = [name]
23
- return
24
- end
25
- MultiLogger.error("Device #{name} is not found")
44
+ @available = available.select { |d| d.name == name }
45
+ return unless names.empty?
46
+ MultiLogger.error("Device #{name} is not found.\n
47
+ Check available device with: $ fusuma --list-devices\n")
26
48
  exit 1
27
49
  end
28
50
 
29
51
  private
30
52
 
31
- def no_name?
32
- @names.nil? || @names.empty?
53
+ # @return [Array]
54
+ def fetch_available
55
+ line_parser = LineParser.new
56
+ LibinputCommands.new.list_devices do |line|
57
+ line_parser.push(line)
58
+ end
59
+ line_parser.generate_devices
33
60
  end
34
61
 
35
- # @return [Array]
36
- def fetch_device_names
37
- [].tap do |devices|
38
- current_device = nil
39
- LibinputCommands.new.list_devices do |line|
40
- current_device = extracted_input_device_from(line) || current_device
41
- next unless natural_scroll_is_available?(line)
42
- devices << current_device
62
+ # parse line and generate devices
63
+ class LineParser
64
+ attr_reader :lines
65
+
66
+ def initialize
67
+ @lines = []
68
+ end
69
+
70
+ # @param line [String]
71
+ def push(line)
72
+ lines.push(line)
73
+ end
74
+
75
+ def generate_devices
76
+ device = nil
77
+ lines.each_with_object([]) do |line, devices|
78
+ device ||= Device.new
79
+ device = parse(device: device, line: line)
80
+ if device.available
81
+ devices << device
82
+ device = nil
83
+ end
43
84
  end
44
- end.compact
45
- end
85
+ end
46
86
 
47
- def extracted_input_device_from(line)
48
- return unless line =~ /^Kernel: /
49
- line.match(/event[0-9]+/).to_s
50
- end
87
+ # @return [Device]
88
+ def parse(device:, line:)
89
+ if (id = id_from(line))
90
+ device.id = id
91
+ elsif (name = name_from(line))
92
+ device.name = name
93
+ elsif (available = natural_scroll_is_available?(line))
94
+ device.available = available
95
+ end
96
+ device
97
+ end
98
+
99
+ def id_from(line)
100
+ line.match('^Kernel:[[:space:]]*') do |m|
101
+ m.post_match.match(/event[0-9]+/).to_s
102
+ end
103
+ end
51
104
 
52
- def natural_scroll_is_available?(line)
53
- return false unless line =~ /^Nat.scrolling: /
54
- return false if line =~ %r{n/a}
55
- true
105
+ def name_from(line)
106
+ line.match('^Device:[[:space:]]*') do |m|
107
+ m.post_match.strip
108
+ end
109
+ end
110
+
111
+ def natural_scroll_is_available?(line)
112
+ return false unless line =~ /^Nat.scrolling: /
113
+ return false if line =~ %r{n/a}
114
+ true
115
+ end
56
116
  end
57
117
  end
58
118
  end
@@ -70,9 +70,11 @@ module Fusuma
70
70
  end
71
71
 
72
72
  private
73
-
73
+ # use device option only if libinput detect only 1 device
74
+ # @return [String]
74
75
  def device_option
75
- "--device /dev/input/#{Device.names.first}" if Device.names.size == 1
76
+ return unless Device.available.size == 1
77
+ "--device /dev/input/#{Device.available.first.id}"
76
78
  end
77
79
 
78
80
  # which in ruby: Checking if program exists in $PATH from ruby
@@ -1,3 +1,3 @@
1
1
  module Fusuma
2
- VERSION = '0.8.0'.freeze
2
+ VERSION = '0.9.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fusuma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - iberianpig
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-23 00:00:00.000000000 Z
11
+ date: 2018-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler