Skip to content
Browse files

Use more intuitive names for colorize funcs

  • Loading branch information...
1 parent aac559d commit 90f89574bbc73a30ba0111cfc2218c454f9a601a @andreyvit committed Nov 23, 2012
Showing with 18 additions and 18 deletions.
  1. +2 −2 lib/cli.iced
  2. +16 −16 lib/colorize.iced
View
4 lib/cli.iced
@@ -2,7 +2,7 @@ fs = require 'fs'
tty = require 'tty'
{ diff } = require './index'
-{ colorizeWithAnsiEscapes} = require './colorize'
+{ colorize } = require './colorize'
module.exports = (argv) ->
options = require('dreamopt') [
@@ -43,4 +43,4 @@ module.exports = (argv) ->
process.stdout.write JSON.stringify(result, null, 2)
else
process.stderr.write "Producing colored output...\n" if options.verbose
- process.stdout.write colorizeWithAnsiEscapes(result, color: options.color)
+ process.stdout.write colorize(result, color: options.color)
View
32 lib/colorize.iced
@@ -8,24 +8,24 @@ Theme =
'-': color.red
-subcolorize = (key, diff, output, color, indent) ->
+subcolorizeToCallback = (key, diff, output, color, indent) ->
prefix = if key then "#{key}: " else ''
subindent = indent + ' '
switch extendedTypeOf(diff)
when 'object'
if ('__old' of diff) and ('__new' of diff) and (Object.keys(diff).length is 2)
- subcolorize(key, diff.__old, output, '-', indent)
- subcolorize(key, diff.__new, output, '+', indent)
+ subcolorizeToCallback(key, diff.__old, output, '-', indent)
+ subcolorizeToCallback(key, diff.__new, output, '+', indent)
else
output color, "#{indent}#{prefix}{"
for own subkey, subvalue of diff
if m = subkey.match /^(.*)__deleted$/
- subcolorize(m[1], subvalue, output, '-', subindent)
+ subcolorizeToCallback(m[1], subvalue, output, '-', subindent)
else if m = subkey.match /^(.*)__added$/
- subcolorize(m[1], subvalue, output, '+', subindent)
+ subcolorizeToCallback(m[1], subvalue, output, '+', subindent)
else
- subcolorize(subkey, subvalue, output, color, subindent)
+ subcolorizeToCallback(subkey, subvalue, output, color, subindent)
output color, "#{indent}}"
when 'array'
@@ -39,40 +39,40 @@ subcolorize = (key, diff, output, color, indent) ->
if looksLikeDiff
for [op, subvalue] in diff
if op is ' ' && !subvalue?
- subcolorize('', '...', output, ' ', subindent)
+ subcolorizeToCallback('', '...', output, ' ', subindent)
else
unless op in [' ', '~', '+', '-']
throw new Error("Unexpected op '#{op}' in #{JSON.stringify(diff, null, 2)}")
op = ' ' if op is '~'
- subcolorize('', subvalue, output, op, subindent)
+ subcolorizeToCallback('', subvalue, output, op, subindent)
else
for subvalue in diff
- subcolorize('', subvalue, output, color, subindent)
+ subcolorizeToCallback('', subvalue, output, color, subindent)
output color, "#{indent}]"
else
output(color, indent + prefix + JSON.stringify(diff))
-colorize = (diff, output) ->
- subcolorize('', diff, output, ' ', '')
+colorizeToCallback = (diff, output) ->
+ subcolorizeToCallback('', diff, output, ' ', '')
colorizeToArray = (diff) ->
output = []
- colorize(diff, (color, line) -> output.push "#{color}#{line}")
+ colorizeToCallback(diff, (color, line) -> output.push "#{color}#{line}")
return output
-colorizeWithAnsiEscapes = (diff, options={}) ->
+colorize = (diff, options={}) ->
output = []
- colorize diff, (color, line) ->
+ colorizeToCallback diff, (color, line) ->
if options.color
- output.push Theme[color]("#{color}#{line}") + "\n"
+ output.push (options.theme?[color] ? Theme[color])("#{color}#{line}") + "\n"
else
output.push "#{color}#{line}\n"
return output.join('')
-module.exports = { colorize, colorizeToArray, colorizeWithAnsiEscapes }
+module.exports = { colorize, colorizeToArray, colorizeToCallback }

0 comments on commit 90f8957

Please sign in to comment.
Something went wrong with that request. Please try again.