1 | #!/usr/bin/env node
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | 'use strict';
|
17 |
|
18 | const Commands = require('./lib/commands');
|
19 | const Logger = require('@accordproject/ergo-compiler').Logger;
|
20 |
|
21 | try {
|
22 | const args = process.argv;
|
23 | for (let i = 0; i < args.length; i++) {
|
24 | if (args[i].split('.').pop() === 'cto') {
|
25 | const ctoPath = args[i];
|
26 | Commands.parseCTOtoFile(ctoPath);
|
27 | args[i] = ctoPath.substr(0, ctoPath.lastIndexOf('.')) + '.ctoj';
|
28 | }
|
29 | }
|
30 |
|
31 | const ergotop = require('./extracted/ergotopcore.js').ergotop;
|
32 | const readline = require('readline');
|
33 | const chalk = require('chalk');
|
34 |
|
35 | const PS1 = chalk.gray('ergo$ ');
|
36 | const PS2 = chalk.gray(' ... ');
|
37 | const rl = readline.createInterface({
|
38 | input: process.stdin,
|
39 | output: process.stdout,
|
40 | prompt: PS1
|
41 | });
|
42 |
|
43 | let ctx = ergotop.initRCtxt;
|
44 | let inp = '';
|
45 |
|
46 | rl.on('line', (line) => {
|
47 | if (line.charAt(line.length - 1) === '\\') {
|
48 | inp += line.slice(0, line.length - 1) + '\n';
|
49 | rl.setPrompt(PS2);
|
50 | } else {
|
51 | inp += line + '\n';
|
52 | rl.setPrompt(PS1);
|
53 | const x = ergotop.runLine(ctx, inp);
|
54 | inp = '';
|
55 | if (x) {
|
56 | ctx = x.ctx;
|
57 | process.stdout.write(
|
58 | x.out
|
59 | .replace(/^Response. /gm, chalk.green('Response. '))
|
60 | .replace(/^Emit. /gm, chalk.magenta('Emit. '))
|
61 | .replace(/^State. /gm, chalk.blue('State. '))
|
62 | .replace(/^Failure. /gm, chalk.red('Failure. '))
|
63 | );
|
64 | }
|
65 | }
|
66 | rl.prompt();
|
67 | }).on('close', () => {
|
68 | process.exit(0);
|
69 | });
|
70 |
|
71 | rl.prompt();
|
72 | } catch (err) {
|
73 | Logger.error(err.message);
|
74 | }
|