Skip to content

Commit

Permalink
# version 1.4.2:
Browse files Browse the repository at this point in the history
 - Fix access access to file on remote location (like hadoop/HDFS)
 - add test for accessing files over network
 - 2 spaces instead 4
  • Loading branch information
syzer committed Mar 1, 2018
1 parent 6f66091 commit 2f861f9
Show file tree
Hide file tree
Showing 7 changed files with 3,170 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ os: osx
language: node_js
osx_image: xcode8.2
node_js:
- '6'
- '8'
env:
- CXX=g++-4.8
addons:
Expand Down
33 changes: 19 additions & 14 deletions bin.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
#!/usr/bin/env node

const errMsg = require('./errorMsg')
const version = require('./package.json').version
const argv = require('yargs')
.usage('Usage: $0 [url|file] --cols [num] --ratio [num]')
.option('c', {
alias: 'cols',
default: 80,
describe: 'Number of columns in terminal'
})
.option('r', {
alias: 'ratio',
default: 1,
describe: 'Aspect ratio. Try 0.5 to flatten image\nand 2 to lengthen image'
})
.demand(1)
.argv
.usage('Usage: $0 [url|file] --cols [num] --ratio [num]')
.option('c', {
alias: 'cols',
default: 80,
describe: 'Number of columns in terminal'
})
.option('r', {
alias: 'ratio',
default: 1,
describe: 'Aspect ratio. Try 0.5 to flatten image\nand 2 to lengthen image'
})
.option('v', {
alias: 'version',
describe: `Prints version: ${version}`
})
.demand(1)
.argv

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

const img2ascii = require('./img2ascii')(argv)
.pipe(process.stdout)
.pipe(process.stdout)
23 changes: 11 additions & 12 deletions errorMsg.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
module.exports.printErr = function (err) {
module.exports.printErr = (err) => {

console.error('Error:')
console.error('Error:')

if ('ENOENT' === err.code && 'open' !== err.syscall) {
console.error('Please install graphicsmagick:')
console.error('brew install graphicsmagick')
console.error('sudo apt-get install graphicsmagick')
}
if ('ENOENT' === err.code && 'open' !== err.syscall) {
console.error('Please install graphicsmagick:')
console.error('brew install graphicsmagick')
console.error('sudo apt-get install graphicsmagick')
}

if ('ENOTFOUND' === err.code) {
console.log('Please check your uri / network connection')
}

console.dir(err.message)
if ('ENOTFOUND' === err.code) {
console.log('Please check your uri / network connection')
}

console.dir(err.message)
}
34 changes: 17 additions & 17 deletions img2ascii.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
module.exports = function img2ascii(config) {
const argv = {
ratio: config.ratio,
cols: config.cols,
_: config._ || [config.img]
}
const gm = require('gm')
const pictureTube = require('picture-tube')
module.exports = (config) => {
const argv = {
ratio: config.ratio,
cols: config.cols,
_: config._ || [config.img]
}
const gm = require('gm')
const pictureTube = require('picture-tube')

const isUrl = (str) => str.match('http|0.0|localhost')
const isUrl = (str) => str.match(/^http|0\.0|1..\.|localhost/)

const pipeIn = (isUrl(argv._[0]) ?
require('request-promise')(argv._[0]) :
require('fs').createReadStream(argv._[0]))
const pipeIn = (isUrl(argv._[0]) ?
require('request-promise')(argv._[0]) :
require('fs').createReadStream(argv._[0]))

return gm(pipeIn)
// magic fix of picture tube ratios
.resizeExact(300 * 1.2, 300 * argv.ratio)
.stream('png')
.pipe(pictureTube({cols: argv.cols}))
return gm(pipeIn)
// magic fix of picture tube ratios
.resizeExact(300 * 1.2, 300 * argv.ratio)
.stream('png')
.pipe(pictureTube({ cols: argv.cols }))
}

Loading

0 comments on commit 2f861f9

Please sign in to comment.