Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

giffy-break as a non-iTerm fallback #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ var join = require('path').join;
var open = require('opn');
var got = require('got');
var fs = require('fs');
var giffyBreak = require('giffy-break');

var imgcat = join(__dirname, 'node_modules', '.bin', 'imgcat');

var API_KEY = 'dc6zaTOxFJmzC';


/**
* npm install + gifs
Expand All @@ -28,17 +31,32 @@ var ps = npm(args);
var gif;

if (isInstall(args)) {
findImages()
.then(displayImages)
.catch(errorHandler);
if (isIterm) {
findImages()
.then(displayImages)
.catch(errorHandler);

ps.on('exit', function (code) {
if (gif) {
gif.kill();
}
ps.on('exit', function (code) {
if (gif) {
gif.kill();
}

process.exit(code);
});
process.exit(code);
});
} else {
var promise = new Promise(function (resolve, reject) {
ps.on('exit', function (code) {
(code === 0 ? resolve : reject)(code);
});
});

giffyBreak(promise, API_KEY, {
interval: 3000,
startMessage: 'Running <code>$ npm ' + args.join(' ') + '</code>'
})
.then(open)
.catch(errorHandler);
}
}

function isInstall (args) {
Expand All @@ -56,18 +74,12 @@ function findImages () {
return got('http://api.giphy.com/v1/gifs/trending', {
json: true,
query: {
api_key: 'dc6zaTOxFJmzC'
api_key: API_KEY
}
});
}

function showImage (url, done) {
if (!isIterm) {
open(url);
done();
return;
}

var path = tempfile();
var image = fs.createWriteStream(path);

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"array-shuffle": "^1.0.0",
"cross-spawn-async": "^2.1.9",
"each-series": "^1.0.0",
"giffy-break": "^0.4.1",
"got": "^5.5.0",
"imgcat": "^0.1.1",
"is-iterm": "^1.0.0",
Expand Down