Skip to content

Commit 4850a04

Browse files
committed
small refactor of Node REPL
1 parent 99b876e commit 4850a04

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

bin/lips.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -630,22 +630,6 @@ function run_repl(err, rl) {
630630
function should_update() {
631631
return (token || prev_token) && code_above && !string.match(/^[\n\r]+$/);
632632
}
633-
function refresh() {
634-
// this always need to be executed inside rl._writeToOutput
635-
// even if nothing changes, this make sure that the input
636-
// stay intact while editing the command line
637-
rl.output.write(code);
638-
}
639-
function finalize() {
640-
if (should_update()) {
641-
setTimeout(() => {
642-
// overwrite lines above the cursor this is side effect
643-
process.stdout.write('\x1b7' + ansi_rewrite_above(code_above) + '\x1b8');
644-
}, 0);
645-
}
646-
refresh();
647-
prev_token = token;
648-
}
649633
let token, code_above, code;
650634
try {
651635
const prefix = multiline ? continue_prompt : prompt;
@@ -676,8 +660,16 @@ function run_repl(err, rl) {
676660
}
677661
}
678662
}
663+
if (should_update()) {
664+
// overwrite lines above the cursor this is side effect
665+
process.stdout.write('\x1b7' + ansi_rewrite_above(code_above) + '\x1b8');
666+
}
667+
prev_token = token;
679668
}
680-
finalize();
669+
// this always need to be executed inside rl._writeToOutput
670+
// even if nothing changes, this make sure that the input
671+
// stay intact while editing the command line
672+
rl.output.write(code);
681673
} catch(e) {
682674
console.error(e);
683675
}

0 commit comments

Comments
 (0)