From a0180f364dc73366ee31525c9bba4bed9b96c78f Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 20 Jan 2026 14:02:36 +0000 Subject: [PATCH] fix: accept pi-tui editor ctor variants --- src/tui/components/custom-editor.ts | 31 ++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/tui/components/custom-editor.ts b/src/tui/components/custom-editor.ts index 4dc42391f..b5270cad8 100644 --- a/src/tui/components/custom-editor.ts +++ b/src/tui/components/custom-editor.ts @@ -1,4 +1,11 @@ -import { Editor, Key, matchesKey } from "@mariozechner/pi-tui"; +import { + Editor, + Key, + matchesKey, + type EditorOptions, + type EditorTheme, + type TUI, +} from "@mariozechner/pi-tui"; export class CustomEditor extends Editor { onEscape?: () => void; @@ -12,6 +19,28 @@ export class CustomEditor extends Editor { onShiftTab?: () => void; onAltEnter?: () => void; + constructor(tui: TUI, theme: EditorTheme, options?: EditorOptions); + constructor(theme: EditorTheme, options?: EditorOptions); + constructor( + tuiOrTheme: TUI | EditorTheme, + themeOrOptions?: EditorTheme | EditorOptions, + options?: EditorOptions, + ) { + const hasTui = typeof (tuiOrTheme as TUI).terminal !== "undefined"; + const theme = hasTui ? (themeOrOptions as EditorTheme) : (tuiOrTheme as EditorTheme); + const resolvedOptions = hasTui ? options : (themeOrOptions as EditorOptions | undefined); + const useTuiArg = hasTui && Editor.length >= 2; + const baseArgs = (useTuiArg + ? [tuiOrTheme, theme, resolvedOptions] + : [theme, resolvedOptions]) as unknown as ConstructorParameters; + + super(...baseArgs); + + if (hasTui && !useTuiArg) { + (this as unknown as { tui?: TUI }).tui = tuiOrTheme as TUI; + } + } + handleInput(data: string): void { if (matchesKey(data, Key.alt("enter")) && this.onAltEnter) { this.onAltEnter();