From bf6f08e848a84dedbe2f71a51d4fa70bb72478d9 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Sun, 26 Apr 2015 00:59:24 +0000 Subject: [PATCH 1/3] Implement `layout' run control keyword Allow configuration of the layout by specifying either a class or an instance. --- features/run_control/layout.feature | 27 +++++++++++++++++++++++++++ lib/uh/wm/env.rb | 4 ++-- lib/uh/wm/run_control.rb | 8 ++++++++ spec/uh/wm/env_spec.rb | 24 ++++++++++++++++-------- spec/uh/wm/run_control_spec.rb | 16 ++++++++++++++++ 5 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 features/run_control/layout.feature diff --git a/features/run_control/layout.feature b/features/run_control/layout.feature new file mode 100644 index 0000000..d66f615 --- /dev/null +++ b/features/run_control/layout.feature @@ -0,0 +1,27 @@ +Feature: `layout' run control keyword + + Background: + Given a file named my_layout.rb with: + """ + class MyLayout + def register *_ + puts "testing_rc_layout" + end + end + """ + + Scenario: configures a layout class + Given a run control file with: + """ + layout MyLayout + """ + When I run uhwm with options -r./my_layout + Then the output must contain "testing_rc_layout" + + Scenario: configures a layout instance + Given a run control file with: + """ + layout MyLayout.new + """ + When I run uhwm with options -r./my_layout + Then the output must contain "testing_rc_layout" diff --git a/lib/uh/wm/env.rb b/lib/uh/wm/env.rb index 20755f6..de22e68 100644 --- a/lib/uh/wm/env.rb +++ b/lib/uh/wm/env.rb @@ -21,8 +21,8 @@ module Uh def_delegators :@output, :print, :puts attr_reader :output, :keybinds - attr_accessor :verbose, :debug, :rc_path, :layout_class, :modifier, - :worker + attr_accessor :verbose, :debug, :rc_path, :modifier, :worker, + :layout, :layout_class def initialize output @output = output diff --git a/lib/uh/wm/run_control.rb b/lib/uh/wm/run_control.rb index c890ee1..ba5b218 100644 --- a/lib/uh/wm/run_control.rb +++ b/lib/uh/wm/run_control.rb @@ -32,6 +32,14 @@ module Uh @env.keybinds[translate_keysym *keysyms] = block end + def layout obj + if obj.is_a? Class + @env.layout_class = obj + else + @env.layout = obj + end + end + def worker type, **options @env.worker = [type, options] end diff --git a/spec/uh/wm/env_spec.rb b/spec/uh/wm/env_spec.rb index 17029da..d6bb82a 100644 --- a/spec/uh/wm/env_spec.rb +++ b/spec/uh/wm/env_spec.rb @@ -70,19 +70,27 @@ module Uh end describe '#layout' do - context 'when a layout class is set' do - let(:some_layout) { Class.new } + let(:some_layout_class) { Class.new } - before { env.layout_class = some_layout } + it 'returns the default layout' do + expect(env.layout).to be_an_instance_of ::Uh::Layout + end - it 'returns a new instance of this layout class' do - expect(env.layout).to be_an_instance_of some_layout + context 'when a layout is set' do + let(:some_layout) { some_layout_class.new } + + before { env.layout = some_layout } + + it 'returns the assigned layout' do + expect(env.layout).to be some_layout end end - context 'when a layout class is not set' do - it 'returns an instance of the default layout' do - expect(env.layout).to be_an_instance_of ::Uh::Layout + context 'when a layout class is set' do + before { env.layout_class = some_layout_class } + + it 'returns a new instance of this layout class' do + expect(env.layout).to be_an_instance_of some_layout_class end end end diff --git a/spec/uh/wm/run_control_spec.rb b/spec/uh/wm/run_control_spec.rb index 41a4104..cac60d9 100644 --- a/spec/uh/wm/run_control_spec.rb +++ b/spec/uh/wm/run_control_spec.rb @@ -85,6 +85,22 @@ module Uh end end + describe '#layout' do + context 'when given a class' do + it 'sets a layout class in the env' do + rc.layout layout_class = Class.new + expect(env.layout_class).to be layout_class + end + end + + context 'when given an object' do + it 'sets a layout instance in the env' do + rc.layout layout = Object.new + expect(env.layout).to eq layout + end + end + end + describe '#worker' do it 'sets the worker type in the env' do rc.worker :some_worker From 70fe9bdb032485913083e39840e9c8f19c2e99b0 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Sun, 26 Apr 2015 02:43:39 +0000 Subject: [PATCH 2/3] Update uh-layout dependency to ~> 0.3.0 --- uh-wm.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uh-wm.gemspec b/uh-wm.gemspec index 1a23946..5789b10 100644 --- a/uh-wm.gemspec +++ b/uh-wm.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |s| s.executables = s.files.grep(/\Abin\//) { |f| File.basename(f) } s.add_dependency 'uh', '2.0.0.pre2' - s.add_dependency 'uh-layout', '~> 0.2.3' + s.add_dependency 'uh-layout', '~> 0.3.0' s.add_development_dependency 'aruba', '~> 0.6' s.add_development_dependency 'cucumber', '~> 2.0' From 7c2712924a198a4ed4344ac071786f797ecd00a9 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Sun, 26 Apr 2015 02:49:39 +0000 Subject: [PATCH 3/3] Allow layout options configuration from run control --- features/run_control/layout.feature | 20 ++++++++++++++++---- lib/uh/wm/run_control.rb | 12 ++++++++---- spec/uh/wm/run_control_spec.rb | 11 ++++++++++- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/features/run_control/layout.feature b/features/run_control/layout.feature index d66f615..44899f2 100644 --- a/features/run_control/layout.feature +++ b/features/run_control/layout.feature @@ -4,8 +4,12 @@ Feature: `layout' run control keyword Given a file named my_layout.rb with: """ class MyLayout - def register *_ - puts "testing_rc_layout" + def initialize **options + puts "testing_rc_layout_#{options.inspect}" if options.any? + end + + def register *_, **options + puts "testing_rc_layout_register" end end """ @@ -16,7 +20,15 @@ Feature: `layout' run control keyword layout MyLayout """ When I run uhwm with options -r./my_layout - Then the output must contain "testing_rc_layout" + Then the output must contain "testing_rc_layout_register" + + Scenario: configures a layout class with options + Given a run control file with: + """ + layout MyLayout, foo: :bar + """ + When I run uhwm with options -r./my_layout + Then the output must contain "testing_rc_layout_{:foo=>:bar}" Scenario: configures a layout instance Given a run control file with: @@ -24,4 +36,4 @@ Feature: `layout' run control keyword layout MyLayout.new """ When I run uhwm with options -r./my_layout - Then the output must contain "testing_rc_layout" + Then the output must contain "testing_rc_layout_register" diff --git a/lib/uh/wm/run_control.rb b/lib/uh/wm/run_control.rb index ba5b218..6290677 100644 --- a/lib/uh/wm/run_control.rb +++ b/lib/uh/wm/run_control.rb @@ -32,11 +32,15 @@ module Uh @env.keybinds[translate_keysym *keysyms] = block end - def layout obj - if obj.is_a? Class - @env.layout_class = obj + def layout arg, **options + if arg.is_a? Class + if options.any? + @env.layout = arg.new options + else + @env.layout_class = arg + end else - @env.layout = obj + @env.layout = arg end end diff --git a/spec/uh/wm/run_control_spec.rb b/spec/uh/wm/run_control_spec.rb index cac60d9..a89475f 100644 --- a/spec/uh/wm/run_control_spec.rb +++ b/spec/uh/wm/run_control_spec.rb @@ -87,10 +87,19 @@ module Uh describe '#layout' do context 'when given a class' do + let(:layout_class) { Class.new } + it 'sets a layout class in the env' do - rc.layout layout_class = Class.new + rc.layout layout_class expect(env.layout_class).to be layout_class end + + context 'when given options' do + it 'instantiates the class with given options' do + expect(layout_class).to receive(:new).with(foo: :bar) + rc.layout layout_class, foo: :bar + end + end end context 'when given an object' do