Skip to content

Commit 2f861f9

Browse files
committed
# version 1.4.2:
- Fix access access to file on remote location (like hadoop/HDFS) - add test for accessing files over network - 2 spaces instead 4
1 parent 6f66091 commit 2f861f9

File tree

7 files changed

+3170
-66
lines changed

7 files changed

+3170
-66
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ os: osx
33
language: node_js
44
osx_image: xcode8.2
55
node_js:
6-
- '6'
6+
- '8'
77
env:
88
- CXX=g++-4.8
99
addons:

bin.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
#!/usr/bin/env node
22

33
const errMsg = require('./errorMsg')
4+
const version = require('./package.json').version
45
const 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

1924
process.on('uncaughtException', errMsg.printErr)
2025

2126
const img2ascii = require('./img2ascii')(argv)
22-
.pipe(process.stdout)
27+
.pipe(process.stdout)

errorMsg.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
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
}

img2ascii.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
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(/^http|0\.0|1..\.|localhost/)
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

0 commit comments

Comments
 (0)