From 5fa7b2ae81220e701215537950e09655d3ecf887 Mon Sep 17 00:00:00 2001 From: bn-l Date: Tue, 19 Mar 2024 16:19:39 +1100 Subject: [PATCH 1/5] Updated error code to work with ESM modules (see: https://github.com/nodejs/modules/issues/360). Added message about the env var. --- src/reconciler.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/reconciler.ts b/src/reconciler.ts index d0bdad29..ef07f9a6 100644 --- a/src/reconciler.ts +++ b/src/reconciler.ts @@ -26,10 +26,11 @@ if (process.env['DEV'] === 'true') { try { await import('./devtools.js'); } catch (error: any) { - if (error.code === 'MODULE_NOT_FOUND') { + if (error.code === 'ERR_MODULE_NOT_FOUND') { console.warn( ` -Debugging with React Devtools requires \`react-devtools-core\` dependency to be installed. +The environment variable DEV = true so ink tried to import \`react-devtools-core\` but this +failed as it was not installed. Debugging with React Devtools requires it. To install use this command: $ npm install --save-dev react-devtools-core `.trim() + '\n' From 72c636779bbf00629525bf62ab20feedf7d7f352 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 19 Mar 2024 15:23:34 +0700 Subject: [PATCH 2/5] Update reconciler.ts --- src/reconciler.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/reconciler.ts b/src/reconciler.ts index ef07f9a6..d22b8060 100644 --- a/src/reconciler.ts +++ b/src/reconciler.ts @@ -29,8 +29,10 @@ if (process.env['DEV'] === 'true') { if (error.code === 'ERR_MODULE_NOT_FOUND') { console.warn( ` -The environment variable DEV = true so ink tried to import \`react-devtools-core\` but this -failed as it was not installed. Debugging with React Devtools requires it. To install use this command: +The environment variable DEV is set to true, so Ink tried to import \`react-devtools-core\`, +but this failed as it was not installed. Debugging with React Devtools requires it. + +To install use this command: $ npm install --save-dev react-devtools-core `.trim() + '\n' From 459063af6c886b8607d857036e87ee393d66ad75 Mon Sep 17 00:00:00 2001 From: bn-l Date: Mon, 15 Apr 2024 14:23:01 +1000 Subject: [PATCH 3/5] spaces to tabs --- .vscode/settings.json | 3 +++ src/ink.tsx | 34 +++++++++++++++++----------------- src/render-border.ts | 32 ++++++++++++++++---------------- src/render-node-to-output.ts | 16 ++++++++-------- 4 files changed, 44 insertions(+), 41 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..db98ee61 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "github.copilot.inlineSuggest.enable": true +} \ No newline at end of file diff --git a/src/ink.tsx b/src/ink.tsx index e5efac2d..5cd1c0d8 100644 --- a/src/ink.tsx +++ b/src/ink.tsx @@ -1,22 +1,22 @@ import process from 'node:process'; -import React, {type ReactNode} from 'react'; +import React, { type ReactNode } from 'react'; import throttle from 'lodash/throttle.js'; -import {type DebouncedFunc} from 'lodash'; +import { type DebouncedFunc } from 'lodash'; import ansiEscapes from 'ansi-escapes'; import isInCi from 'is-in-ci'; import autoBind from 'auto-bind'; import signalExit from 'signal-exit'; import patchConsole from 'patch-console'; -import {type FiberRoot} from 'react-reconciler'; +import { type FiberRoot } from 'react-reconciler'; import Yoga from 'yoga-wasm-web/auto'; import reconciler from './reconciler.js'; import render from './renderer.js'; import * as dom from './dom.js'; -import logUpdate, {type LogUpdate} from './log-update.js'; +import logUpdate, { type LogUpdate } from './log-update.js'; import instances from './instances.js'; import App from './components/App.js'; -const noop = () => {}; +const noop = () => { }; export type Options = { stdout: NodeJS.WriteStream; @@ -54,18 +54,18 @@ export default class Ink { this.rootNode.onRender = options.debug ? this.onRender : throttle(this.onRender, 32, { - leading: true, - trailing: true - }); + leading: true, + trailing: true + }); this.rootNode.onImmediateRender = this.onRender; this.log = logUpdate.create(options.stdout); this.throttledLog = options.debug ? this.log : throttle(this.log, undefined, { - leading: true, - trailing: true - }); + leading: true, + trailing: true + }); // Ignore last render after unmounting a tree to prevent empty output before exit this.isUnmounted = false; @@ -86,12 +86,12 @@ export default class Ink { false, null, 'id', - () => {}, + () => { }, null ); // Unmount when process exits - this.unsubscribeExit = signalExit(this.unmount, {alwaysLast: false}); + this.unsubscribeExit = signalExit(this.unmount, { alwaysLast: false }); if (process.env['DEV'] === 'true') { reconciler.injectIntoDevTools({ @@ -121,9 +121,9 @@ export default class Ink { this.onRender(); }; - resolveExitPromise: () => void = () => {}; - rejectExitPromise: (reason?: Error) => void = () => {}; - unsubscribeExit: () => void = () => {}; + resolveExitPromise: () => void = () => { }; + rejectExitPromise: (reason?: Error) => void = () => { }; + unsubscribeExit: () => void = () => { }; calculateLayout = () => { // The 'columns' property can be undefined or 0 when not using a TTY. @@ -144,7 +144,7 @@ export default class Ink { return; } - const {output, outputHeight, staticOutput} = render(this.rootNode); + const { output, outputHeight, staticOutput } = render(this.rootNode); // If output isn't empty, it means new children have been added to it const hasStaticOutput = staticOutput && staticOutput !== '\n'; diff --git a/src/render-border.ts b/src/render-border.ts index e04e0d48..05b7b300 100644 --- a/src/render-border.ts +++ b/src/render-border.ts @@ -1,7 +1,7 @@ import cliBoxes from 'cli-boxes'; import chalk from 'chalk'; import colorize from './colorize.js'; -import {type DOMNode} from './dom.js'; +import { type DOMNode } from './dom.js'; import type Output from './output.js'; const renderBorder = ( @@ -48,12 +48,12 @@ const renderBorder = ( let topBorder = showTopBorder ? colorize( - (showLeftBorder ? box.topLeft : '') + - box.top.repeat(contentWidth) + - (showRightBorder ? box.topRight : ''), - topBorderColor, - 'foreground' - ) + (showLeftBorder ? box.topLeft : '') + + box.top.repeat(contentWidth) + + (showRightBorder ? box.topRight : ''), + topBorderColor, + 'foreground' + ) : undefined; if (showTopBorder && dimTopBorderColor) { @@ -88,12 +88,12 @@ const renderBorder = ( let bottomBorder = showBottomBorder ? colorize( - (showLeftBorder ? box.bottomLeft : '') + - box.bottom.repeat(contentWidth) + - (showRightBorder ? box.bottomRight : ''), - bottomBorderColor, - 'foreground' - ) + (showLeftBorder ? box.bottomLeft : '') + + box.bottom.repeat(contentWidth) + + (showRightBorder ? box.bottomRight : ''), + bottomBorderColor, + 'foreground' + ) : undefined; if (showBottomBorder && dimBottomBorderColor) { @@ -103,11 +103,11 @@ const renderBorder = ( const offsetY = showTopBorder ? 1 : 0; if (topBorder) { - output.write(x, y, topBorder, {transformers: []}); + output.write(x, y, topBorder, { transformers: [] }); } if (showLeftBorder) { - output.write(x, y + offsetY, leftBorder, {transformers: []}); + output.write(x, y + offsetY, leftBorder, { transformers: [] }); } if (showRightBorder) { @@ -117,7 +117,7 @@ const renderBorder = ( } if (bottomBorder) { - output.write(x, y + height - 1, bottomBorder, {transformers: []}); + output.write(x, y + height - 1, bottomBorder, { transformers: [] }); } } }; diff --git a/src/render-node-to-output.ts b/src/render-node-to-output.ts index 50bf2cd1..c0a8b724 100644 --- a/src/render-node-to-output.ts +++ b/src/render-node-to-output.ts @@ -5,7 +5,7 @@ import wrapText from './wrap-text.js'; import getMaxWidth from './get-max-width.js'; import squashTextNodes from './squash-text-nodes.js'; import renderBorder from './render-border.js'; -import {type DOMElement} from './dom.js'; +import { type DOMElement } from './dom.js'; import type Output from './output.js'; // If parent container is ``, text nodes will be treated as separate nodes in @@ -50,7 +50,7 @@ const renderNodeToOutput = ( return; } - const {yogaNode} = node; + const { yogaNode } = node; if (yogaNode) { if (yogaNode.getDisplay() === Yoga.DISPLAY_NONE) { @@ -83,7 +83,7 @@ const renderNodeToOutput = ( text = applyPaddingToText(node, text); - output.write(x, y, text, {transformers: newTransformers}); + output.write(x, y, text, { transformers: newTransformers }); } return; @@ -106,8 +106,8 @@ const renderNodeToOutput = ( const x2 = clipHorizontally ? x + - yogaNode.getComputedWidth() - - yogaNode.getComputedBorder(Yoga.EDGE_RIGHT) + yogaNode.getComputedWidth() - + yogaNode.getComputedBorder(Yoga.EDGE_RIGHT) : undefined; const y1 = clipVertically @@ -116,11 +116,11 @@ const renderNodeToOutput = ( const y2 = clipVertically ? y + - yogaNode.getComputedHeight() - - yogaNode.getComputedBorder(Yoga.EDGE_BOTTOM) + yogaNode.getComputedHeight() - + yogaNode.getComputedBorder(Yoga.EDGE_BOTTOM) : undefined; - output.clip({x1, x2, y1, y2}); + output.clip({ x1, x2, y1, y2 }); clipped = true; } } From b6d0b52e24da028cc643dbc71950da3f188108b6 Mon Sep 17 00:00:00 2001 From: Vadim Demedes Date: Sat, 11 May 2024 20:10:19 +0300 Subject: [PATCH 4/5] Format code --- src/ink.tsx | 20 ++++++++++---------- src/parse-keypress.ts | 8 ++++---- src/render-border.ts | 8 ++++---- src/render-node-to-output.ts | 8 ++++---- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/ink.tsx b/src/ink.tsx index 0fd5ec23..223c82fa 100644 --- a/src/ink.tsx +++ b/src/ink.tsx @@ -1,22 +1,22 @@ import process from 'node:process'; -import React, { type ReactNode } from 'react'; +import React, {type ReactNode} from 'react'; import throttle from 'lodash/throttle.js'; -import { type DebouncedFunc } from 'lodash'; +import {type DebouncedFunc} from 'lodash'; import ansiEscapes from 'ansi-escapes'; import isInCi from 'is-in-ci'; import autoBind from 'auto-bind'; import signalExit from 'signal-exit'; import patchConsole from 'patch-console'; -import { type FiberRoot } from 'react-reconciler'; +import {type FiberRoot} from 'react-reconciler'; import Yoga from 'yoga-wasm-web/auto'; import reconciler from './reconciler.js'; import render from './renderer.js'; import * as dom from './dom.js'; -import logUpdate, { type LogUpdate } from './log-update.js'; +import logUpdate, {type LogUpdate} from './log-update.js'; import instances from './instances.js'; import App from './components/App.js'; -const noop = () => { }; +const noop = () => {}; export type Options = { stdout: NodeJS.WriteStream; @@ -91,7 +91,7 @@ export default class Ink { ); // Unmount when process exits - this.unsubscribeExit = signalExit(this.unmount, { alwaysLast: false }); + this.unsubscribeExit = signalExit(this.unmount, {alwaysLast: false}); if (process.env['DEV'] === 'true') { reconciler.injectIntoDevTools({ @@ -121,9 +121,9 @@ export default class Ink { this.onRender(); }; - resolveExitPromise: () => void = () => { }; - rejectExitPromise: (reason?: Error) => void = () => { }; - unsubscribeExit: () => void = () => { }; + resolveExitPromise: () => void = () => {}; + rejectExitPromise: (reason?: Error) => void = () => {}; + unsubscribeExit: () => void = () => {}; calculateLayout = () => { // The 'columns' property can be undefined or 0 when not using a TTY. @@ -144,7 +144,7 @@ export default class Ink { return; } - const { output, outputHeight, staticOutput } = render(this.rootNode); + const {output, outputHeight, staticOutput} = render(this.rootNode); // If output isn't empty, it means new children have been added to it const hasStaticOutput = staticOutput && staticOutput !== '\n'; diff --git a/src/parse-keypress.ts b/src/parse-keypress.ts index b52059ea..130fab98 100644 --- a/src/parse-keypress.ts +++ b/src/parse-keypress.ts @@ -88,7 +88,7 @@ const keyName: Record = { '[7^': 'home', '[8^': 'end', /* misc. */ - '[Z': 'tab' + '[Z': 'tab', }; export const nonAlphanumericKeys = [...Object.values(keyName), 'backspace']; @@ -106,7 +106,7 @@ const isShiftKey = (code: string) => { '[6$', '[7$', '[8$', - '[Z' + '[Z', ].includes(code); }; @@ -122,7 +122,7 @@ const isCtrlKey = (code: string) => { '[5^', '[6^', '[7^', - '[8^' + '[8^', ].includes(code); }; @@ -160,7 +160,7 @@ const parseKeypress = (s: Buffer | string = ''): ParsedKey => { shift: false, option: false, sequence: s, - raw: s + raw: s, }; key.sequence = key.sequence || s || key.name; diff --git a/src/render-border.ts b/src/render-border.ts index a9c6ba1f..60b50f3e 100644 --- a/src/render-border.ts +++ b/src/render-border.ts @@ -1,7 +1,7 @@ import cliBoxes from 'cli-boxes'; import chalk from 'chalk'; import colorize from './colorize.js'; -import { type DOMNode } from './dom.js'; +import {type DOMNode} from './dom.js'; import type Output from './output.js'; const renderBorder = ( @@ -103,11 +103,11 @@ const renderBorder = ( const offsetY = showTopBorder ? 1 : 0; if (topBorder) { - output.write(x, y, topBorder, { transformers: [] }); + output.write(x, y, topBorder, {transformers: []}); } if (showLeftBorder) { - output.write(x, y + offsetY, leftBorder, { transformers: [] }); + output.write(x, y + offsetY, leftBorder, {transformers: []}); } if (showRightBorder) { @@ -117,7 +117,7 @@ const renderBorder = ( } if (bottomBorder) { - output.write(x, y + height - 1, bottomBorder, { transformers: [] }); + output.write(x, y + height - 1, bottomBorder, {transformers: []}); } } }; diff --git a/src/render-node-to-output.ts b/src/render-node-to-output.ts index 05e3e9a6..965f90e2 100644 --- a/src/render-node-to-output.ts +++ b/src/render-node-to-output.ts @@ -5,7 +5,7 @@ import wrapText from './wrap-text.js'; import getMaxWidth from './get-max-width.js'; import squashTextNodes from './squash-text-nodes.js'; import renderBorder from './render-border.js'; -import { type DOMElement } from './dom.js'; +import {type DOMElement} from './dom.js'; import type Output from './output.js'; // If parent container is ``, text nodes will be treated as separate nodes in @@ -50,7 +50,7 @@ const renderNodeToOutput = ( return; } - const { yogaNode } = node; + const {yogaNode} = node; if (yogaNode) { if (yogaNode.getDisplay() === Yoga.DISPLAY_NONE) { @@ -83,7 +83,7 @@ const renderNodeToOutput = ( text = applyPaddingToText(node, text); - output.write(x, y, text, { transformers: newTransformers }); + output.write(x, y, text, {transformers: newTransformers}); } return; @@ -120,7 +120,7 @@ const renderNodeToOutput = ( yogaNode.getComputedBorder(Yoga.EDGE_BOTTOM) : undefined; - output.clip({ x1, x2, y1, y2 }); + output.clip({x1, x2, y1, y2}); clipped = true; } } From e73e9ad4aca2e1c7ce1962e28c609fdb44311170 Mon Sep 17 00:00:00 2001 From: Vadim Demedes Date: Sat, 11 May 2024 20:15:27 +0300 Subject: [PATCH 5/5] Delete .vscode --- .vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index db98ee61..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "github.copilot.inlineSuggest.enable": true -} \ No newline at end of file