uh-wm 0.1.0 → 0.2.2

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
- SHA1:
3
- metadata.gz: 959239c4e633cdfa25d86371729560ddf40afa4a
4
- data.tar.gz: 704626fb3cfe89b8ea8d84fe5f6e1200d9000ffa
2
+ SHA256:
3
+ metadata.gz: bdfaa9044850872fdb32698f87fe8323e5e846519b6c6bec7815db47169ca8d1
4
+ data.tar.gz: b5fc6c161f4c491d6cf80f32eaa7ea2f494c21bda689424baa3bb7e6ea4628f0
5
5
  SHA512:
6
- metadata.gz: e2a06d4832cfff8ffdb1ed5bf6c59f999b51c8d6e3f055f449e5414be799fd0c88beaf0b054a0c9054d0930d0bfb5a170fc1b5090966c3f60f90b1a9778de3ff
7
- data.tar.gz: 5f96afa7bc57f3ea5e48dc7a8ba8544b9472b29957c06ef0a760a3ba8423c6d0ce26614e2cee2f9e1f70e57aa3253ff724962f2c9b4bfcd8043bda5953442cb7
6
+ metadata.gz: c36a250861f7afa38a3fef39a72979d71576bfd71083e46e7405d42c4c050fa38f21374b8abbcbac6485c39c5c51bf9a240a5d08d4db073f8e229f496b7c70f0
7
+ data.tar.gz: fcfe9ec464a7ee86e725bb2fd93c02151d429057764fe987db90ceee1887adcb1aec4770ea3dbc571a9a3ebc86a9e967c4f90dd679b780725c2711795532b896
data/README.md CHANGED
@@ -7,7 +7,7 @@ directly with ruby code.
7
7
 
8
8
  The layout behavior can be changed, the default one being
9
9
  implemented by the `uh-layout` ruby gem. A layout is a simple ruby
10
- object responding to specific messages, so you can wrote your own in
10
+ object responding to specific messages, so you can write your own in
11
11
  plain ruby without any dependency.
12
12
 
13
13
  Main features:
@@ -16,7 +16,7 @@ plain ruby without any dependency.
16
16
  * different adapters for event handling: blocking, multiplexing
17
17
  with `select()` or `kqueue()`;
18
18
  * configuration with a run control file;
19
- * key bindings with user defined code as callback;
19
+ * key bindings with user defined callbacks;
20
20
  * configurable modifier key;
21
21
  * user-defined layout behavior (ruby);
22
22
  * external program execution;
