fix shitty replace job

This commit is contained in:
Arma-Damna-Dillo 2025-01-06 15:28:40 -06:00
parent 3bd884535e
commit 01f7cc7d43

63
repl.js
View file

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