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

Support animated GIFs #1

Merged
merged 4 commits into from
Jul 18, 2020
Merged
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
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