Skip to content

Commit

Permalink
[dsl] add ( ) if background operator exists
Browse files Browse the repository at this point in the history
  • Loading branch information
achiurizo committed Apr 7, 2011
1 parent 87e237e commit ca7a685
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 4 additions & 2 deletions lib/terminitor/dsl.rb
Expand Up @@ -45,12 +45,14 @@ def window(options = {}, &block)
# run 'brew update'
def run(*commands)
# if we are in a window context, append commands to default tab.
if @_context.is_a?(Hash) && @_context[:tabs]
if @_context.is_a?(Hash) && @_context[:tabs]
current = @_context[:tabs]['default'][:commands]
else
current = @_context
end
current << commands.map { |c| "#{c}" }.join(" && ")
current << commands.map do |c|
c =~ /&$/ ? "(#{c})" : c
end.join(" && ")
end

# runs commands before each tab in window context
Expand Down
12 changes: 6 additions & 6 deletions test/dsl_test.rb
Expand Up @@ -22,35 +22,35 @@
setup { topic[:tabs] }

asserts([:[], 'tab2']).equivalent_to({
:commands=>["(echo 'named tab')", "(ls)"],
:commands=>["echo 'named tab'", "ls"],
:options => {
:name => "named tab",
:settings=>"Grass"
}
})

asserts([:[], 'tab1']).equivalent_to({
:commands=>["echo 'first tab'", "echo 'of window'", "echo 'than now'"]
:commands=>["echo 'first tab'", "motion &", "echo 'than now'"]
})

asserts([:[],'tab3']).equivalent_to({
:commands=>["(top)"],
:commands=>["top","(mate &) && (gitx &) && cd /this"],
:options =>{
:name => "a tab",
:settings => "Pro"
}
})

asserts([:[],'tab4']).equivalent_to({
:commands=>["(ls)"],
:commands=>["ls"],
:options =>{
:name => "another named tab",
:settings => "Grass"
}
})

asserts([:[],'default']).equivalent_to({
:commands=>['(whoami) && (who) && (ls)']
:commands=>['whoami && who && ls']
})
end

Expand All @@ -59,7 +59,7 @@
context "with 'window2' key" do
setup { topic['window2'] }

asserts([:[],:before]).equals ['(whoami)']
asserts([:[],:before]).equals ['whoami']

context "with :tabs" do
setup { topic[:tabs] }
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/bar.term
Expand Up @@ -10,7 +10,7 @@ window :size => [70,30] do
before 'cd /path'

run "whoami","who", "ls"
tab "echo 'first tab'", "echo 'of window'", "echo 'than now'"
tab "echo 'first tab'", "motion &", "echo 'than now'"

tab :name => "named tab", :settings => "Grass" do
run "echo 'named tab'"
Expand All @@ -19,6 +19,7 @@ window :size => [70,30] do

tab "a tab", :settings => "Pro" do
run "top"
run "mate &", "gitx &", "cd /this"
end

tab("another named tab", :settings => 'Grass') { run "ls" }
Expand Down

0 comments on commit ca7a685

Please sign in to comment.