forked from LittleHelicase/pivi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pivi.js
executable file
·45 lines (43 loc) · 1.31 KB
/
pivi.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
#!/usr/bin/env node
var canvas = require("canvas");
var es = require("event-stream");
var parse = require("./lib/grammar.js").parse;
var sc = require("./lib/streamCanvas.js");
var tc = require("./lib/terminalCanvas.js")
var argv = require("yargs")
.usage("echo 'line (0 0) (200 200)' | $0 [options]")
.default("f","./out%d.png")
.describe("f", "The output file that gets generated")
.default("a",false)
.describe("a","create an animated gif")
.default("t",false)
.describe("t","print result to terminal")
.help("h")
.argv;
var api = require("./lib/api.js");
if(argv.a){
if(argv.f == "./out%d.png"){
argv.f = "out.gif";
}
process.stdin
.pipe(es.split())
.pipe(es.mapSync(parse))
.pipe(sc())
.pipe(api.createAnimationProcessor(argv.f));
} else {
if(argv.t){
console.log("Caution: Canvas size is " + process.stdout.columns*2+":"+process.stdout.rows*3.3 + ". Painting outside can result in strange behaviour. Use the canvas command to set appropriate size.")
process.stdin
.pipe(es.split())
.pipe(es.mapSync(parse))
.pipe(tc())
.pipe(process.stdout);
}
else {
process.stdin
.pipe(es.split())
.pipe(es.mapSync(parse))
.pipe(sc(argv.f))
.pipe(process.stdout);
}
}