From 917d080e2de197c6f4c96bc4f1b19413fdb42b02 Mon Sep 17 00:00:00 2001 From: Sam Symons Date: Sat, 28 Jun 2014 11:37:00 -0700 Subject: [PATCH 1/2] Add support for the --no-color option. The `colored` gem was replaced with `colorize`. It has a very similar API but comes with a few extra methods to remove or check colors. The Tabber class has had an options hash added to it, to make further additions easier. --- README.md | 1 + bin/synx | 3 ++- lib/synx.rb | 2 +- lib/synx/project.rb | 2 +- lib/synx/tabber.rb | 15 ++++++++------- spec/synx/tabber_spec.rb | 8 +++++++- synx.gemspec | 2 +- 7 files changed, 21 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 66e9ae1..6859a65 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ Synx supports the following options: ``` --prune, -p remove source files and image resources that are not referenced by the the xcode project + --no-color removes all color from the output --no-default-exclusions doesn't use the default exclusions of /Libraries, /Frameworks, and /Products --quiet, -q silence all output --exclusion, -e EXCLUSION ignore an Xcode group while syncing diff --git a/bin/synx b/bin/synx index 8b004c6..1aad4af 100755 --- a/bin/synx +++ b/bin/synx @@ -7,13 +7,14 @@ Clamp do parameter "xcodeproj", "Path to the xcodeproj", :attribute_name => :xcodeproj_path option ["--prune", "-p"], :flag, "remove source files and image resources that are not referenced by the the xcode project" + option "--no-color", :flag, "removes all color from the output" option "--no-default-exclusions", :flag, "doesn't use the default exclusions of /Libraries, /Frameworks, and /Products" option ["--quiet", "-q"], :flag, "silence all output" option ["--exclusion", "-e"], "EXCLUSION", "ignore an Xcode group while syncing", :multivalued => true def execute project = Synx::Project.open(xcodeproj_path) - project.sync(:prune => prune?, :quiet => quiet?, :no_default_exclusions => no_default_exclusions?, :group_exclusions => exclusion_list) + project.sync(:prune => prune?, :quiet => quiet?, :no_color => no_color?, :no_default_exclusions => no_default_exclusions?, :group_exclusions => exclusion_list) end end diff --git a/lib/synx.rb b/lib/synx.rb index 8931932..88f8124 100644 --- a/lib/synx.rb +++ b/lib/synx.rb @@ -7,7 +7,7 @@ require "synx/pbx_variant_group" require "synx/tabber" -require "colored" +require "colorize" module Synx end diff --git a/lib/synx/project.rb b/lib/synx/project.rb index e82d44c..46ad362 100644 --- a/lib/synx/project.rb +++ b/lib/synx/project.rb @@ -49,7 +49,7 @@ def set_options(options) self.group_exclusions |= options[:group_exclusions] if options[:group_exclusions] - Synx::Tabber.quiet = options[:quiet] + Synx::Tabber.options = options end private :set_options diff --git a/lib/synx/tabber.rb b/lib/synx/tabber.rb index c6be381..c2a5030 100644 --- a/lib/synx/tabber.rb +++ b/lib/synx/tabber.rb @@ -1,7 +1,7 @@ module Synx class Tabber - @@quiet = false + @@options = {} @@tabbing = 0 class << self @@ -20,19 +20,20 @@ def current def reset @@tabbing = 0 - self.quiet = false + self.options = {} end - def quiet=(quiet) - @@quiet = quiet + def options=(options = {}) + @@options = options end - def quiet? - @@quiet + def options + @@options end def puts(str="") - Kernel.puts (a_single_tab * @@tabbing) + str.to_s unless quiet? + str = str.uncolorize if options[:no_color] + Kernel.puts (a_single_tab * @@tabbing) + str.to_s unless options[:quiet] end def a_single_tab diff --git a/spec/synx/tabber_spec.rb b/spec/synx/tabber_spec.rb index 521b092..658f31d 100644 --- a/spec/synx/tabber_spec.rb +++ b/spec/synx/tabber_spec.rb @@ -55,11 +55,17 @@ end it "should not print anything if quiet is true" do - Synx::Tabber.quiet = true + Synx::Tabber.options = { quiet: true } Synx::Tabber.increase(3) expect(Kernel).to_not receive(:puts) Synx::Tabber.puts("Hello, world.") end + + it "should not print colors if no_color is true" do + Synx::Tabber.options = { no_color: true } + expect(Kernel).to receive(:puts).with("Hello, world.") + Synx::Tabber.puts("Hello, world.".red) + end end describe "::a_single_tab" do diff --git a/synx.gemspec b/synx.gemspec index a34864f..e2111ba 100644 --- a/synx.gemspec +++ b/synx.gemspec @@ -27,6 +27,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency "pry", "~> 0.9" spec.add_dependency "clamp", "~> 0.6" - spec.add_dependency "colored", "~> 1.2" + spec.add_dependency "colorize", "~> 0.7" spec.add_dependency "xcodeproj", "~> 0.17" end From 415b1de055d25e189dd4c51b70c08168602e5172 Mon Sep 17 00:00:00 2001 From: Sam Symons Date: Mon, 30 Jun 2014 13:58:23 -0700 Subject: [PATCH 2/2] Test that omitting the no_color option will allow colors to be printed. --- spec/synx/tabber_spec.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/synx/tabber_spec.rb b/spec/synx/tabber_spec.rb index 658f31d..1caf815 100644 --- a/spec/synx/tabber_spec.rb +++ b/spec/synx/tabber_spec.rb @@ -56,11 +56,15 @@ it "should not print anything if quiet is true" do Synx::Tabber.options = { quiet: true } - Synx::Tabber.increase(3) expect(Kernel).to_not receive(:puts) Synx::Tabber.puts("Hello, world.") end + it "should print colors if no_color is false or not present" do + expect(Kernel).to receive(:puts).with("\e[0;31;49mHello, world.\e[0m") + Synx::Tabber.puts("Hello, world.".red) + end + it "should not print colors if no_color is true" do Synx::Tabber.options = { no_color: true } expect(Kernel).to receive(:puts).with("Hello, world.")