Commit 7003e433 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Implement --color and --no-color options.

To force terminal colors on/off.

Fixes: #348
parent bcf309d7
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -10,8 +10,14 @@ module JsDuck
    # Set to true to enable verbose logging
    attr_accessor :verbose

    # Set true to force colored output.
    # Set false to force no colors.
    attr_accessor :colors

    def initialize
      @verbose = false
      @colors = nil

      @warning_docs = [
        [:global, "Member doesn't belong to any class"],
        [:inheritdoc, "@inheritdoc referring to unknown class or member"],
@@ -154,7 +160,7 @@ module JsDuck
    # Only does color output when STDERR is attached to TTY
    # i.e. is not piped/redirected.
    def paint(color_name, msg)
      if Util::OS.windows? || !$stderr.tty?
      if @colors == false || @colors == nil && (Util::OS.windows? || !$stderr.tty?)
        msg
      else
        COLORS[color_name] + msg + CLEAR
+9 −0
Original line number Diff line number Diff line
@@ -609,6 +609,15 @@ module JsDuck
          end
        end

        opts.on('--[no-]color',
          "Turn on/off colorized terminal output.",
          "",
          "By default the colored output is on, but gets disabled",
          "automatically when output is not an interactive terminal",
          "(or when running on Windows system).") do |on|
          Logger.colors = on
        end

        opts.on('-p', '--processes=COUNT',
          "The number of parallel processes to use.",
          "",