module 'use strict' ; import util = require ( 'util' ) ; import events = require ( 'events' ) ; import _ = require ( './lodash' ) ; var step = '  ' ; var padding = ' ' ; var colors = { skip : 'yellow' , force : 'yellow' , create : 'green' , invoke : 'bold' , conflict : 'red' , identical : 'cyan' , info : 'gray' } ; function pad ( status ) { var max = 'identical' . length ; var delta = max - status . length ; return delta ? new Array ( delta + 1 ) . join ( ' ' ) + status : status ; } function formatter ( msg , ctx ) { while ( msg . indexOf ( '%' ) !== - 1 ) { var start = msg . indexOf ( '%' ) ; var end = msg . indexOf ( ' ' , start ) ; if ( end === - 1 ) { end = msg . length ; } msg = msg . slice ( 0 , start ) + ctx [ msg . slice ( start + 1 , end ) ] + msg . slice ( end ) ; } return msg ; } module . exports = function logger ( ) { var log = function log ( msg , ctx ) { } ; _ . extend ( log , events . EventEmitter . prototype ) ; log . write = function ( msg ) { if ( ! msg ) { return this . write ( '\n' ) ; } console . log ( util . format . apply ( util , arguments ) ) ; return this ; } ; log . writeln = function ( ) { return this . write . apply ( this , arguments ) . write ( ) ; } ; log . ok = function ( ) { this . write ( ' ' + util . format . apply ( util , arguments ) + '\n' ) ; return this ; } ; log . error = function ( ) { this . write ( ' ' + util . format . apply ( util , arguments ) + '\n' ) ; return this ; } ; log . on ( 'up' , function ( ) { padding = padding + step ; } ) ; log . on ( 'down' , function ( ) { padding = padding . replace ( step , '' ) ; } ) ; var messages = { skip : < string [ ] > [ ] , force : < string [ ] > [ ] , create : < string [ ] > [ ] , invoke : < string [ ] > [ ] , conflict : < string [ ] > [ ] , identical : < string [ ] > [ ] , info : < string [ ] > [ ] } ; log . messages = messages ; Object . keys ( colors ) . forEach ( function ( status ) { log [ status ] = function ( ) { var color = colors [ status ] ; messages [ status ] . push ( _ . toArray ( < any > arguments ) . join ( ' ' ) ) ; this . write ( util . format . apply ( util , [ status ] . concat ( Array . prototype . slice ( < any > arguments ) ) ) + '\n' ) ; return this ; } ; } ) ; log . table = function ( opts ) { var tableData = [ ] ; opts = Array . isArray ( opts ) ? { rows : opts } : opts ; opts . rows = opts . rows || [ ] ; opts . rows . forEach ( function ( row ) { tableData . push ( row ) ; } ) ; } ; return log ; } ;