Index: trunk/extensions/VisualEditor/tests/parser/dumpGrepper.js |
— | — | @@ -27,6 +27,11 @@ |
28 | 28 | description: 'Case-insensitive matching', |
29 | 29 | 'boolean': true, |
30 | 30 | 'default': false |
| 31 | + }, |
| 32 | + 'color': { |
| 33 | + description: 'Highlight matched substring using color', |
| 34 | + 'boolean': true, |
| 35 | + 'default': true |
31 | 36 | } |
32 | 37 | } ).argv; |
33 | 38 | |
— | — | @@ -43,12 +48,14 @@ |
44 | 49 | reader.on( 'revision', grepper.grepRev.bind( grepper ) ); |
45 | 50 | grepper.on( 'match', function ( revision, bits ) { |
46 | 51 | console.log( 'Match:' + revision.page.title ); |
47 | | - for ( var i = 0, l = bits.length; i < l-1; i++ ) { |
48 | | - var m = bits[i+1].match( re )[0]; |
49 | | - console.log( 'm: ' + m ); |
50 | | - console.log( bits[i].substr(-40) + m.green + bits[i+1].substr( m.length, 40 ) ); |
| 52 | + for ( var i = 0, l = bits.length; i < l-1; i += 2 ) { |
| 53 | + var m = bits[i+1]; |
| 54 | + if ( argv.color ) { |
| 55 | + console.log( bits[i].substr(-40) + m.green + bits[i+2].substr( 0, 40 ) ); |
| 56 | + } else { |
| 57 | + console.log( bits[i].substr(-40) + m + bits[i+2].substr( 0, 40 ) ); |
| 58 | + } |
51 | 59 | } |
52 | | - //console.log( bits.map( function ( s ) { return s.substr(0, 40) } ) ); |
53 | 60 | } ); |
54 | 61 | process.stdin.setEncoding('utf8'); |
55 | 62 | process.stdin.on('data', reader.push.bind(reader) ); |