fix shitty replace job
This commit is contained in:
parent
3bd884535e
commit
01f7cc7d43
1 changed files with 42 additions and 47 deletions
89
repl.js
89
repl.js
|
@ -26,32 +26,27 @@ import * as std from "qjs:std";
|
|||
import * as os from "qjs:os";
|
||||
import * as bjson from "qjs:bjson";
|
||||
|
||||
//REPL POLYFILLS BEGIN
|
||||
globalThis.global = globalThis
|
||||
global.console.error = console.log
|
||||
global.console.warn = console.log
|
||||
globalThis.breakFunction = () => { throw new Error('Function Break'); };
|
||||
|
||||
if (typeof os !== 'undefined') {
|
||||
globalThis.sleep = os.sleep
|
||||
async function setTimeout2(func, ms) {globalThis.clearTimeout = false; await sleep(ms); if (!clearTimeout) { func(); } }
|
||||
globalThis.setTimeout = setTimeout2
|
||||
} else {
|
||||
console.error('os is not defined.')
|
||||
}
|
||||
|
||||
if (typeof os !== 'undefined') {
|
||||
globalThis.sleep = os.sleep
|
||||
async function setTimeout2(func, ms) {globalThis.clearTimeout = false; await sleep(ms); if (!clearTimeout) { func(); } }
|
||||
globalThis.setTimeout = setTimeout2
|
||||
} else {
|
||||
console.error('os is not defined.')
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (typeof std !== 'undefined') {
|
||||
globalThis.urlGet = std.urlGet
|
||||
globalThis.loadFile = std.loadFile
|
||||
globalThis.printf = console.log
|
||||
globalThis.evalFile = std.loadScript
|
||||
// " globalThis.require = std.loadScript"
|
||||
globalThis.getURL = std.urlGet
|
||||
} else {
|
||||
console.error('std is not defined.');
|
||||
}
|
||||
if (typeof std !== 'undefined') {
|
||||
globalThis.urlGet = std.urlGet
|
||||
globalThis.loadFile = std.loadFile
|
||||
globalThis.printf = console.log
|
||||
globalThis.evalFile = std.loadScript
|
||||
// " globalThis.require = std.loadScript"
|
||||
globalThis.getURL = std.urlGet
|
||||
} else {
|
||||
console.error('std is not defined.');
|
||||
}
|
||||
|
||||
(function(g) {
|
||||
/* add 'bjson', 'os' and 'std' bindings */
|
||||
|
@ -303,7 +298,7 @@ globalThis.global = globalThis
|
|||
if (delta > 0) {
|
||||
while (delta != 0) {
|
||||
if (term_cursor_x == (term_width - 1)) {
|
||||
std.puts("); /* translated to CRLF */
|
||||
std.puts("\n"); /* translated to CRLF */
|
||||
term_cursor_x = 0;
|
||||
delta--;
|
||||
} else {
|
||||
|
@ -445,7 +440,7 @@ globalThis.global = globalThis
|
|||
}
|
||||
|
||||
function accept_line() {
|
||||
std.puts(");
|
||||
std.puts("\n");
|
||||
history_add(cmd);
|
||||
return -1;
|
||||
}
|
||||
|
@ -528,7 +523,7 @@ globalThis.global = globalThis
|
|||
|
||||
function control_d() {
|
||||
if (cmd.length == 0) {
|
||||
std.puts(");
|
||||
std.puts("\n");
|
||||
return -3; /* exit read eval print loop */
|
||||
} else {
|
||||
delete_char_dir(1);
|
||||
|
@ -616,10 +611,10 @@ globalThis.global = globalThis
|
|||
|
||||
function control_c() {
|
||||
if (last_fun === control_c) {
|
||||
std.puts(");
|
||||
std.puts("\n");
|
||||
exit(0);
|
||||
} else {
|
||||
std.puts("\n(Press Ctrl-C again to quit));
|
||||
std.puts("\n(Press Ctrl-C again to quit)\n");
|
||||
readline_print_prompt();
|
||||
}
|
||||
}
|
||||
|
@ -771,7 +766,7 @@ globalThis.global = globalThis
|
|||
max_width += 2;
|
||||
n_cols = Math.max(1, Math.floor((term_width + 1) / max_width));
|
||||
n_rows = Math.ceil(tab.length / n_cols);
|
||||
std.puts(");
|
||||
std.puts("\n");
|
||||
/* display the sorted list column-wise */
|
||||
for (row = 0; row < n_rows; row++) {
|
||||
for (col = 0; col < n_cols; col++) {
|
||||
|
@ -783,7 +778,7 @@ globalThis.global = globalThis
|
|||
s = s.padEnd(max_width);
|
||||
std.puts(s);
|
||||
}
|
||||
std.puts(");
|
||||
std.puts("\n");
|
||||
}
|
||||
/* show a new prompt */
|
||||
readline_print_prompt();
|
||||
|
@ -1426,7 +1421,7 @@ globalThis.global = globalThis
|
|||
output_str(sep);
|
||||
sep = ",";
|
||||
if (col === cols - 1) {
|
||||
output_spaces(", indent);
|
||||
output_spaces("\n", indent);
|
||||
col = 0;
|
||||
} else {
|
||||
output_spaces("", colwidth[col++] - w);
|
||||
|
@ -1439,10 +1434,10 @@ globalThis.global = globalThis
|
|||
for (i = first; i < last; i++) {
|
||||
output_str(sep);
|
||||
sep = ",";
|
||||
output_spaces(", indent);
|
||||
output_spaces("\n", indent);
|
||||
[i, w] = output_indent(indent, i);
|
||||
}
|
||||
output_spaces(", indent -= 2);
|
||||
output_spaces("\n", indent -= 2);
|
||||
output_pretty(tokens[last]);
|
||||
return [last, breakLength];
|
||||
}
|
||||
|
@ -1454,7 +1449,7 @@ globalThis.global = globalThis
|
|||
|
||||
function print(val) {
|
||||
std.puts(util.inspect(val, { depth: show_depth, colors: show_colors, showHidden: show_hidden }));
|
||||
std.puts(");
|
||||
std.puts("\n");
|
||||
}
|
||||
|
||||
/* return true if the string was a directive */
|
||||
|
@ -1492,19 +1487,19 @@ globalThis.global = globalThis
|
|||
|
||||
function help() {
|
||||
var sel = (n) => n ? "*": " ";
|
||||
std.puts(".help print this help +
|
||||
".x " + sel(hex_mode) + "hexadecimal number display +
|
||||
".dec " + sel(!hex_mode) + "decimal number display +
|
||||
".time " + sel(show_time) + "toggle timing display +
|
||||
".strict " + sel(use_strict) + "toggle strict mode evaluation +
|
||||
std.puts(".help print this help\n" +
|
||||
".x " + sel(hex_mode) + "hexadecimal number display\n" +
|
||||
".dec " + sel(!hex_mode) + "decimal number display\n" +
|
||||
".time " + sel(show_time) + "toggle timing display\n" +
|
||||
".strict " + sel(use_strict) + "toggle strict mode evaluation\n" +
|
||||
`.depth set object depth (current: ${show_depth})\n` +
|
||||
".hidden " + sel(show_hidden) + "toggle hidden properties display +
|
||||
".color " + sel(show_colors) + "toggle colored output +
|
||||
".dark " + sel(styles == themes.dark) + "select dark color theme +
|
||||
".light " + sel(styles == themes.light) + "select light color theme +
|
||||
".clear clear the terminal +
|
||||
".load load source code from a file +
|
||||
".quit exit);
|
||||
".hidden " + sel(show_hidden) + "toggle hidden properties display\n" +
|
||||
".color " + sel(show_colors) + "toggle colored output\n" +
|
||||
".dark " + sel(styles == themes.dark) + "select dark color theme\n" +
|
||||
".light " + sel(styles == themes.light) + "select light color theme\n" +
|
||||
".clear clear the terminal\n" +
|
||||
".load load source code from a file\n" +
|
||||
".quit exit\n");
|
||||
}
|
||||
|
||||
function load(s) {
|
||||
|
@ -1543,7 +1538,7 @@ globalThis.global = globalThis
|
|||
}, null);
|
||||
|
||||
function cmd_start() {
|
||||
std.puts('QuickJS-ng DoneJS Edition - Type ".help" for help\n');
|
||||
std.puts('QuickJS-ng DoneJS Edition - Type ".help" for help\n');
|
||||
cmd_readline_start();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue