Implement `layout' run control keyword
Allow configuration of the layout by specifying either a class or an instance.
This commit is contained in:
parent
7c06b52664
commit
bf6f08e848
27
features/run_control/layout.feature
Normal file
27
features/run_control/layout.feature
Normal file
@ -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"
|
@ -21,8 +21,8 @@ module Uh
|
|||||||
def_delegators :@output, :print, :puts
|
def_delegators :@output, :print, :puts
|
||||||
|
|
||||||
attr_reader :output, :keybinds
|
attr_reader :output, :keybinds
|
||||||
attr_accessor :verbose, :debug, :rc_path, :layout_class, :modifier,
|
attr_accessor :verbose, :debug, :rc_path, :modifier, :worker,
|
||||||
:worker
|
:layout, :layout_class
|
||||||
|
|
||||||
def initialize output
|
def initialize output
|
||||||
@output = output
|
@output = output
|
||||||
|
@ -32,6 +32,14 @@ module Uh
|
|||||||
@env.keybinds[translate_keysym *keysyms] = block
|
@env.keybinds[translate_keysym *keysyms] = block
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def layout obj
|
||||||
|
if obj.is_a? Class
|
||||||
|
@env.layout_class = obj
|
||||||
|
else
|
||||||
|
@env.layout = obj
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def worker type, **options
|
def worker type, **options
|
||||||
@env.worker = [type, options]
|
@env.worker = [type, options]
|
||||||
end
|
end
|
||||||
|
@ -70,19 +70,27 @@ module Uh
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#layout' do
|
describe '#layout' do
|
||||||
context 'when a layout class is set' do
|
let(:some_layout_class) { Class.new }
|
||||||
let(:some_layout) { 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
|
context 'when a layout is set' do
|
||||||
expect(env.layout).to be_an_instance_of some_layout
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when a layout class is not set' do
|
context 'when a layout class is set' do
|
||||||
it 'returns an instance of the default layout' do
|
before { env.layout_class = some_layout_class }
|
||||||
expect(env.layout).to be_an_instance_of ::Uh::Layout
|
|
||||||
|
it 'returns a new instance of this layout class' do
|
||||||
|
expect(env.layout).to be_an_instance_of some_layout_class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -85,6 +85,22 @@ module Uh
|
|||||||
end
|
end
|
||||||
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
|
describe '#worker' do
|
||||||
it 'sets the worker type in the env' do
|
it 'sets the worker type in the env' do
|
||||||
rc.worker :some_worker
|
rc.worker :some_worker
|
||||||
|
Loading…
x
Reference in New Issue
Block a user