Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
vihanb committed Sep 30, 2016
1 parent cb916f8 commit b3c40de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"colors": "^1.1.2",
"commander": "^2.9.0",
"crypto": "0.0.3",
"node-color-readline": "^1.0.1",
"readline": "^1.3.0",
"xregexp": "^3.1.1"
},
Expand Down
20 changes: 16 additions & 4 deletions src/cli/repl.es6
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import readline from 'readline';
import readline from 'node-color-readline';
import colors from 'colors';

import CheddarScope from '../interpreter/core/env/scope';
Expand Down Expand Up @@ -28,7 +28,7 @@ try {
let shortest_segment = longest_segment === latest ? old : latest;

let status = 0;

for (let i = 0; i < shortest_segment.length; i++) {
if (longest_segment[i]) {
if (shortest_segment[i] < longest_segment[i]) {
Expand All @@ -52,9 +52,21 @@ try {
}
} catch(e){}

function clearc(s) {
return s.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, "");
}

let reserved = new RegExp([...require('../tokenizer/consts/ops').RESERVED_KEYWORDS].join("|"), "g");
// Workaround
let REPL = readline.createInterface(process.stdin, process.stdout);
let PROMPT = 'cheddar> '.yellow.bold;
let REPL = readline.createInterface({
input: process.stdin,
output: process.stdout,
colorize: str =>str
.replace(/-?(\.?\d+|\d+\.\d+)|0b[10]+|0x[\dABCDEF]+/g, s => clearc(s).blue)
.replace(reserved, s => clearc(s).cyan)
.replace(/(["'])(?:(?=\\*)\\.|.)*?\1/g, s => clearc(s).red)
});
let PROMPT = 'cheddar> ';//.yellow.bold;
REPL.setPrompt(PROMPT);
REPL.prompt();

Expand Down

0 comments on commit b3c40de

Please sign in to comment.