lib/taskjuggler/Tj3AppBase.rb in taskjuggler-3.0.0 vs lib/taskjuggler/Tj3AppBase.rb in taskjuggler-3.1.0

- old
+ new

@@ -1,24 +1,26 @@ #!/usr/bin/env ruby -w # encoding: UTF-8 # # = Tj3AppBase.rb -- The TaskJuggler III Project Management Software # -# Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011 +# Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011, 2012 # by Chris Schlaeger <chris@linux.com> # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # require 'rubygems' require 'optparse' +require 'term/ansicolor' require 'taskjuggler/Tj3Config' require 'taskjuggler/RuntimeConfig' require 'taskjuggler/TjTime' require 'taskjuggler/TextFormatter' +require 'taskjuggler/Log' class TaskJuggler class TjRuntimeError < RuntimeError end @@ -33,10 +35,15 @@ # Show some progress information by default @silent = false @configFile = nil @mandatoryArgs = '' @mininumRubyVersion = '1.9.2' + + # If stdout is not a tty, we don't use ANSI escape sequences to color + # the terminal output. Additionally, we have the --no-color option to + # force colors off in case this does not work properly. + Term::ANSIColor.coloring = STDOUT.tty? end def processArguments(argv) @opts = OptionParser.new @opts.summary_width = @optsSummaryWidth @@ -57,9 +64,19 @@ @configFile = arg end @opts.on('--silent', format("Don't show program and progress information")) do @silent = true + TaskJuggler::Log.silent = true + end + @opts.on('--no-color', + format(<<'EOT' +Don't use ANSI contol sequences to color the terminal output. Colors should +only be used when spooling to an ANSI terminal. In case the detection fails, +you can this option to force colors to be off. +EOT + )) do + Term::ANSIColor::coloring = false end @opts.on('--debug', format('Enable Ruby debug mode')) do $DEBUG = true end