diff --git a/cli.js b/cli.js index fdc4771..d572e4a 100755 --- a/cli.js +++ b/cli.js @@ -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 @@ -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)); + } } })(); diff --git a/fixture.gif b/fixture.gif new file mode 100644 index 0000000..03ad404 Binary files /dev/null and b/fixture.gif differ diff --git a/package.json b/package.json index 325f718..39722f6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/readme.md b/readme.md index a2e4065..edd782c 100644 --- a/readme.md +++ b/readme.md @@ -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.