UNPKG

tstosc

Version:

A transpiler that convert TypeScript to SuperCollider's SCLang.

58 lines (55 loc) 1.96 kB
import ansis from 'ansis'; import wrapTextANSI from 'wrap-ansi'; import { prompt } from 'readline-sync'; import { TStoSCError, UnsupportedTypeError, UnsupportedSyntaxError } from '../util/error.js'; const [console_height, console_width] = [process.stdout.rows, process.stdout.columns]; function wrapText(text, column = console_width, option) { return wrapTextANSI(text, column, option); } function askToProceedOrAbort(hint, proceed_text = "y") { return prompt({ prompt: hint }) == proceed_text; } function success(text) { return ansis.hex("67a70c").open + text + ansis.hex("2e7e16").close; } function error(text) { return ansis.hex("e9546b").open + text + ansis.hex("e9546b").close; } function warn(text) { return ansis.hex("ff9740").open + text + ansis.hex("f56a29").close; } function cmd(text) { return ansis.hex("2ca9e1").open + text + ansis.hex("2ca9e1").close; } function param(text) { return ansis.hex("d9a62e").open + text + ansis.hex("d9a62e").close; } function fileArg(text) { return ansis.hex("a69425").open + text + ansis.hex("a69425").close; } function bold(text) { return ansis.bold.open + text + ansis.bold.close; } function italic(text) { return ansis.italic.open + text + ansis.italic.close; } function dim(text) { return ansis.dim.open + text + ansis.dim.close; } function printError(err, indent_level = 0) { console.log(error(err.message).indent(1 + indent_level)); if (err instanceof TStoSCError) { switch (true) { case err instanceof UnsupportedSyntaxError: break; case err instanceof UnsupportedTypeError: { console.log(error(wrapText(err.tryGetErrorOrigin()).indent(2 + indent_level))); } break; } } else { console.log((error(err.toString()) + error(err.stack ?? "")).indent(indent_level)); } } export { askToProceedOrAbort, bold, cmd, console_height, console_width, dim, error, fileArg, italic, param, printError, success, warn, wrapText };