fix: tolerate pi-tui type exports
This commit is contained in:
@@ -1,11 +1,4 @@
|
|||||||
import {
|
import { Editor, Key, matchesKey } from "@mariozechner/pi-tui";
|
||||||
Editor,
|
|
||||||
Key,
|
|
||||||
matchesKey,
|
|
||||||
type EditorOptions,
|
|
||||||
type EditorTheme,
|
|
||||||
type TUI,
|
|
||||||
} from "@mariozechner/pi-tui";
|
|
||||||
|
|
||||||
export class CustomEditor extends Editor {
|
export class CustomEditor extends Editor {
|
||||||
onEscape?: () => void;
|
onEscape?: () => void;
|
||||||
@@ -19,26 +12,22 @@ export class CustomEditor extends Editor {
|
|||||||
onShiftTab?: () => void;
|
onShiftTab?: () => void;
|
||||||
onAltEnter?: () => void;
|
onAltEnter?: () => void;
|
||||||
|
|
||||||
constructor(tui: TUI, theme: EditorTheme, options?: EditorOptions);
|
constructor(tuiOrTheme: unknown, themeOrOptions?: unknown, options?: { paddingX?: number }) {
|
||||||
constructor(theme: EditorTheme, options?: EditorOptions);
|
const hasTui = Boolean((tuiOrTheme as { terminal?: unknown })?.terminal);
|
||||||
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 useTuiArg = hasTui && Editor.length >= 2;
|
||||||
const baseArgs = (useTuiArg
|
|
||||||
? [tuiOrTheme, theme, resolvedOptions]
|
|
||||||
: [theme, resolvedOptions]) as unknown as ConstructorParameters<typeof Editor>;
|
|
||||||
|
|
||||||
super(...baseArgs);
|
if (hasTui) {
|
||||||
|
const theme = themeOrOptions;
|
||||||
if (hasTui && !useTuiArg) {
|
if (useTuiArg) {
|
||||||
(this as unknown as { tui?: TUI }).tui = tuiOrTheme as TUI;
|
super(tuiOrTheme as never, theme as never, options as never);
|
||||||
|
} else {
|
||||||
|
super(theme as never, options as never);
|
||||||
|
this.tui = tuiOrTheme as unknown as typeof this.tui;
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
super(tuiOrTheme as never, themeOrOptions as never);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleInput(data: string): void {
|
handleInput(data: string): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user