Permalink
Browse files

Add a “focus” option for splits (fixes #22)

  • Loading branch information...
1 parent 664358c commit ffe5778b5f4974bd2270036d09cd2911bc470dd9 @remiprev committed Jun 30, 2012
View
@@ -87,7 +87,8 @@ Every window must define an array of splits that will be created within it. A ve
* `cmd` (the commands to initially execute in the split)
* `width` (the split width, in percentage)
* `height` (the split width, in percentage)
-* `target` (the split to set focus on, before creating the current one)
+* `target` (the split to set focus on before creating the current one)
+* `focus` (the split to set focus on after initializing all the splits for a window)
#### Example
@@ -101,6 +102,7 @@ windows:
splits:
- cmd: "git status"
- cmd: "bundle exec rails server --port 4000"
+ focus: true
width: 50
- cmd:
- "sudo service memcached start"
@@ -4,6 +4,7 @@ windows:
- cmd: "echo 'first split'"
- cmd: "echo 'second split'"
width: 50
+ focus: true
- cmd: "echo 'fourth split'"
height: 50
target: bottom-right
@@ -23,8 +23,6 @@ def generate_commands # {{{
commands = []
commands << "tmux rename-session \"#{@name}\"" unless @name.nil?
commands << @windows.map(&:generate_commands)
- commands << "tmux select-pane -t 0"
- commands
end # }}}
end
@@ -3,7 +3,7 @@ class Layout
# This class represents a split within a tmux window
class Split
- attr_reader :width, :height, :cmd, :index, :target
+ attr_reader :width, :height, :cmd, :index, :target, :focus
# Initialize a new tmux split
#
@@ -16,6 +16,7 @@ def initialize(window, index, attrs={}) # {{{
@width = attrs["width"]
@cmd = attrs["cmd"]
@target = attrs["target"]
+ @focus = attrs["focus"] || false
@window = window
@index = index
@@ -47,6 +47,8 @@ def generate_commands # {{{
commands << "tmux set-window-option #{option} #{value}"
end
+ commands << "tmux select-pane -t #{@splits.map(&:focus).index(true) || 0}"
+
commands
end # }}}
@@ -15,6 +15,7 @@ two-windows:
- "echo 'bar in an array'"
target: bottom-right
- cmd: "echo 'bar again'"
+ focus: true
width: 50
# Simple two windows layout with filters
View
@@ -71,6 +71,12 @@
session.windows.last.splits[0].cmd.first.should == "echo 'bar'"
session.windows.last.splits[0].cmd.last.should == "echo 'bar in an array'"
end # }}}
+
+ it "handles focused splits" do # {{{
+ session = @layout.compile!
+ session.windows.last.splits[1].focus.should be_true
+ session.windows.last.splits[0].focus.should be_false
+ end # }}}
end # }}}
describe "filters" do # {{{
@@ -126,13 +132,20 @@
@layout = Teamocil::Layout.new(layouts["two-windows"], {})
end # }}}
- it "should generate commands" do #{{{
+ it "should generate split commands" do #{{{
session = @layout.compile!
commands = session.windows.last.splits[0].generate_commands
commands.length.should == 2
commands.first.should == "tmux send-keys -t 0 \"export TEAMOCIL=1 && cd \"/bar\" && echo 'bar' && echo 'bar in an array'\""
commands.last.should == "tmux send-keys -t 0 Enter"
end # }}}
+
+ it "should generate window commands" do #{{{
+ session = @layout.compile!
+ commands = session.windows.last.generate_commands
+ commands.first.should == "tmux new-window -n \"bar\""
+ commands.last.should == "tmux select-pane -t 1"
+ end # }}}
end
end

0 comments on commit ffe5778

Please sign in to comment.