Skip to content

Core

Everything in TermUI sits on top of @termuijs/core. It handles the screen buffer, input decoding, layout computation, style data, events, and the application lifecycle.

If you only install one package, this is it.

Installation

·CODE
npm install @termuijs/core

What's inside

ExportWhat it does
AppWires terminal, input, screen, and render loop together
ScreenDouble-buffered cell grid with diff-based rendering
RendererDiffs screen buffers and flushes changes to stdout
TerminalRaw mode, alt screen, cursor control, clipboard, bell, notifications, resize events
InputParserDecodes raw stdin bytes into key, mouse, and paste events
MouseGesturesSynthesizes double-click and drag events from raw mouse events
ChordMatcherBinds multi-key sequences (vim-style chords) to handlers
EventEmitterType-safe publish/subscribe
FocusManagerTab-order focus cycling across widgets
createLayoutNode / computeLayoutFlexbox-inspired layout engine
resolveConstraints / ConstraintConstraint-based axis splitting for dashboard-style layouts
Pos / Dim / resolveLayoutVariablesPosition and dimension algebra for overlay and absolute layouts
prefersReducedMotion / shouldUseColor / prefersHighContrastEnvironment capability helpers
defaultStyle / mergeStylesStyle objects. colors, bold, dim, underline
parseColorNamed, hex, and RGB color parsing
stringWidth / truncate / wordWrapUnicode-aware string measurement and wrapping

Quick example

·CODE
import { App } from '@termuijs/core'
import { Box, Text } from '@termuijs/widgets'

const root = new Box({ border: 'round', padding: 1 })
root.addChild(new Text('Hello, TermUI!', { bold: true }))

const app = new App(root)

app.events.on('key', (event) => {
    if (event.key === 'q') app.exit()
})

await app.mount()

How other packages use core

  • @termuijs/widgets renders into the Screen buffer and uses the layout engine for positioning
  • @termuijs/tss builds on top of the Style interface, adding CSS-like variables and themes
  • @termuijs/router plugs into the App lifecycle for screen transitions
  • @termuijs/motion animates style properties through the render loop