Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BlessedElement<Options>

Abstract base element. Elements are Node that are rendered visually so they have dimention, position, content, border, padding, etc.

Content Methods

  • Methods for dealing with text content, line by line. Useful for writing a text editor, irc client, etc.

  • Note: All of these methods deal with pre-aligned, pre-wrapped text. If you use deleteTop() on a box with a wrapped line at the top, it may remove 3-4 "real" lines (rows) depending on how long the original line was.

  • The lines parameter can be a string or an array of strings. The line parameter must be a string.

Type parameters

Hierarchy

Implements

Index

Constructors

constructor

Properties

$

$: object

An object for any miscellanous user data.

Type declaration

  • [index: string]: any

_

_: object

An object for any miscellanous user data.

Type declaration

  • [index: string]: any

Optional _label

_label: BlessedElement | undefined

Get's the child element implementing the current label of this node.

internal

abottom

abottom: number

Calculated absolute bottom offset.

aleft

aleft: number

Calculated absolute left offset.

aright

aright: number

Calculated absolute right offset.

atop

atop: number

Calculated absolute top offset.

bg

bg: number

Border foreground and background, must be numbers (-1 for default).

bold

bold: string

Border attributes.

border

border: TBorder

Border object.

bottom

bottom: number | string

Calculated relative bottom offset.

children

children: Node[]

Array of node's children.

content

content: string

data

data: object

An object for any miscellanous user data.

Type declaration

  • [index: string]: any

detached

detached: boolean

draggable

draggable: boolean

Whether the element is draggable. Set to true to allow dragging.

fg

fg: number

focusable

focusable: boolean

height

height: number | string

Calculated height.

hidden

hidden: boolean

iheight

iheight: TPosition

ileft

ileft: TTopLeft

index

index: number

Render index (document order index) of the last render call.

itop

itop: TTopLeft

iwidth

iwidth: TPosition

left

left: number | string

Calculated relative left offset.

lpos

name

name: string

Name of the element. Useful for form submission.

options

options: Options

Original options object.

padding

padding: Required<Padding>

Current element padding

Optional parent

parent: Node

Parent node. If null it means the element is not attached to any screen or program, or the node is a Screen.

position

position: Position

rbottom

rbottom: TPosition

Calculated relative bottom offset.

right

right: number | string

Calculated relative right offset.

rleft

rleft: TTopLeft

Calculated relative left offset.

rright

rright: TPosition

Calculated relative right offset.

rtop

rtop: TTopLeft

Calculated relative top offset.

screen

screen: Screen

Parent screen.

shrink

shrink: boolean

style

style: TStyle

top

top: number | string

Calculated relative top offset.

type

type: string

Type of the node (e.g. box).

uid

uid: number

Unique identifier for Node instances. @internal

underline

underline: string

width

width: number | string

Calculated width.

Static defaultMaxListeners

defaultMaxListeners: number

Methods

_align

  • _align(line: string, width: number, align: string): void
  • internal

    Parameters

    • line: string
    • width: number
    • align: string

    Returns void

_getCoords

  • _getCoords(get?: boolean, noscroll?: boolean): Coords | undefined
  • Parameters

    • Optional get: boolean
    • Optional noscroll: boolean

    Returns Coords | undefined

_getHeight

  • _getHeight(get?: boolean): number

_getLeft

  • _getLeft(get?: boolean): number

_getPos

  • _getPos(): Pos

_getTop

  • _getTop(get?: boolean): number

_getWidth

  • _getWidth(get?: boolean): number

_parseAttr

  • _parseAttr(ines: string[]): string[]

