File tree Expand file tree Collapse file tree 3 files changed +29
-9
lines changed Expand file tree Collapse file tree 3 files changed +29
-9
lines changed Original file line number Diff line number Diff line change @@ -8,12 +8,15 @@ const { readFileSync } = require('fs')
88cli
99 . version ( `0.1.0` )
1010 . usage ( `[options] <file1> <file2>` )
11+ . option ( '--color' , "Force color output ON" )
12+ . option ( '--no-color' , "Force color output OFF" )
13+ . option ( '--columns [columns]' , "Specify width output override." )
1114 . on ( `--help` , ( ) => {
1215 console . log ( `` )
1316 console . log ( ` Example:` )
1417 console . log ( `` )
1518 console . log ( ` $ splitdiff file1 file2` )
16- console . log ( ` $ git --no-pager diff file1 file2 | splitdiff` )
19+ console . log ( ` $ git --no-pager diff file1 file2 | splitdiff [options] ` )
1720 console . log ( `` )
1821 } )
1922 . parse ( process . argv )
@@ -34,17 +37,23 @@ try {
3437 } )
3538 process . stdin . on ( 'end' , ( ) => {
3639 if ( data !== '' ) {
37- console . log ( splitPatch ( data , { } ) )
40+ let opts = { }
41+
42+ if ( cli . columns ) {
43+ opts . columns = cli . columns
44+ }
45+
46+ console . log ( splitPatch ( data , opts ) )
3847 }
3948 } )
4049
41- }
50+ }
4251 else {
4352 console . log (
4453 splitDiffStrings (
4554 cli . args [ 0 ] + `\n\n` + readFileSync ( cli . args [ 0 ] , { encoding : `utf8` } ) ,
4655 cli . args [ 1 ] + `\n\n` + readFileSync ( cli . args [ 1 ] , { encoding : `utf8` } ) ,
47- {
56+ {
4857 diffType : `diffLines` ,
4958 lineNumbers : true ,
5059 lineOffset : 2
Original file line number Diff line number Diff line change @@ -2,10 +2,16 @@ const diff = require(`diff`)
22const chalk = require ( `chalk` )
33const stripAnsi = require ( `strip-ansi` )
44
5- const terminalWidth = ( process . stdout && process . stdout . columns ) ? process . stdout . columns : 80
6- const colwidth = Math . floor ( ( terminalWidth ) / 2 )
5+ let terminalWidth = ( process . stdout && process . stdout . columns ) ? process . stdout . columns : 80
6+ let colwidth
77const bgColor = chalk . bgRgb ( 15 , 15 , 15 )
88
9+ function updateColWidth ( ) {
10+ colwidth = Math . floor ( ( terminalWidth ) / 2 )
11+ }
12+
13+ updateColWidth ( )
14+
915function repeatChar ( char , times ) {
1016 let ret = ''
1117 while ( -- times >= 0 ) ret += char
@@ -247,10 +253,15 @@ module.exports = {
247253 return pair . combine ( )
248254 } ,
249255
250- splitPatch ( patch ) {
256+ splitPatch ( patch , options ) {
251257 let parsedPatch = diff . parsePatch ( patch )
252258 let output = [ ]
253259
260+ if ( options . columns ) {
261+ terminalWidth = options . columns
262+ updateColWidth ( )
263+ }
264+
254265 for ( let patch of parsedPatch ) {
255266
256267 let pair = new Pair (
@@ -300,7 +311,7 @@ module.exports = {
300311 pair . right . currentSourceLine = line
301312 pair . right . drawLine ( true )
302313 }
303- }
314+ }
304315
305316 output . push ( pair . combine ( ) )
306317 output . push ( '' )
You can’t perform that action at this time.
0 commit comments