Skip to content

Commit

Permalink
Support animated GIFs (#1)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
Richienb and sindresorhus committed Jul 18, 2020
1 parent eb31abb commit 87a7817
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
16 changes: 14 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const meow = require('meow');
const getStdin = require('get-stdin');
const terminalImage = require('terminal-image');
const fileType = require('file-type');

const cli = meow(`
Usage
Expand All @@ -23,8 +24,19 @@ if (!input && process.stdin.isTTY) {

(async () => {
if (input) {
console.log(await terminalImage.file(input));
// TODO: Make it `if ((await fileType.fromFile(input))?.ext === 'gif') {` when targeting Node.js 14.
if ((await fileType.fromFile(input)).ext === 'gif') {
terminalImage.gifFile(input);
} else {
console.log(await terminalImage.file(input));
}
} else {
console.log(await terminalImage.buffer(await getStdin.buffer()));
const stdin = await getStdin.buffer();

if ((await fileType.fromBuffer(stdin)).ext === 'gif') {
terminalImage.gifBuffer(stdin);
} else {
console.log(await terminalImage.buffer(stdin));
}
}
})();
Binary file added fixture.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@
"escape",
"png",
"jpg",
"jpeg"
"jpeg",
"gif"
],
"dependencies": {
"file-type": "^14.6.2",
"get-stdin": "^7.0.0",
"meow": "^7.0.0",
"terminal-image": "^1.0.0"
"terminal-image": "^1.2.0"
},
"devDependencies": {
"ava": "^2.4.0",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Display images in the terminal
Works in any terminal that supports colors.
Works in any terminal that supports colors. Supports animated GIFs.

<img src="screenshot.png" width="1082">

Expand Down

0 comments on commit 87a7817

Please sign in to comment.