UNPKG

@unito/integration-debugger

Version:

The Unito Integration Debugger

62 lines (61 loc) 2.81 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const chalk_1 = __importDefault(require("chalk")); const clipboardy_1 = __importDefault(require("clipboardy")); const blessed_1 = require("../resources/blessed"); const styles_1 = require("../styles"); const store_1 = require("../store"); const Process = () => { const windowRef = (0, react_1.useRef)(null); const listRef = (0, react_1.useRef)(null); const processState = (0, store_1.useIntegrationProcessState)(); const [copying, setCopying] = (0, react_1.useState)(false); (0, react_1.useEffect)(() => { return () => { if (windowRef.current) { windowRef.current.free(); } }; }, [windowRef]); (0, react_1.useEffect)(() => { if (listRef.current) { listRef.current?.focus(); (0, blessed_1.enableListScrolling)(listRef.current); } return () => { if (listRef.current) { listRef.current.free(); } }; }, [listRef]); (0, react_1.useEffect)(() => { if (listRef.current) { const index = processState.output.length - 1; listRef.current.select(index); } }, [listRef, processState.output]); (0, react_1.useEffect)(() => { listRef.current?.key(['c'], (ch, key) => { setCopying(true); const processOutput = (0, styles_1.uncolorize)(processState.output.join('\n')); clipboardy_1.default.writeSync(processOutput); // Blink effect. setTimeout(() => { setCopying(false); }, 100); }); }, [listRef, processState.output]); const labels = { copy: [chalk_1.default.whiteBright('c'), chalk_1.default.blueBright('opy')].join(''), }; const effectiveLabels = { copy: copying ? chalk_1.default.bgWhiteBright(labels.copy) : labels.copy, }; return ((0, jsx_runtime_1.jsxs)("box", { top: 3, ref: windowRef, children: [(0, jsx_runtime_1.jsx)("list", { ref: listRef, label: "Output", right: 0, width: "100%", top: 0, height: "100%-3", border: styles_1.paneBorder, style: styles_1.focusedPane, scrollbar: styles_1.scrollbar, scrollable: true, focusable: true, keys: true, items: processState.output.map(s => s) }), (0, jsx_runtime_1.jsx)("layout", { left: 0, bottom: 0, height: 3, border: styles_1.paneBorder, style: styles_1.unfocusablePane, children: (0, jsx_runtime_1.jsx)("button", { label: effectiveLabels.copy }) })] })); }; exports.default = Process;