_parseTags

  • _parseTags(s: string): string
  • Converts {red-fg}foo{/red-fg} to \x1b[31mfoo\x1b[39m. @internal.

    Parameters

    • s: string

    Returns string

_wrapContent

  • _wrapContent(content: string, width: number): void
  • internal

    Parameters

    • content: string
    • width: number

    Returns void

addListener

  • addListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

append

  • append(node: Node): void

clearBaseLine

  • clearBaseLine(i: number): void
  • Clear a line from the box's content from the visible top.

    Parameters

    • i: number

    Returns void

clearLine

  • clearLine(i: number): void
  • Clear a line from the box's content.

    Parameters

    • i: number

    Returns void

clearPos

  • clearPos(): void
  • Cleans the rectangle of this element on the screen. Useful for subclasses before rendering. @internal

    Returns void

collectAncestors

  • collectAncestors(s?: boolean): void

collectDescendants

  • collectDescendants(s?: boolean): void

deleteBottom

  • deleteBottom(): void

deleteLine

  • deleteLine(i: number): void
  • Delete a line from the box's content.

    Parameters

    • i: number

    Returns void

deleteTop

  • deleteTop(): void

destroy

  • destroy(): void
  • Same as the detach() method, except this will automatically call free() and unbind any screen events to prevent memory leaks. for use with onScreenEvent(), removeScreenEvent(), and free().

    Returns void

detach

  • detach(): void

disableDrag

  • disableDrag(): void

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

emitAncestors

  • emitAncestors(): void

emitDescendants

  • emitDescendants(type?: string, ...args: any[]): void
  • Emit event for element, and recursively emit same event for all descendants. If s is provided it will call [[iter]] on self first.

    Parameters

    • Optional type: string
    • Rest ...args: any[]

    Returns void

enableDrag

  • enableDrag(): void

enableInput

  • enableInput(): void
  • Enable key and mouse events. Calls bot enableMouse and enableKeys.

    Returns void

enableKeys

  • enableKeys(): void
  • Enable keypress events for the element (automatically called when a form of on('keypress') is bound).

    Returns void

enableMouse

  • enableMouse(): void
  • Enable mouse events for the element (automatically called when a form of on('mouse') is bound).

    Returns void

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

focus

  • focus(): void

forAncestors

  • forAncestors(iter: function, s?: boolean): void

forDescendants

  • forDescendants(iter: function, s?: boolean): void
  • Visit each node's descendants, with [[iter]] function, parents first. If s is provided it will call [[iter]] on self first.

    Parameters

    • iter: function
        • (node: Node): void
        • Parameters

          Returns void

    • Optional s: boolean

    Returns void

free

  • free(): void
  • Free up the element. Automatically unbind all events that may have been bound to the screen object. This prevents memory leaks. For use with onScreenEvent(), removeScreenEvent(), and destroy().

    Returns void

get

  • get<T>(name: string, def: T): T
  • Get user property with a potential default value.

    Type parameters

    • T

    Parameters

    • name: string
    • def: T

    Returns T

getBaseLine

  • getBaseLine(i: number): string
  • Get a line from the box's content from the visible top.

    Parameters

    • i: number

    Returns string

getContent

  • getContent(): string
  • Return content, slightly different from el.content. Assume the above formatting.

    Returns string

getLine

  • getLine(i: number): string
  • Get a line from the box's content.

    Parameters

    • i: number

    Returns string

getLines

  • getLines(): string[]
  • An array containing the content lines.

    Returns string[]

getMaxListeners

  • getMaxListeners(): number
  • Returns number

getScreenLines

  • getScreenLines(): string[]
  • An array containing the lines as they are displayed on the screen.

    Returns string[]

getText

  • getText(): string
  • Similar to getContent, but return content with tags and escape codes removed.

    Returns string

hasAncestor

hasDescendant

hide

  • hide(): void

insert

  • insert(node: Node, index: number): void
  • Insert a node to this node's children at index i.

    Parameters

    • node: Node
    • index: number

    Returns void

insertAfter

  • insertAfter(node: Node, refNode: Node): void

insertBefore

  • insertBefore(node: Node, refNode: Node): void

insertBottom

  • insertBottom(lines: string | string[]): void
  • Insert a line at the bottom of the box.

    Parameters

    • lines: string | string[]

    Returns void

insertLine

  • insertLine(i: number, lines: string | string[]): void
  • Insert a line into the box's content.

    Parameters

    • i: number
    • lines: string | string[]

    Returns void

insertTop

  • insertTop(lines: string | string[]): void
  • Insert a line at the top of the box.

    Parameters

    • lines: string | string[]

    Returns void

key

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

off

  • off(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

on

onScreenEvent

  • onScreenEvent(type: string, handler: function): void
  • Same as el.on('screen', ...) except this will automatically keep track of which listeners are bound to the screen object. For use with removeScreenEvent(), free(), and destroy().

    Parameters

    • type: string
    • handler: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns void

once

  • once(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

onceKey

parseContent

  • parseContent(noTags: string): boolean
  • internal

    parses given content string with no tags before rendering. Removes / transform characters that break the output . For example, double-width chars will eat the next char after render in this case it creates a blank character after it so it doesn't eat the real next char.

    Parameters

    • noTags: string

    Returns boolean

popLine

  • popLine(i: number): string
  • Pop a line off the bottom of the content.

    Parameters

    • i: number

    Returns string

prepend

  • prepend(node: Node): void

prependListener

  • prependListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

pushLine

  • pushLine(lines: string | string[]): void
  • Push a line onto the bottom of the content.

    Parameters

    • lines: string | string[]

    Returns void

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

remove

  • remove(node: Node): void

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeHover

  • removeHover(): void

removeKey

removeLabel

  • removeLabel(): any

removeListener

  • removeListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

removeScreenEvent

  • removeScreenEvent(type: string, handler: function): void
  • Same asel.removeListener('screen', ...) except this will automatically keep track of which listeners are bound to the screen object. For use with onScreenEvent(), free(), and destroy().

    Parameters

    • type: string
    • handler: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns void

render

  • render(): Coords | undefined

sattr

  • sattr(style: TStyle, fg?: string, bg?: string): any
  • calculates the value for style (could be substyle like style.bar) to paint in the screen according to the rest of the properties and optionally bg and fg.

    Parameters

    • style: TStyle
    • Optional fg: string
    • Optional bg: string

    Returns any

screenshot

  • screenshot(xi: number, xl: number, yi: number, yl: number): string
  • screenshot(): void
  • Take an SGR screenshot of the screen within the region. Returns a string containing only characters and SGR codes. Can be displayed by simply echoing it in a terminal.

    Parameters

    • xi: number
    • xl: number
    • yi: number
    • yl: number

    Returns string

  • Take an SGR screenshot of the whole screen. Returns a string containing only characters and SGR codes. Can be displayed by simply echoing it in a terminal.

    Returns void

set

  • set(name: string, value: any): void
  • Set user property to value.

    Parameters

    • name: string
    • value: any

    Returns void

setBack

  • setBack(): void

setBaseLine

  • setBaseLine(i: number, line: string | string[]): void
  • Set a line in the box's content from the visible top.

    Parameters

    • i: number
    • line: string | string[]

    Returns void

setContent

  • setContent(text: string, noClear?: boolean, noTags?: boolean): void
  • Set the content. Note: When text is input, it will be stripped of all non-SGR escape codes, tabs will be replaced with 8 spaces, and tags will be replaced with SGR codes (if enabled).

    Parameters

    • text: string
    • Optional noClear: boolean
    • Optional noTags: boolean

    Returns void

setFront

  • setFront(): void

setHover

  • text/options - Set a hover text box to follow the cursor. Similar to the "title" DOM attribute in the browser. Example options: {text:'foo'}

    Parameters

    Returns void

setIndex

  • setIndex(z: number): void
  • Change this element's index in its parent's children array. This will change the rendering order. If all elements are positioned by their selves then this could be similar to CSS z-index property. But if you are using a layout or relaying somhow in the children order then it will change the position of this element and its siblings.

    Parameters

    • z: number

    Returns void

setLabel

  • text/options - Set the label text for the top-left corner. Example options: {text:'foo',side:'left'}

    Parameters

    Returns void

setLine

  • setLine(i: number, line: string | string[]): void
  • Set a line in the box's content.

    Parameters

    • i: number
    • line: string | string[]

    Returns void

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

setText

  • setText(text: string, noClear?: boolean): void
  • Similar to setContent, but ignore tags and remove escape codes.

    Parameters

    • text: string
    • Optional noClear: boolean

    Returns void

shiftLine

  • shiftLine(i: number): void
  • Shift a line off the top of the content.

    Parameters

    • i: number

    Returns void

show

  • show(): void

strWidth

  • strWidth(text: string): string
  • Get a string's displayed width, taking into account double-width, surrogate pairs, combining characters, tags, and SGR escape codes.

    Parameters

    • text: string

    Returns string

toggle

  • toggle(): void

unkey

unshiftLine

  • unshiftLine(lines: string | string[]): void
  • Unshift a line onto the top of the content.

    Parameters

    • lines: string | string[]

    Returns void

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Generated using TypeDoc