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