diff --git a/packages/core/src/component.ts b/packages/core/src/component.ts index a9ea68d..6d7c8b4 100644 --- a/packages/core/src/component.ts +++ b/packages/core/src/component.ts @@ -121,6 +121,10 @@ export class RenderHost extends Component { this.#output = output; } + #onResize = (): void => { + this.requestUpdate(); + }; + render(): Template { const result: TemplateArray = []; for (const child of this.children) { @@ -148,6 +152,13 @@ export class RenderHost extends Component { super.onUnmount(); this.#lastFrame = undefined; this.#mounted = false; + this.#output.off('resize', this.#onResize); + this.#output.write(cursor.show); + } + + onMount(): void { + super.onMount(); + this.#output.on('resize', this.#onResize); } attach(component: Component): void { diff --git a/packages/core/src/prompts/prompt.ts b/packages/core/src/prompts/prompt.ts index 931ff42..669d665 100644 --- a/packages/core/src/prompts/prompt.ts +++ b/packages/core/src/prompts/prompt.ts @@ -1,7 +1,6 @@ import { stdin, stdout } from 'node:process'; import readline, { type Key, type ReadLine } from 'node:readline'; import type { Readable, Writable } from 'node:stream'; -import { cursor } from 'sisteransi'; import { Component, RenderHost } from '../component.js'; import type { ClackEvents, ClackState } from '../types.js'; import type { Action } from '../utils/index.js'; @@ -153,19 +152,14 @@ export default class Prompt extends Component { this.input.on('keypress', this.onKeypress); setRawMode(this.input, true); - this.output.on('resize', this.requestUpdate); this.requestUpdate(); this.once('submit', () => { - this.output.write(cursor.show); - this.output.off('resize', this.requestUpdate); setRawMode(this.input, false); resolve(this.value); }); this.once('cancel', () => { - this.output.write(cursor.show); - this.output.off('resize', this.requestUpdate); setRawMode(this.input, false); resolve(CANCEL_SYMBOL); });