@@ -67,8 +67,7 @@ BROWSERS = %w[
67
67
 
68
68
  modifier :mod1 # This key is added to the modifier mask for *all*
69
69
  # key bindings.
70
- key(:p) { execute DMENU } # Execute given command in a shell when mod1+shift
71
- # is pressed.
70
+ key(:p) { execute DMENU } # Execute given command in a shell with mod1+p.
72
71
  key(:Q) { quit } # Quit when mod1+shift+q is pressed (a capitalized
73
72
  # key adds shift to mod mask).
74
73
  key(:enter) { execute VT } # Common key names (`enter') are translated to
@@ -68,16 +68,16 @@ module Uh
68
68
  end
69
69
 
70
70
  # Forwards unhandled messages prefixed with `layout_` to the layout,
71
- # without the prefix
71
+ # replacing the prefix with `handle_`
72
72
  # @example
73
- # layout_foo # delegates to `layout.foo'
73
+ # layout_foo # delegates to `layout.handle_foo'
74
74
  def method_missing m, *args, &block
75
75
  if respond_to? m
76
76
  meth = layout_method m
77
77
  log "#{layout.class.name}##{meth} #{args.inspect}"
78
- begin
78
+ if layout.respond_to? meth
79
79
  layout.send meth, *args
80
- rescue NoMethodError
80
+ else
81
81
  log_error "Layout does not implement `#{meth}'"
82
82
  end
83
83
  else
@@ -100,7 +100,7 @@ module Uh
100
100
  private
101
101
 
102
102
  def layout_method m
103
- m.to_s.gsub(/\Alayout_/, 'handle_').to_sym
103
+ m.to_s.sub(/\Alayout_/, 'handle_').to_sym
104
104
  end
105
105
  end
106
106
  end
data/lib/uh/wm/cli.rb CHANGED
@@ -1,90 +1,39 @@
1
1
  module Uh
2
2
  module WM
3
- class CLI
4
- ArgumentError = Class.new(ArgumentError)
5
-
6
- include EnvLogging
7
-
8
- USAGE = "Usage: #{File.basename $0} [options]".freeze
9
-
10
- EX_USAGE = 64
11
- EX_SOFTWARE = 70
12
-
3
+ class CLI < Baf::CLI
13
4
  class << self
14
- def run arguments, stdout: $stdout, stderr: $stderr
15
- cli = new arguments, stdout: stdout
16
- cli.parse_arguments!
17
- cli.run
18
- rescue ArgumentError => e
19
- stderr.puts e
20
- exit EX_USAGE
21
- rescue RuntimeError => e
22
- stderr.puts "#{e.class.name}: #{e.message}"
23
- stderr.puts e.backtrace.map { |l| ' %s' % l } if cli.env.debug?
24
- exit EX_SOFTWARE
5
+ def handle_error env, ex
6
+ env.puts_error "#{ex.class.name}: #{ex.message}"
7
+ env.puts_error ex.backtrace.map { |l| ' %s' % l } if env.debug?
25
8
  end
26
9
  end
27
10
 
28
- attr_reader :env
11
+ def setup
12
+ flag_verbose
13
+ flag_debug
14
+ flag_version WM::VERSION
29
15
 
30
- def initialize args, stdout: $stdout
31
- @arguments = args
32
- @env = Env.new(stdout.tap { |o| o.sync = true })
33
- end
16
+ option :f, :run_control, 'PATH', 'specify alternate run control file' do |path|
17
+ @env.rc_path = path
18
+ end
19
+ option :r, :require, 'PATH', 'require ruby feature' do |feature|
20
+ require feature
21
+ env.log "Loaded `#{feature}' ruby feature"
22
+ end
23
+ option :l, :layout, 'LAYOUT', 'specify layout' do |layout|
24
+ env.layout_class = Object.const_get layout.to_sym
25
+ end
26
+ option :w, :worker, 'WORKER', 'specify worker' do |worker|
27
+ env.worker = worker.to_sym
28
+ end
34
29
 
35
- def parse_arguments!
36
- option_parser.parse! @arguments
37
- rescue OptionParser::InvalidOption
38
- raise ArgumentError, option_parser
30
+ env.sync_output
39
31
  end
40
32
 
41
33
  def run
34
+ env.log_logger_level
42
35
  Runner.run env
43
36
  end
44
-
45
- private
46
-
47
- def option_parser
48
- OptionParser.new do |opts|
49
- opts.banner = USAGE
50
- opts.separator ''
51
- opts.separator 'options:'
52
-
53
- opts.on '-v', '--verbose', 'enable verbose mode' do
54
- @env.verbose = true
55
- @env.log_logger_level
56
- end
57
- opts.on '-d', '--debug', 'enable debug mode' do
58
- @env.debug = true
59
- @env.log_logger_level
60
- end
61
- opts.on '-f', '--run-control PATH',
62
- 'specify alternate run control file' do |e|
63
- @env.rc_path = e
64
- end
65
- opts.on '-r', '--require PATH', 'require ruby feature' do |feature|
66
- require feature
67
- log "Loaded `#{feature}' ruby feature"
68
- end
69
- opts.on '-l', '--layout LAYOUT', 'specify layout' do |layout|
70
- @env.layout_class = Object.const_get layout.to_sym
71
- end
72
- opts.on '-w', Workers.types, '--worker WORKER',
73
- 'specify worker' do |worker|
74
- @env.worker = worker.to_sym
75
- end
76
-
77
- opts.separator ''
78
- opts.on_tail '-h', '--help', 'print this message' do
79
- @env.print opts
80
- exit
81
- end
82
- opts.on_tail '-V', '--version', 'print version' do
83
- @env.puts WM::VERSION
84
- exit
85
- end
86
- end
87
- end
88
37
  end
89
38
  end
90
39
  end
data/lib/uh/wm/env.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Uh
2
2
  module WM
3
- class Env
3
+ class Env < Baf::Env
4
4
  RC_PATH = '~/.uhwmrc.rb'.freeze
5
5
 
6
6
  MODIFIER = :mod1
@@ -15,19 +15,17 @@ module Uh
15
15
  LOGGER_LEVEL_STRINGS = %w[DEBUG INFO WARN ERROR FATAL UNKNOWN].freeze
16
16
 
17
17
  extend Forwardable
18
- def_delegator :logger, :info, :log
19
- def_delegator :logger, :fatal, :log_fatal
20
- def_delegator :logger, :error, :log_error
21
- def_delegator :logger, :debug, :log_debug
22
- def_delegators :@output, :print, :puts
18
+ def_delegator :logger, :info, :log
19
+ def_delegator :logger, :fatal, :log_fatal
20
+ def_delegator :logger, :error, :log_error
21
+ def_delegator :logger, :debug, :log_debug
23
22
 
24
- attr_reader :output, :keybinds
25
- attr_accessor :verbose, :debug, :rc_path, :modifier, :modifier_ignore,
26
- :worker, :layout, :layout_class, :layout_options, :rules,
27
- :launch
23
+ attr_reader :keybinds
24
+ attr_accessor :rc_path, :modifier, :modifier_ignore, :worker, :layout,
25
+ :layout_class, :layout_options, :rules, :launch
28
26
 
29
- def initialize output
30
- @output = output
27
+ def initialize **_
28
+ super
31
29
  @rc_path = RC_PATH
32
30
  @modifier = MODIFIER
33
31
  @modifier_ignore = []
@@ -37,14 +35,6 @@ module Uh
37
35
  @rules = {}
38
36
  end
39
37
 
40
- def verbose?
41
- !!@verbose
42
- end
43
-
44
- def debug?
45
- !!@debug
46
- end
47
-
48
38
  def layout
49
39
  @layout ||= if layout_class
50
40
  layout_class.new @layout_options
@@ -75,7 +75,7 @@ module Uh
75
75
  # @param arg [Class, Object, Hash] A layout class, a layout instance, or
76
76
  # options for the default layout
77
77
  # @param options [Hash] Layout options
78
- def layout arg, **options
78
+ def layout arg, options = {}
79
79
  case arg
80
80
  when Class
81
81
  if options.any?
@@ -144,7 +144,7 @@ module Uh
144
144
  translated_keysym = KEYSYM_TRANSLATIONS.key?(translate_key) ?
145
145
  KEYSYM_TRANSLATIONS[translate_key] :
146
146
  translate_key
147
- keysym =~ /[A-Z]/ ? [translated_keysym, :shift] : translated_keysym
147
+ keysym.to_s =~ /[A-Z]/ ? [translated_keysym, :shift] : translated_keysym
148
148
  end
149
149
  end
150
150
  end
@@ -1,3 +1,5 @@
1
+ require 'baf/testing/process'
2
+
1
3
  require 'uh'
2
4
  require 'uh/wm/testing/x_client'
3
5
 
@@ -5,24 +7,14 @@ module Uh
5
7
  module WM
6
8
  module Testing
7
9
  module AcceptanceHelpers
8
- TIMEOUT_DEFAULT = 2
9
10
  QUIT_KEYBINDING = 'alt+shift+q'.freeze
10
11
  LOG_READY = 'Working events'.freeze
11
12
 
12
13
  attr_reader :other_wm
13
14
 
14
- def build_regexp pattern, options
15
- Regexp.new(pattern, options.each_char.inject(0) do |m, e|
16
- m | case e
17
- when ?i then Regexp::IGNORECASE
18
- when ?m then Regexp::MULTILINE
19
- when ?x then Regexp::EXTENDED
20
- end
21
- end)
22
- end
23
-
24
15
  def icccm_window_start
25
- @icccm_window = ChildProcess.build(*%w[xmessage window])
16
+ @icccm_window = Baf::Testing::Process.new %w[xmessage window],
17
+ env_allow: %w[DISPLAY]
26
18
  @icccm_window.start
27
19
  end
28
20
 
@@ -34,57 +26,29 @@ module Uh
34
26
  'xmessage'
35
27
  end
36
28
 
37
- def uhwm_run options = '-v'
38
- command = %w[uhwm]
39
- command << options if options
40
- @interactive = @process = run command.join ' '
41
- end
42
-
43
- def uhwm
44
- @process
45
- end
46
-
47
29
  def uhwm_request_quit
48
30
  x_key QUIT_KEYBINDING
49
31
  end
50
32
 
51
33
  def uhwm_ensure_stop
52
- if @process
53
- x_key 'alt+shift+q'
54
- @process.terminate
55
- end
34
+ uhwm_request_quit
56
35
  end
57
36
 
58
- def uhwm_wait_output message, times = 1, value = nil
59
- output = -> { @process.stdout + @process.stderr }
60
- timeout_until do
61
- case message
62
- when Regexp then (value = output.call.scan(message)).size >= times
63
- when String then output.call.include? message
64
- end
37
+ def uhwm_run_wait_ready options = '-v'
38
+ cmd = $_baf[:program] + options.split(' ')
39
+ env = Baf::Testing::ENV_WHITELIST + $_baf[:env_allow]
40
+ Baf::Testing::Process.new(cmd, env_allow: env).tap do |uhwm|
41
+ uhwm.start
42
+ Baf::Testing.wait_output LOG_READY, stream: -> { uhwm.output }
65
43
  end
66
- value
67
- rescue TimeoutError => e
68
- raise <<-eoh
69
- expected `#{message}' (#{times}) not seen after #{e.timeout} seconds in:
70
- ```\n#{output.call.lines.map { |l| " #{l}" }.join} ```
71
- eoh
72
- end
73
-
74
- def uhwm_wait_ready
75
- uhwm_wait_output LOG_READY
76
44
  end
77
45
 
78
- def uhwm_run_wait_ready options = nil
79
- if options then uhwm_run options else uhwm_run end
80
- uhwm_wait_ready
81
- end
82
-
83
- def with_other_wm
84
- @other_wm = ChildProcess.build('./bin/uhwm')
46
+ def with_other_wm uhwm_command
47
+ env = Baf::Testing::ENV_WHITELIST + $_baf[:env_allow]
48
+ @other_wm = Baf::Testing::Process.new uhwm_command, env_allow: env
85
49
  @other_wm.start
86
50
  yield
87
- @other_wm.stop
51
+ uhwm_request_quit
88
52
  @other_wm = nil
89
53
  end
90
54
 
@@ -116,31 +80,6 @@ expected `#{message}' (#{times}) not seen after #{e.timeout} seconds in:
116
80
  end
117
81
  `xwininfo #{select_args} 2> /dev/null`[/Map State: (\w+)/, 1]
118
82
  end
119
-
120
- private
121
-
122
- def timeout_until message = 'condition not met after %d seconds'
123
- timeout = ENV.key?('UHWMTEST_TIMEOUT') ?
124
- ENV['UHWMTEST_TIMEOUT'].to_i :
125
- TIMEOUT_DEFAULT
126
- Timeout.timeout(timeout) do
127
- loop do
128
- break if yield
129
- sleep 0.1
130
- end
131
- end
132
- rescue Timeout::Error
133
- raise TimeoutError.new(message % timeout, timeout)
134
- end
135
-
136
- class TimeoutError < ::StandardError
137
- attr_reader :timeout
138
-
139
- def initialize message, timeout
140
- super message
141
- @timeout = timeout
142
- end
143
- end
144
83
  end
145
84
  end
146
85
  end
@@ -1,4 +1,4 @@
1
- require 'childprocess'
1
+ require 'baf/testing/process'
2
2
 
3
3
  module Uh
4
4
  module WM
@@ -8,15 +8,18 @@ module Uh
8
8
  DISPLAY_SCREEN = '640x480x24'
9
9
 
10
10
  def with_xvfb
11
- xvfb = ChildProcess.build(*%W[
11
+ xvfb = Baf::Testing::Process.new %W[
12
12
  Xvfb -ac #{DISPLAY_NAME} -screen 0 #{DISPLAY_SCREEN}
13
- ])
13
+ ]
14
14
  xvfb.start
15
15
  original_display = ENV['DISPLAY']
16
16
  ENV['DISPLAY'] = DISPLAY_NAME
17
- yield
18
- ENV['DISPLAY'] = original_display
19
- xvfb.stop
17
+ begin
18
+ yield
19
+ ensure
20
+ ENV['DISPLAY'] = original_display
21
+ xvfb.stop
22
+ end
20
23
  end
21
24
  end
22
25
  end
@@ -26,7 +26,7 @@ module Uh
26
26
  end
27
27
 
28
28
  def window_id
29
- @window.id
29
+ window.id
30
30
  end
31
31
 
32
32
  def window_name
data/lib/uh/wm/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Uh
2
2
  module WM
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.2.2'.freeze
4
4
  end
5
5
  end
@@ -4,7 +4,7 @@ module Uh
4
4
  class Base
5
5
  CALLBACKS = %w[before_watch on_timeout on_read on_read_next].freeze
6
6
 
7
- def initialize **_options
7
+ def initialize *_options
8
8
  @ios = []
9
9
  end
10
10
 
data/lib/uh/wm/workers.rb CHANGED
@@ -2,9 +2,9 @@ module Uh
2
2
  module WM
3
3
  module Workers
4
4
  FACTORIES = {
5
- block: ->(options) { Blocking.new(options) },
6
- kqueue: ->(options) { KQueue.new(options) },
7
- mux: ->(options) { Mux.new(options) }
5
+ block: ->(options) { Blocking.new(**options) },
6
+ kqueue: ->(options) { KQueue.new(**options) },
7
+ mux: ->(options) { Mux.new(**options) }
8
8
  }.freeze
9
9
 
10
10
  class << self
@@ -16,7 +16,7 @@ module Uh
16
16
  FACTORIES.key? type
17
17
  end
18
18
 
19
- def build type, **options
19
+ def build type, options = {}
20
20
  (FACTORIES[type] or fail ArgumentError, "unknown worker: `#{type}'")
21
21
  .call options
22
22
  end
data/lib/uh/wm.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'baf/cli'
1
2
  require 'forwardable'
2
3
  require 'logger'
3
4
  require 'optparse'
metadata CHANGED
@@ -1,19 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uh-wm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-22 00:00:00.000000000 Z
11
+ date: 2022-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: baf
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.14'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.14'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rb-kqueue
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.2'
17
34
  - - ">="
18
35
  - !ruby/object:Gem::Version
19
36
  version: 0.2.4
@@ -21,6 +38,9 @@ dependencies:
21
38
  prerelease: false
22
39
  version_requirements: !ruby/object:Gem::Requirement
23
40
  requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '0.2'
24
44
  - - ">="
25
45
  - !ruby/object:Gem::Version
26
46
  version: 0.2.4
@@ -42,6 +62,9 @@ dependencies:
42
62
  name: uh-layout
43
63
  requirement: !ruby/object:Gem::Requirement
44
64
  requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0.4'
45
68
  - - ">="
46
69
  - !ruby/object:Gem::Version
47
70
  version: 0.4.2
@@ -49,37 +72,26 @@ dependencies:
49
72
  prerelease: false
50
73
  version_requirements: !ruby/object:Gem::Requirement
51
74
  requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '0.4'
52
78
  - - ">="
53
79
  - !ruby/object:Gem::Version
54
80
  version: 0.4.2
55
- - !ruby/object:Gem::Dependency
56
- name: aruba
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '='
60
- - !ruby/object:Gem::Version
61
- version: 0.7.4
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '='
67
- - !ruby/object:Gem::Version
68
- version: 0.7.4
69
81
  - !ruby/object:Gem::Dependency
70
82
  name: cucumber
71
83
  requirement: !ruby/object:Gem::Requirement
72
84
  requirements:
73
85
  - - "~>"
74
86
  - !ruby/object:Gem::Version
75
- version: '2.0'
87
+ version: '3.2'
76
88
  type: :development
77
89
  prerelease: false
78
90
  version_requirements: !ruby/object:Gem::Requirement
79
91
  requirements:
80
92
  - - "~>"
81
93
  - !ruby/object:Gem::Version
82
- version: '2.0'
94
+ version: '3.2'
83
95
  - !ruby/object:Gem::Dependency
84
96
  name: rake
85
97
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +112,14 @@ dependencies:
100
112
  requirements:
101
113
  - - "~>"
102
114
  - !ruby/object:Gem::Version
103
- version: '3.2'
115
+ version: '3.11'
104
116
  type: :development
105
117
  prerelease: false
106
118
  version_requirements: !ruby/object:Gem::Requirement
107
119
  requirements:
108
120
  - - "~>"
109
121
  - !ruby/object:Gem::Version
110
- version: '3.2'
122
+ version: '3.11'
111
123
  description: |2
112
124
  uhwm is a minimalistic tiling and stacking window manager for X. It
113
125
  shares some similarities with dwm and wmii, but is written in ruby so
@@ -147,7 +159,7 @@ homepage: https://rubygems.org/gems/uh-wm
147
159
  licenses:
148
160
  - BSD-3-Clause
149
161
  metadata: {}
150
- post_install_message:
162
+ post_install_message:
151
163
  rdoc_options: []
152
164
  require_paths:
153
165
  - lib
@@ -162,9 +174,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
174
  - !ruby/object:Gem::Version
163
175
  version: '0'
164
176
  requirements: []
165
- rubyforge_project:
166
- rubygems_version: 2.6.14
167
- signing_key:
177
+ rubygems_version: 3.3.17
178
+ signing_key:
168
179
  specification_version: 4
169
180
  summary: minimalistic tiling and stacking X window manager
170
181
  test_files: []