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

54 lines 2.48 kB
"use strict"; /* * Copyright (c) 2021-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. * */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const ink_1 = require("ink"); const react_1 = __importDefault(require("react")); const kotlin_lang_utils_1 = require("../lang-utils/kotlin-lang-utils"); const tui_colors_1 = require("../tui-colors"); const tui_core_1 = require("../tui-core"); const tui_node_keyboard_1 = require("../tui-node-keyboard"); // Hooks. const runHooks = (input) => { const { name } = input; const createShortcutsFn = () => (0, kotlin_lang_utils_1._also)((0, tui_node_keyboard_1.createNewShortcutToActionMap)(), map => map.set("q", tui_core_1.LifecycleHelper.fireExit)); return { greeting: tui_colors_1.TextColor.builder.rainbow.build()(name), useKeyboard: (0, tui_node_keyboard_1.useKeyboardWithMapCached)(createShortcutsFn) }; }; // Function component. const App = () => { const output = runHooks({ name: "Your example goes here!" }); const { greeting } = output; return (react_1.default.createElement(ink_1.Box, { flexDirection: "column" }, react_1.default.createElement(Row_Debug, { ctx: output }), react_1.default.createElement(ink_1.Text, null, greeting))); }; const Row_Debug = ({ ctx }) => { const { keyPress: kp, inRawMode: mode } = ctx.useKeyboard; return mode ? react_1.default.createElement(ink_1.Text, { color: "magenta" }, "keyPress: ", kp ? `${kp.toString()}` : "n/a") : react_1.default.createElement(ink_1.Text, { color: "gray" }, "keyb disabled"); }; // Main. (0, tui_core_1.inkCLIAppMainFn)(() => (0, ink_1.render)(react_1.default.createElement(App, null)), "Exiting ink", "Problem w/ exiting ink").catch(console.error); //# sourceMappingURL=template.js.map