File tree Expand file tree Collapse file tree 7 files changed +3170
-66
lines changed
Expand file tree Collapse file tree 7 files changed +3170
-66
lines changed Original file line number Diff line number Diff line change 33language : node_js
44osx_image : xcode8.2
55node_js :
6- - ' 6 '
6+ - ' 8 '
77env :
88 - CXX=g++-4.8
99addons :
Original file line number Diff line number Diff line change 11#!/usr/bin/env node
22
33const errMsg = require ( './errorMsg' )
4+ const version = require ( './package.json' ) . version
45const argv = require ( 'yargs' )
5- . usage ( 'Usage: $0 [url|file] --cols [num] --ratio [num]' )
6- . option ( 'c' , {
7- alias : 'cols' ,
8- default : 80 ,
9- describe : 'Number of columns in terminal'
10- } )
11- . option ( 'r' , {
12- alias : 'ratio' ,
13- default : 1 ,
14- describe : 'Aspect ratio. Try 0.5 to flatten image\nand 2 to lengthen image'
15- } )
16- . demand ( 1 )
17- . argv
6+ . usage ( 'Usage: $0 [url|file] --cols [num] --ratio [num]' )
7+ . option ( 'c' , {
8+ alias : 'cols' ,
9+ default : 80 ,
10+ describe : 'Number of columns in terminal'
11+ } )
12+ . option ( 'r' , {
13+ alias : 'ratio' ,
14+ default : 1 ,
15+ describe : 'Aspect ratio. Try 0.5 to flatten image\nand 2 to lengthen image'
16+ } )
17+ . option ( 'v' , {
18+ alias : 'version' ,
19+ describe : `Prints version: ${ version } `
20+ } )
21+ . demand ( 1 )
22+ . argv
1823
1924process . on ( 'uncaughtException' , errMsg . printErr )
2025
2126const img2ascii = require ( './img2ascii' ) ( argv )
22- . pipe ( process . stdout )
27+ . pipe ( process . stdout )
Original file line number Diff line number Diff line change 1- module . exports . printErr = function ( err ) {
1+ module . exports . printErr = ( err ) => {
22
3- console . error ( 'Error:' )
3+ console . error ( 'Error:' )
44
5- if ( 'ENOENT' === err . code && 'open' !== err . syscall ) {
6- console . error ( 'Please install graphicsmagick:' )
7- console . error ( 'brew install graphicsmagick' )
8- console . error ( 'sudo apt-get install graphicsmagick' )
9- }
5+ if ( 'ENOENT' === err . code && 'open' !== err . syscall ) {
6+ console . error ( 'Please install graphicsmagick:' )
7+ console . error ( 'brew install graphicsmagick' )
8+ console . error ( 'sudo apt-get install graphicsmagick' )
9+ }
1010
11- if ( 'ENOTFOUND' === err . code ) {
12- console . log ( 'Please check your uri / network connection' )
13- }
14-
15- console . dir ( err . message )
11+ if ( 'ENOTFOUND' === err . code ) {
12+ console . log ( 'Please check your uri / network connection' )
13+ }
1614
15+ console . dir ( err . message )
1716}
Original file line number Diff line number Diff line change 1- module . exports = function img2ascii ( config ) {
2- const argv = {
3- ratio : config . ratio ,
4- cols : config . cols ,
5- _ : config . _ || [ config . img ]
6- }
7- const gm = require ( 'gm' )
8- const pictureTube = require ( 'picture-tube' )
1+ module . exports = ( config ) => {
2+ const argv = {
3+ ratio : config . ratio ,
4+ cols : config . cols ,
5+ _ : config . _ || [ config . img ]
6+ }
7+ const gm = require ( 'gm' )
8+ const pictureTube = require ( 'picture-tube' )
99
10- const isUrl = ( str ) => str . match ( ' http|0.0|localhost' )
10+ const isUrl = ( str ) => str . match ( / ^ h t t p | 0 \ .0 | 1 .. \. | l o c a l h o s t / )
1111
12- const pipeIn = ( isUrl ( argv . _ [ 0 ] ) ?
13- require ( 'request-promise' ) ( argv . _ [ 0 ] ) :
14- require ( 'fs' ) . createReadStream ( argv . _ [ 0 ] ) )
12+ const pipeIn = ( isUrl ( argv . _ [ 0 ] ) ?
13+ require ( 'request-promise' ) ( argv . _ [ 0 ] ) :
14+ require ( 'fs' ) . createReadStream ( argv . _ [ 0 ] ) )
1515
16- return gm ( pipeIn )
17- // magic fix of picture tube ratios
18- . resizeExact ( 300 * 1.2 , 300 * argv . ratio )
19- . stream ( 'png' )
20- . pipe ( pictureTube ( { cols : argv . cols } ) )
16+ return gm ( pipeIn )
17+ // magic fix of picture tube ratios
18+ . resizeExact ( 300 * 1.2 , 300 * argv . ratio )
19+ . stream ( 'png' )
20+ . pipe ( pictureTube ( { cols : argv . cols } ) )
2121}
2222
You can’t perform that action at this time.
0 commit comments