Last active
April 6, 2025 13:53
-
-
Save 8bu/7d267e0afff85681c8da0c030ddc78c3 to your computer and use it in GitHub Desktop.
neo-blessed.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module 'neo-blessed' { | |
// Base event types | |
export type BlessedEventHandler = (args?: any) => void; | |
export type KeyEventHandler = (ch?: string, key?: { name: string; full: string; sequence: string; ctrl: boolean; meta: boolean; shift: boolean }) => void; | |
export type MouseEventHandler = (data: { x: number; y: number; action: string }) => void; | |
// Base node options | |
export interface NodeOptions { | |
screen?: Screen; | |
parent?: Node; | |
children?: Node[]; | |
} | |
// Base node interface | |
export interface Node { | |
type: string; | |
options: NodeOptions; | |
parent: Node | null; | |
screen: Screen; | |
children: Node[]; | |
data: any; | |
index: number; | |
detached: boolean; | |
prepend(node: Node): void; | |
append(node: Node): void; | |
remove(node: Node): void; | |
insert(node: Node, index: number): void; | |
insertBefore(node: Node, refNode: Node): void; | |
insertAfter(node: Node, refNode: Node): void; | |
detach(): void; | |
emit(event: string, ...args: any[]): void; | |
on(event: string, callback: BlessedEventHandler): void; | |
off(event: string, callback: BlessedEventHandler): void; | |
once(event: string, callback: BlessedEventHandler): void; | |
} | |
// Element position interface | |
export interface ElementPosition { | |
left: number | string; | |
right: number | string; | |
top: number | string; | |
bottom: number | string; | |
width: number | string; | |
height: number | string; | |
} | |
// Element style interface | |
export interface ElementStyle { | |
fg?: string; | |
bg?: string; | |
bold?: boolean; | |
underline?: boolean; | |
blink?: boolean; | |
inverse?: boolean; | |
invisible?: boolean; | |
transparent?: boolean; | |
border?: { | |
fg?: string; | |
bg?: string; | |
}; | |
hover?: { | |
bg?: string; | |
fg?: string; | |
bold?: boolean; | |
underline?: boolean; | |
}; | |
focus?: { | |
bg?: string; | |
fg?: string; | |
bold?: boolean; | |
underline?: boolean; | |
}; | |
scrollbar?: { | |
fg?: string; | |
bg?: string; | |
}; | |
selected?: { | |
fg?: string; | |
bg?: string; | |
bold?: boolean; | |
underline?: boolean; | |
}; | |
item?: { | |
fg?: string; | |
bg?: string; | |
}; | |
} | |
// Element border interface | |
export interface ElementBorder { | |
type?: 'line' | 'bg' | 'ascii'; | |
ch?: string; | |
bg?: string; | |
fg?: string; | |
bold?: boolean; | |
underline?: boolean; | |
} | |
// Base element options | |
export interface ElementOptions extends NodeOptions { | |
top?: number | string; | |
left?: number | string; | |
right?: number | string; | |
bottom?: number | string; | |
width?: number | string; | |
height?: number | string; | |
position?: ElementPosition; | |
content?: string; | |
tags?: boolean; | |
border?: boolean | ElementBorder; | |
style?: ElementStyle; | |
hidden?: boolean; | |
clickable?: boolean; | |
input?: boolean; | |
keyable?: boolean; | |
focused?: boolean; | |
align?: 'left' | 'center' | 'right'; | |
valign?: 'top' | 'middle' | 'bottom'; | |
shrink?: boolean; | |
padding?: number | { left: number; right: number; top: number; bottom: number }; | |
shadow?: boolean; | |
label?: string; | |
hoverText?: string; | |
draggable?: boolean; | |
scrollable?: boolean; | |
mouse?: boolean; | |
keys?: boolean; | |
vi?: boolean; | |
alwaysScroll?: boolean; | |
scrollbar?: boolean | { | |
ch?: string; | |
track?: { bg?: string }; | |
style?: ElementStyle; | |
}; | |
} | |
// Base element interface | |
export interface Element extends Node { | |
position: ElementPosition; | |
hidden: boolean; | |
visible: boolean; | |
detached: boolean; | |
style: ElementStyle; | |
border: ElementBorder; | |
hide(): void; | |
show(): void; | |
toggle(): void; | |
focus(): void; | |
blur(): void; | |
key(name: string | string[], listener: KeyEventHandler): void; | |
onScreenEvent(type: string, handler: BlessedEventHandler): void; | |
setContent(content: string): void; | |
getContent(): string; | |
setText(content: string): void; | |
getText(): string; | |
setLine(i: number, line: string): void; | |
insertLine(i: number, line: string): void; | |
deleteLine(i: number): void; | |
clearLine(i: number): void; | |
clearValue(): void; | |
setLabel(text: string): void; | |
setHover(text: string): void; | |
removeLabel(): void; | |
removeHover(): void; | |
enableMouse(): void; | |
enableKeys(): void; | |
enableInput(): void; | |
enableDrag(): void; | |
disableMouse(): void; | |
disableKeys(): void; | |
disableInput(): void; | |
disableDrag(): void; | |
} | |
// Box specific options | |
export interface BoxOptions extends ElementOptions { | |
inputOnFocus?: boolean; | |
mouse?: boolean; | |
fill?: boolean; | |
ch?: string; | |
} | |
// Box interface | |
export interface Box extends Element { | |
value: string; | |
setValue(value: string): void; | |
getValue(): string; | |
parseTags: boolean; | |
setParser(): void; | |
setContent(content: string): void; | |
getContent(): string; | |
setLine(i: number, line: string): void; | |
insertLine(i: number, line: string): void; | |
deleteLine(i: number): void; | |
getLine(i: number): string; | |
getBaseLine(i: number): string; | |
setBaseLine(i: number, line: string): void; | |
clearBaseLine(i: number): void; | |
setScrollPerc(i: number): void; | |
getScrollPerc(): number; | |
scroll(offset: number): void; | |
resetScroll(): void; | |
} | |
// Text box specific options | |
export interface TextboxOptions extends BoxOptions { | |
inputOnFocus?: boolean; | |
secret?: boolean; | |
censor?: string; | |
vi?: boolean; | |
mouse?: boolean; | |
} | |
// Text box interface | |
export interface Textbox extends Box { | |
input: boolean; | |
secret: boolean; | |
censor: string; | |
value: string; | |
setValue(value: string): void; | |
getValue(): string; | |
submit(): void; | |
cancel(): void; | |
clearInput(): void; | |
readInput(callback: (err: Error | null, value: string) => void): void; | |
} | |
// Screen options | |
export interface ScreenOptions { | |
title?: string; | |
terminal?: string; | |
fullUnicode?: boolean; | |
smartCSR?: boolean; | |
fastCSR?: boolean; | |
useBCE?: boolean; | |
cursor?: { | |
artificial: boolean; | |
shape: string; | |
blink: boolean; | |
color: string; | |
}; | |
debug?: boolean; | |
warnings?: boolean; | |
dockBorders?: boolean; | |
ignoreLocked?: boolean; | |
log?: string; | |
dump?: string; | |
input?: NodeJS.ReadableStream; | |
output?: NodeJS.WritableStream; | |
focused?: Element; | |
autoPadding?: boolean; | |
tabc?: string; | |
} | |
// Screen class | |
export class Screen implements Node { | |
constructor(options: ScreenOptions); | |
type: string; | |
options: ScreenOptions; | |
parent: null; | |
screen: this; | |
children: Node[]; | |
data: any; | |
index: number; | |
program: any; | |
title: string; | |
cursor: { | |
artificial: boolean; | |
shape: string; | |
blink: boolean; | |
color: string; | |
}; | |
width: number; | |
height: number; | |
cols: number; | |
rows: number; | |
focused: Element | null; | |
debugLog: string[]; | |
append(node: Node): void; | |
remove(node: Node): void; | |
prepend(node: Node): void; | |
insert(node: Node, index: number): void; | |
insertBefore(node: Node, refNode: Node): void; | |
insertAfter(node: Node, refNode: Node): void; | |
detach(): void; | |
destroy(): void; | |
key(keys: string | string[], callback: KeyEventHandler): void; | |
onceKey(keys: string | string[], callback: KeyEventHandler): void; | |
unkey(keys: string | string[], callback: KeyEventHandler): void; | |
on(event: string, callback: BlessedEventHandler): void; | |
once(event: string, callback: BlessedEventHandler): void; | |
off(event: string, callback: BlessedEventHandler): void; | |
emit(event: string, ...args: any[]): void; | |
render(): void; | |
clearRegion(left: number, top: number, right: number, bottom: number): void; | |
fillRegion(ch: string, left: number, top: number, right: number, bottom: number): void; | |
focusNext(): void; | |
focusPrevious(): void; | |
focusPush(element: Element): void; | |
focusPop(): void; | |
saveFocus(): void; | |
restoreFocus(): void; | |
rewindFocus(): void; | |
enableMouse(): void; | |
disableMouse(): void; | |
enableKeys(): void; | |
disableKeys(): void; | |
copyToClipboard(text: string): void; | |
cursorShape(shape: string, blink?: boolean): void; | |
cursorColor(color: string): void; | |
cursorReset(): void; | |
screenshot(xi?: number, xl?: number, yi?: number, yl?: number): string; | |
resetScroll(): void; | |
setEffects(el: Element, fel: Element, over: boolean, out: boolean, back: boolean): void; | |
leave(el: Element): void; | |
enter(el: Element): void; | |
clearRegion(left: number, top: number, right: number, bottom: number): void; | |
fillRegion(ch: string, left: number, top: number, right: number, bottom: number): void; | |
box(options: BoxOptions): Box; | |
textbox(options: TextboxOptions): Textbox; | |
line(options: BoxOptions): Box; | |
text(options: BoxOptions): Box; | |
list(options: BoxOptions & { items: string[] }): Box; | |
form(options: BoxOptions): Box; | |
input(options: BoxOptions): Box; | |
textarea(options: BoxOptions): Box; | |
button(options: BoxOptions): Box; | |
checkbox(options: BoxOptions): Box; | |
radioset(options: BoxOptions): Box; | |
radiobutton(options: BoxOptions): Box; | |
table(options: BoxOptions & { rows: string[][] }): Box; | |
prompt(options: BoxOptions): Box; | |
question(options: BoxOptions): Box; | |
message(options: BoxOptions): Box; | |
loading(options: BoxOptions): Box; | |
progressbar(options: BoxOptions): Box; | |
log(options: BoxOptions): Box; | |
terminal(options: BoxOptions): Box; | |
image(options: BoxOptions & { file: string }): Box; | |
video(options: BoxOptions & { file: string }): Box; | |
layout(options: BoxOptions): Box; | |
} | |
// Main blessed interface | |
export interface Blessed { | |
screen(options: ScreenOptions): Screen; | |
box(options: BoxOptions): Box; | |
textbox(options: TextboxOptions): Textbox; | |
line(options: BoxOptions): Box; | |
text(options: BoxOptions): Box; | |
list(options: BoxOptions & { items: string[] }): Box; | |
form(options: BoxOptions): Box; | |
input(options: BoxOptions): Box; | |
textarea(options: BoxOptions): Box; | |
button(options: BoxOptions): Box; | |
checkbox(options: BoxOptions): Box; | |
radioset(options: BoxOptions): Box; | |
radiobutton(options: BoxOptions): Box; | |
table(options: BoxOptions & { rows: string[][] }): Box; | |
prompt(options: BoxOptions): Box; | |
question(options: BoxOptions): Box; | |
message(options: BoxOptions): Box; | |
loading(options: BoxOptions): Box; | |
progressbar(options: BoxOptions): Box; | |
log(options: BoxOptions): Box; | |
terminal(options: BoxOptions): Box; | |
image(options: BoxOptions & { file: string }): Box; | |
video(options: BoxOptions & { file: string }): Box; | |
layout(options: BoxOptions): Box; | |
} | |
const blessed: Blessed; | |
export = blessed; | |
// Text widget | |
export interface TextOptions extends ElementOptions { | |
content?: string; | |
align?: 'left' | 'center' | 'right'; | |
} | |
export interface Text extends Element { | |
content: string; | |
setContent(content: string): void; | |
getContent(): string; | |
} | |
// Line widget | |
export interface LineOptions extends BoxOptions { | |
orientation?: 'horizontal' | 'vertical'; | |
type?: 'line' | 'bg'; | |
ch?: string; | |
} | |
export interface Line extends Box { | |
orientation: 'horizontal' | 'vertical'; | |
type: 'line' | 'bg'; | |
ch: string; | |
} | |
// ScrollableBox widget (deprecated) | |
export interface ScrollableBoxOptions extends BoxOptions { | |
alwaysScroll?: boolean; | |
scrollable?: boolean; | |
mouse?: boolean; | |
scrollbar?: boolean | { | |
ch?: string; | |
track?: { bg?: string }; | |
style?: ElementStyle; | |
}; | |
} | |
export interface ScrollableBox extends Box { | |
scroll: number; | |
scrollable: boolean; | |
getScroll(): number; | |
setScroll(index: number): void; | |
scrollTo(index: number): void; | |
getScrollHeight(): number; | |
getScrollPerc(): number; | |
setScrollPerc(percentage: number): void; | |
} | |
// ScrollableText widget (deprecated) | |
export interface ScrollableTextOptions extends ScrollableBoxOptions { | |
content?: string; | |
} | |
export interface ScrollableText extends ScrollableBox { | |
content: string; | |
setContent(content: string): void; | |
getContent(): string; | |
} | |
// BigText widget | |
export interface BigTextOptions extends BoxOptions { | |
content?: string; | |
font?: string; | |
} | |
export interface BigText extends Box { | |
content: string; | |
font: string; | |
setContent(content: string): void; | |
getContent(): string; | |
} | |
// List widget | |
export interface ListOptions extends BoxOptions { | |
items?: string[]; | |
selected?: number; | |
mouse?: boolean; | |
keys?: boolean; | |
vi?: boolean; | |
interactive?: boolean; | |
style?: ElementStyle & { | |
selected?: ElementStyle; | |
item?: ElementStyle; | |
}; | |
} | |
export interface List extends Box { | |
items: string[]; | |
selected: number; | |
interactive: boolean; | |
value: string; | |
add(item: string): void; | |
removeItem(item: string): void; | |
pushItem(item: string): void; | |
popItem(): string; | |
unshiftItem(item: string): void; | |
shiftItem(): string; | |
insertItem(i: number, item: string): void; | |
getItem(i: number): string; | |
setItem(i: number, item: string): void; | |
clearItems(): void; | |
setItems(items: string[]): void; | |
move(offset: number): void; | |
up(amount?: number): void; | |
down(amount?: number): void; | |
pick(callback: (item: string, index: number) => void): void; | |
} | |
// FileManager widget | |
export interface FileManagerOptions extends ListOptions { | |
cwd?: string; | |
path?: string; | |
} | |
export interface FileManager extends List { | |
cwd: string; | |
path: string; | |
refresh(callback?: (err: Error | null, files: string[]) => void): void; | |
pick(callback: (file: string) => void): void; | |
reset(): void; | |
} | |
// ListTable widget | |
export interface ListTableOptions extends ListOptions { | |
rows?: string[][]; | |
pad?: number; | |
noCellBorders?: boolean; | |
style?: ElementStyle & { | |
header?: ElementStyle; | |
cell?: ElementStyle; | |
}; | |
} | |
export interface ListTable extends List { | |
rows: string[][]; | |
setRows(rows: string[][]): void; | |
setData(rows: string[][]): void; | |
} | |
// Listbar widget | |
export interface ListbarOptions extends BoxOptions { | |
commands?: { [key: string]: () => void }; | |
autoCommandKeys?: boolean; | |
} | |
export interface Listbar extends Box { | |
commands: { [key: string]: () => void }; | |
setCommands(commands: { [key: string]: () => void }): void; | |
add(item: string, callback: () => void): void; | |
remove(item: string): void; | |
select(offset: number): void; | |
} | |
// Form widget | |
export interface FormOptions extends BoxOptions { | |
keys?: boolean; | |
vi?: boolean; | |
} | |
export interface Form extends Box { | |
submission: any; | |
submit(): void; | |
cancel(): void; | |
reset(): void; | |
} | |
// Input widget (abstract) | |
export interface InputOptions extends BoxOptions { | |
inputOnFocus?: boolean; | |
mouse?: boolean; | |
} | |
export interface Input extends Box { | |
input: boolean; | |
value: string; | |
setValue(value: string): void; | |
getValue(): string; | |
clearInput(): void; | |
submit(): void; | |
cancel(): void; | |
} | |
// Textarea widget | |
export interface TextareaOptions extends InputOptions { | |
inputOnFocus?: boolean; | |
scrollable?: boolean; | |
scrollbar?: boolean | { | |
ch?: string; | |
track?: { bg?: string }; | |
style?: ElementStyle; | |
}; | |
} | |
export interface Textarea extends Input { | |
value: string; | |
setValue(value: string): void; | |
getValue(): string; | |
clearInput(): void; | |
submit(): void; | |
cancel(): void; | |
} | |
// Button widget | |
export interface ButtonOptions extends InputOptions { | |
content?: string; | |
align?: 'left' | 'center' | 'right'; | |
} | |
export interface Button extends Input { | |
pressed: boolean; | |
press(): void; | |
} | |
// Checkbox widget | |
export interface CheckboxOptions extends InputOptions { | |
text?: string; | |
checked?: boolean; | |
} | |
export interface Checkbox extends Input { | |
text: string; | |
checked: boolean; | |
check(): void; | |
uncheck(): void; | |
toggle(): void; | |
} | |
// RadioSet widget | |
export interface RadioSetOptions extends BoxOptions { | |
spacing?: number; | |
} | |
export interface RadioSet extends Box { | |
value: string; | |
add(text: string, value?: string): void; | |
remove(element: RadioButton): void; | |
} | |
// RadioButton widget | |
export interface RadioButtonOptions extends CheckboxOptions { | |
text?: string; | |
checked?: boolean; | |
} | |
export interface RadioButton extends Checkbox { | |
text: string; | |
checked: boolean; | |
} | |
// Prompt widget | |
export interface PromptOptions extends BoxOptions { | |
question?: string; | |
} | |
export interface Prompt extends Box { | |
input: Input; | |
ask(question: string, callback: (err: Error | null, value: string) => void): void; | |
} | |
// Question widget | |
export interface QuestionOptions extends BoxOptions { | |
question?: string; | |
} | |
export interface Question extends Box { | |
ask(question: string, callback: (err: Error | null, value: boolean) => void): void; | |
} | |
// Message widget | |
export interface MessageOptions extends BoxOptions { | |
text?: string; | |
} | |
export interface Message extends Box { | |
display(text: string, time?: number, callback?: () => void): void; | |
error(text: string, time?: number, callback?: () => void): void; | |
log(text: string, time?: number, callback?: () => void): void; | |
} | |
// Loading widget | |
export interface LoadingOptions extends BoxOptions { | |
text?: string; | |
} | |
export interface Loading extends Box { | |
load(text: string): void; | |
stop(): void; | |
} | |
// ProgressBar widget | |
export interface ProgressBarOptions extends InputOptions { | |
orientation?: 'horizontal' | 'vertical'; | |
filled?: number; | |
value?: number; | |
pch?: string; | |
} | |
export interface ProgressBar extends Input { | |
progress: number; | |
filled: number; | |
value: number; | |
setProgress(value: number): void; | |
reset(): void; | |
} | |
// Log widget | |
export interface LogOptions extends ScrollableTextOptions { | |
scrollback?: number; | |
scrollOnInput?: boolean; | |
} | |
export interface Log extends ScrollableText { | |
scrollback: number; | |
log(text: string, time?: number): void; | |
add(text: string): void; | |
} | |
// Table widget | |
export interface TableOptions extends BoxOptions { | |
rows?: string[][]; | |
pad?: number; | |
noCellBorders?: boolean; | |
style?: ElementStyle & { | |
header?: ElementStyle; | |
cell?: ElementStyle; | |
}; | |
} | |
export interface Table extends Box { | |
rows: string[][]; | |
setRows(rows: string[][]): void; | |
setData(rows: string[][]): void; | |
} | |
// Terminal widget | |
export interface TerminalOptions extends BoxOptions { | |
shell?: string; | |
args?: string[]; | |
env?: NodeJS.ProcessEnv; | |
cwd?: string; | |
} | |
export interface Terminal extends Box { | |
pty: any; | |
write(data: string): void; | |
screenshot(xi?: number, xl?: number, yi?: number, yl?: number): string; | |
} | |
// Image widget | |
export interface ImageOptions extends BoxOptions { | |
file: string; | |
type?: 'ansi' | 'overlay'; | |
} | |
export interface Image extends Box { | |
file: string; | |
type: 'ansi' | 'overlay'; | |
setImage(file: string, callback?: (err?: Error) => void): void; | |
} | |
// ANSIImage widget | |
export interface ANSIImageOptions extends ImageOptions { | |
animate?: boolean; | |
speed?: number; | |
} | |
export interface ANSIImage extends Image { | |
animate: boolean; | |
speed: number; | |
start(): void; | |
stop(): void; | |
} | |
// OverlayImage widget | |
export interface OverlayImageOptions extends ImageOptions { | |
width?: number | 'shrink'; | |
height?: number | 'shrink'; | |
} | |
export interface OverlayImage extends Image { | |
width: number | 'shrink'; | |
height: number | 'shrink'; | |
} | |
// Video widget | |
export interface VideoOptions extends BoxOptions { | |
file: string; | |
start?: boolean; | |
} | |
export interface Video extends Box { | |
file: string; | |
start(): void; | |
stop(): void; | |
} | |
// Layout widget | |
export interface LayoutOptions extends ElementOptions { | |
renderer?: (coords: ElementPosition) => void; | |
} | |
export interface Layout extends Element { | |
renderer: (coords: ElementPosition) => void; | |
realloc(): void; | |
} | |
// Update Blessed interface to include all widget constructors | |
export interface Blessed { | |
// ... existing methods ... | |
text(options: TextOptions): Text; | |
line(options: LineOptions): Line; | |
scrollablebox(options: ScrollableBoxOptions): ScrollableBox; | |
scrollabletext(options: ScrollableTextOptions): ScrollableText; | |
bigtext(options: BigTextOptions): BigText; | |
list(options: ListOptions): List; | |
filemanager(options: FileManagerOptions): FileManager; | |
listtable(options: ListTableOptions): ListTable; | |
listbar(options: ListbarOptions): Listbar; | |
form(options: FormOptions): Form; | |
input(options: InputOptions): Input; | |
textarea(options: TextareaOptions): Textarea; | |
button(options: ButtonOptions): Button; | |
checkbox(options: CheckboxOptions): Checkbox; | |
radioset(options: RadioSetOptions): RadioSet; | |
radiobutton(options: RadioButtonOptions): RadioButton; | |
prompt(options: PromptOptions): Prompt; | |
question(options: QuestionOptions): Question; | |
message(options: MessageOptions): Message; | |
loading(options: LoadingOptions): Loading; | |
progressbar(options: ProgressBarOptions): ProgressBar; | |
log(options: LogOptions): Log; | |
table(options: TableOptions): Table; | |
terminal(options: TerminalOptions): Terminal; | |
image(options: ImageOptions): Image; | |
ansiimage(options: ANSIImageOptions): ANSIImage; | |
overlayimage(options: OverlayImageOptions): OverlayImage; | |
video(options: VideoOptions): Video; | |
layout(options: LayoutOptions): Layout; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment