Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Avoid double outputs clear on file changes

  • Loading branch information...
commit 3c6f508b7da3a7f1bf6a9acbb35f707f0b8c23fd 1 parent 560515a
Thibaud Guillaume-Gentil authored
View
6 lib/guard.rb
@@ -47,7 +47,7 @@ def setup(options = {})
@runner = Runner.new
@allow_stop = Listen::Turnstile.new
- UI.clear
+ UI.clear(force: true)
deprecated_options_warning
setup_groups
@@ -180,7 +180,7 @@ def stop
#
def reload(scopes)
within_preserved_state do
- UI.clear
+ UI.clear(force: true)
UI.action_with_scopes('Reload', scopes)
Dsl.reevaluate_guardfile if scopes.empty?
runner.run(:reload, scopes)
@@ -193,7 +193,7 @@ def reload(scopes)
#
def run_all(scopes)
within_preserved_state do
- UI.clear
+ UI.clear(force: true)
UI.action_with_scopes('Run', scopes)
runner.run(:run_all, scopes)
end
View
1  lib/guard/runner.rb
@@ -60,6 +60,7 @@ def run(task, scopes = {})
# @param [Array<String>] removed the removed paths.
#
def run_on_changes(modified, added, removed)
+ UI.clearable
scoped_guards do |guard|
modified_paths = Watcher.match_files(guard, modified)
added_paths = Watcher.match_files(guard, added)
View
15 lib/guard/ui.rb
@@ -78,10 +78,19 @@ def reset_line
STDERR.print(color_enabled? ? "\r\e[0m" : "\r\n")
end
- # Clear the output.
+ # Clear the output if clearable.
#
- def clear
- system('clear;') if ::Guard.options[:clear]
+ def clear(options = {})
+ if ::Guard.options[:clear] && (@clearable || options[:force])
+ @clearable = false
+ system('clear;')
+ end
+ end
+
+ # Allow the screen to be cleared again.
+ #
+ def clearable
+ @clearable = true
end
# Show a scoped action message.
View
5 spec/guard/runner_spec.rb
@@ -125,6 +125,11 @@ class ::Guard::Bar2 < ::Guard::Guard; end
watcher_module.stub(:match_files) { [] }
}
+ it "always calls UI.clearable" do
+ Guard::UI.should_receive(:clearable)
+ subject.run_on_changes(*changes)
+ end
+
context 'when clearable' do
before { subject.stub(:clearable?) { true } }
View
40 spec/guard/ui_spec.rb
@@ -0,0 +1,40 @@
+require 'spec_helper'
+
+describe Guard::UI do
+
+ describe "clear" do
+ context "Guard.options[:clear] is true" do
+ before { ::Guard.stub(:options) { { clear: true } } }
+
+ it "clears the outputs if clearable" do
+ Guard::UI.clearable
+ Guard::UI.should_receive(:system).with('clear;')
+ Guard::UI.clear
+ end
+
+ it "doesn't clear the output if already cleared" do
+ Guard::UI.stub(:system)
+ Guard::UI.clear
+ Guard::UI.should_not_receive(:system).with('clear;')
+ Guard::UI.clear
+ end
+
+ it "clears the outputs if forced" do
+ Guard::UI.stub(:system)
+ Guard::UI.clear
+ Guard::UI.should_receive(:system).with('clear;')
+ Guard::UI.clear(force: true)
+ end
+ end
+
+ context "Guard.options[:clear] is false" do
+ before { ::Guard.stub(:options) { { clear: false } } }
+
+ it "doesn't clear the output" do
+ Guard::UI.should_not_receive(:system).with('clear;')
+ Guard::UI.clear
+ end
+ end
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.