MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

remove osc 52

+5 -55
+5 -55
src/repl.c
··· 25 25 #include "reactor.h" 26 26 #include "runtime.h" 27 27 #include "internal.h" 28 - #include "base64.h" 29 28 30 29 #include "silver/ast.h" 31 30 #include "silver/engine.h" ··· 426 425 } 427 426 428 427 #ifdef _WIN32 429 - static bool repl_stdout_is_tty(void) { 430 - return _isatty(_fileno(stdout)) != 0; 431 - } 432 - 433 - static bool repl_copy_with_osc52(const char *data, size_t len) { 434 - const char *term = getenv("TERM"); 435 - if (!repl_stdout_is_tty()) return false; 436 - if (term && strcmp(term, "dumb") == 0) return false; 437 - 438 - size_t b64_len = 0; 439 - char *b64 = ant_base64_encode((const uint8_t *)data, len, &b64_len); 440 - (void)b64_len; 441 - if (!b64) return false; 442 - 443 - int rc = fprintf(stdout, "\033]52;c;%s\a", b64); 444 - fflush(stdout); 445 - free(b64); 446 - return rc > 0; 447 - } 448 - 449 428 static bool repl_copy_with_command(const char *data, size_t len) { 450 429 FILE *pipe = _popen("clip", "wb"); 451 430 if (!pipe) return false; ··· 455 434 return written == len && close_rc == 0; 456 435 } 457 436 #else 458 - static bool repl_stdout_is_tty(void) { 459 - return isatty(STDOUT_FILENO) == 1; 460 - } 461 - 462 - static bool repl_copy_with_osc52(const char *data, size_t len) { 463 - const char *term = getenv("TERM"); 464 - if (!repl_stdout_is_tty()) return false; 465 - if (term && strcmp(term, "dumb") == 0) return false; 466 - 467 - size_t b64_len = 0; 468 - char *b64 = ant_base64_encode((const uint8_t *)data, len, &b64_len); 469 - (void)b64_len; 470 - if (!b64) return false; 471 - 472 - int rc = 0; 473 - const char *tmux = getenv("TMUX"); 474 - if (tmux && *tmux) { 475 - rc = fprintf(stdout, "\033Ptmux;\033\033]52;c;%s\a\033\\", b64); 476 - } else { 477 - rc = fprintf(stdout, "\033]52;c;%s\a", b64); 478 - } 479 - 480 - fflush(stdout); 481 - free(b64); 482 - return rc > 0; 483 - } 484 - 485 437 static bool repl_copy_with_single_command(const char *cmd, const char *data, size_t len) { 486 438 FILE *pipe = popen(cmd, "w"); 487 439 if (!pipe) return false; ··· 514 466 515 467 repl_clear_exception_state(js); 516 468 jsval_t result = js_eval_bytecode_repl(js, arg, strlen(arg)); 469 + 517 470 js_run_event_loop(js); 518 - 519 471 if (print_uncaught_throw(js)) return CMD_OK; 520 472 521 473 char cbuf[512]; 522 474 js_cstr_t cstr = js_to_cstr(js, result, cbuf, sizeof(cbuf)); 523 - bool copied_osc52 = repl_copy_with_osc52(cstr.ptr, cstr.len); 524 - bool copied = copied_osc52 || repl_copy_with_command(cstr.ptr, cstr.len); 525 - 475 + 476 + bool copied_command = repl_copy_with_command(cstr.ptr, cstr.len); 526 477 if (cstr.needs_free) free((void *)cstr.ptr); 527 478 528 - if (!copied) { 479 + if (!copied_command) { 529 480 fprintf(stderr, "Failed to copy to clipboard (no clipboard command available).\n"); 530 481 return CMD_OK; 531 482 } 532 483 533 - if (copied_osc52) printf("Copied to clipboard (OSC 52).\n"); 534 - else printf("Copied to clipboard.\n"); 484 + printf("Copied to clipboard.\n"); 535 485 return CMD_OK; 536 486 } 537 487