Skip to content

Latest commit

 

History

History
118 lines (67 loc) · 3.85 KB

Document.md

File metadata and controls

118 lines (67 loc) · 3.85 KB

Document

The Document element is the main Element of the document model: it represents the whole document just like the document object of the browser DOM. Most use cases just need one document, mapping the whole terminal area.

It is the necessary top-level Element, on top of all other widgets, since it manages drawing/redrawing of them, as well as event dispatching, and so on. All other elements are children of a document or children of children of (children of... etc) a document: they just don't work without it.

Being a Container, it is backed by a screenBuffer.

So widgets are first drawn to the document's screenBuffer, and then the document's screenBuffer is delta-optimized drawn to the underlying terminal.

TODOC

Table of Contents

Events

key

See Element's key event.

Key Bindings

  • focusNext: give the focus the next element, default: "TAB"
  • focusPrevious: give the focus the previous element, default: "SHIFT_TAB"

new Document( options )

  • options Object, where:
    • all the base class Container's constructor options
    • outputDst Terminal or ScreenBuffer this is the object where the document should be drawn into, it is set automatically when using term.createDocument() instead of new termkit.Document().
    • eventSource EventEmitter or any EventEmitter-compatible objects (e.g. nextgen-events) it is set automatically when using term.createDocument() instead of new termkit.Document().
    • outputX, outputY, outputWidth, outputHeight integer (optional) the position and size of the document with respect to the screen (i.e. the outputDst)
    • keyBindings Object having a Terminal Kit key name as the key and an action as value (see above)
    • noDraw boolean if true, don't draw the document on instantiation (default: false, draw immediately)

Instead of using new termkit.Document(), it's recommended to use term.createDocument(): it set automatically some options like outputDst and eventSource to term.

This creates a document mapping an area of the terminal (or even an area of another screenBuffer).

.giveFocusTo( element )

  • element Element the element to give focus to

Give the focus to an Element.

.focusNext()

Give the focus to the next focusable Element. This is usually done internally when the user press the TAB key or any keys binded to the focusNext action.

.focusPrevious()

Give the focus to the previous focusable Element. This is usually done internally when the user press the SHIFT_TAB key or any keys binded to the focusPrevious action.

.createShortcuts()

TODOC / unstable

.removeElementShortcuts()

TODOC / unstable