-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcli.js
executable file
·51 lines (44 loc) · 950 Bytes
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env node
import process from 'node:process';
import meow from 'meow';
import getStdin from 'get-stdin';
import terminalImage from 'term-img';
const cli = meow(`
Usage
$ term-img <image>
$ cat <image> | term-img
Options
--width Width to render [N|Npx|N%]
--height Height to render [N|Npx|N%]
Examples
$ term-img unicorn.jpg --width=200px
$ cat unicorn.jpg | term-img --height=50%
`, {
importMeta: import.meta,
flags: {
width: {
type: 'string',
},
height: {
type: 'string',
},
},
});
const [input] = cli.input;
function init(data) {
try {
console.log(terminalImage(data, cli.flags));
} catch (error) {
if (error.name === 'UnsupportedTerminalError') {
console.error(error.message);
process.exit(1);
} else {
throw error;
}
}
}
if (!input && process.stdin.isTTY) {
console.error('Specify the path to an image');
process.exit(1);
}
init(input ?? await getStdin.buffer());