Color output #4
5 changed files with 13 additions and 1 deletions
|
@ -2,11 +2,13 @@ PATH
|
|||
remote: .
|
||||
specs:
|
||||
format-staged (0.0.3)
|
||||
colorize
|
||||
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
ast (2.4.2)
|
||||
colorize (0.8.1)
|
||||
parallel (1.22.1)
|
||||
parser (3.1.2.0)
|
||||
ast (~> 2.4.1)
|
||||
|
|
|
@ -57,6 +57,10 @@ parser = OptionParser.new do |opt|
|
|||
puts FormatStaged::VERSION
|
||||
exit
|
||||
end
|
||||
|
||||
opt.on('--[no-]color', 'Colorizes output') do |value|
|
||||
parameters[:color_output] = value
|
||||
end
|
||||
end
|
||||
|
||||
parser.parse!
|
||||
|
|
|
@ -16,6 +16,8 @@ Gem::Specification.new do |s|
|
|||
s.homepage = 'https://github.com/5sw/format-staged'
|
||||
s.license = 'MIT'
|
||||
s.required_ruby_version = '~> 2.7'
|
||||
|
||||
s.add_dependency 'colorize'
|
||||
|
||||
s.add_development_dependency 'rake', '~> 13.0'
|
||||
s.add_development_dependency 'rubocop', '~> 1.29'
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'English'
|
||||
|
||||
class FormatStaged
|
||||
def get_output(*args, lines: true, silent: false)
|
||||
puts "> #{args.join(' ')}" if @verbose
|
||||
|
|
|
@ -5,18 +5,21 @@ require 'format-staged/version'
|
|||
require 'format-staged/entry'
|
||||
require 'format-staged/io'
|
||||
require 'shellwords'
|
||||
require 'colorize'
|
||||
|
||||
##
|
||||
# Runs staged changes through a formatting tool
|
||||
class FormatStaged
|
||||
attr_reader :formatter, :patterns, :update, :write, :verbose
|
||||
|
||||
def initialize(formatter:, patterns:, update: true, write: true, verbose: true)
|
||||
def initialize(formatter:, patterns:, update: true, write: true, verbose: true, color_output: nil)
|
||||
@formatter = formatter
|
||||
@patterns = patterns
|
||||
@update = update
|
||||
@write = write
|
||||
@verbose = verbose
|
||||
|
||||
String.disable_colorization = !(color_output || STDOUT.isatty)
|
||||
end
|
||||
|
||||
def run
|
||||
|
|
Loading…
Add table
Reference in a new issue