From f41f5f3c9a1a2b3a0ecf2159df5ff0df821b7d21 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Mon, 7 Mar 2016 18:28:24 +0300 Subject: [PATCH 1/2] giffy-break as a non-iTerm fallback --- cli.js | 44 ++++++++++++++++++++++++++++---------------- package.json | 1 + 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/cli.js b/cli.js index ac32322..9f707ad 100755 --- a/cli.js +++ b/cli.js @@ -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 @@ -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 $ npm ' + args.join(' ') + '' + }) + .then(open) + .catch(errorHandler); + } } function isInstall (args) { @@ -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); diff --git a/package.json b/package.json index 35bb72d..8111b77 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "array-shuffle": "^1.0.0", "cross-spawn-async": "^2.1.9", "each-series": "^1.0.0", + "giffy-break": "^0.3.0", "got": "^5.5.0", "imgcat": "^0.1.1", "is-iterm": "^1.0.0", From 8fe0aa58b3544bbefb55ab568f252e5e8f8ef208 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Tue, 8 Mar 2016 02:03:45 +0300 Subject: [PATCH 2/2] update to node 0.12-compatible version of giffy-break --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8111b77..903e29c 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "array-shuffle": "^1.0.0", "cross-spawn-async": "^2.1.9", "each-series": "^1.0.0", - "giffy-break": "^0.3.0", + "giffy-break": "^0.4.1", "got": "^5.5.0", "imgcat": "^0.1.1", "is-iterm": "^1.0.0",