UNPKG

r3bl-ts-utils

Version:

The `r3bl-ts-utils` package is a set of useful TypeScript functions and classes that can be used in Node.js and browser environments. They are inspired by Kotlin stdlib, and Rust to write code as expressions rather than statements, colorized text, powerfu

69 lines 2.75 kB
"use strict"; /* * Copyright (c) 2022 R3BL LLC. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ Object.defineProperty(exports, "__esModule", { value: true }); exports.StyledColorConsole = exports.Styles = exports.ColorConsole = exports.Formatter = void 0; const kotlin_lang_utils_1 = require("../lang-utils/kotlin-lang-utils"); const tui_colors_1 = require("../tui-colors"); exports.Formatter = (0, kotlin_lang_utils_1._let)({ headerUnderlineFn: tui_colors_1.TextColor.builder.underline.blue.build(), headerFn: tui_colors_1.TextColor.builder.blue.build(), headerMessageFn: tui_colors_1.TextColor.builder.cyan.bold.build(), primaryFn: tui_colors_1.TextColor.builder.yellow.bold.build(), secondaryFn: tui_colors_1.TextColor.builder.underline.cyan.build(), }, (it) => it); class ColorConsole { myStyleFn; myText = ""; static create = (style) => { const instance = new ColorConsole(style); return Object.assign((text) => instance.call(text), instance); }; constructor(style) { this.myStyleFn = style; } call = (text) => this.apply(text); apply = (text) => { this.myText = text; return this; }; consoleLog = (prefixWithNewline = false) => { prefixWithNewline ? console.log() : null; console.log(this.toString()); }; // https://gist.githubusercontent.com/narenaryan/a2f4f8a3559d49ee2380aa17e7dc1dea/raw/d777cf7fad282d6bf1b00a0ec474e6430151b07f/streams_copy_basic.js consoleLogInPlace = (printNewline = false) => { process.stdout.clearLine(-1); process.stdout.cursorTo(0); process.stdout.write(exports.Styles.Primary(this.toString())); printNewline ? process.stdout.write("\n") : null; }; consoleError = () => { console.error(this.toString()); }; toString = () => this.myStyleFn(this.myText); } exports.ColorConsole = ColorConsole; exports.Styles = { Primary: exports.Formatter.primaryFn, Secondary: exports.Formatter.secondaryFn, }; exports.StyledColorConsole = { Primary: ColorConsole.create(exports.Styles.Primary), Secondary: ColorConsole.create(exports.Styles.Secondary), }; //# sourceMappingURL=color-console.js.map