A lightweight, zero-dependency, component-based Terminal User Interface (TUI) framework for Node.js. Engineered to work seamlessly in both modern terminal emulators and raw Linux virtual consoles (TERM=linux / TTY).
- Zero Dependencies: Built purely on standard Node.js modules (
node:readline). - Flicker-Free Rendering: Full-frame buffering, line-end clearing, and batched re-renders via
setImmediate. - Flexbox Layout Engine: Responsive
Flex,Row, andColumncontainers supportingflexratios, fixed sizes, auto-sizing, andgap. - TTY-Safe ANSI Styling: Chainable style builder (
ANSI.bold.bgBlue.brightWhite(...)) compatible with the 16-color VGA TTY palette, including nested background preservation. - Page Routing & Input Isolation:
PageandPageManagercomponents that isolate keyboard events and local hotkeys to the active view.
Clone the repository or install it locally in your project:
npm i tiny-tuiimport { App, Component, ANSI, Flex, Box, SelectList } from 'tiny-tui';
class MainScreen extends Component {
constructor(onExit) {
super();
this.state = { status: 'Ready' };
// Mount child components to automatically propagate state updates and key events
this.menu = this.mount(new SelectList({
items: ['Run Task', 'Check Status', 'Exit'],
onSelect: (item) => {
if (item === 'Exit') return onExit();
this.setState({ status: `Executed: ${ANSI.green(item)}` });
},
}));
}
render(width, height) {
return new Flex({
direction: 'column',
width,
height,
children: [
new Box({
title: ANSI.bold.inverse.brightYellow(' SYSTEM MONITOR '),
children: [`Status: ${this.state.status}`],
}),
new Box({
title: 'ACTIONS',
flex: 1,
children: [this.menu],
}),
],
}).render(width, height);
}
}
const app = new App(new MainScreen(() => app.exit()));
app.start();- Dual-Pane Terminal File Manager — A Midnight Commander–style dual-pane file manager written using
tiny-tui, featuring directory browsing, sorting, and file operations (copy, move, delete).
new App(rootComponent): Initializes alternate screen buffer, hides cursor, enables raw TTY input, handles terminalresizeevents, and restores terminal state cleanly on exit or crash.this.mount(child): Registers a child component so itssetState()triggers a screen re-render and keyboard events bubble down automatically.this.setState(partialState): Merges new state and schedules a batched UI update.
Distributes available terminal space across child elements:
direction:'row'|'column'(shorthandsRowandColumnare also exported).flex: Proportional weight for remaining space (e.g.,flex: 1,flex: 2).width/height: Fixed dimensions in character cells (auto-calculated from content if omitted).gap: Spacing in cells/lines between child items.
Draws a bordered container around content:
title: Header text displayed on the top border (preserves custom ANSI styles).borderColor: Style function applied to border characters (e.g.,ANSI.cyan).scrollBottom: Whentrue, automatically keeps the latest lines visible if content overflows the box height.
Interactive vertical menu with Up/Down arrow navigation and Enter selection:
items: Array of strings to display.onSelect(item): Callback triggered whenEnteris pressed.
Manages multi-screen applications with isolated hotkeys:
Page: Extend this class to build custom views. Usethis.setHotkeys([{ key, label, action }])to bind page-specific shortcuts andthis.renderHotkeys()to render a formatted hotkey bar anywhere in your layout.PageManager: Accepts{ pages, initialPage }and routesrender()andhandleKey()calls exclusively to the active page viamanager.goTo(pageName).
ANSI: Chainable color and modifier builder (bold,dim,inverse,red,green,yellow,cyan,gray,brightWhite,bgBlue,bgYellow, etc.) plusANSI.style(stylesArray, text).- String Helpers:
stripAnsi(str),visibleLength(str),truncateAnsi(str, maxLen),padRight(str, len), andpadLeft(str, len).
The test suite uses the built-in Node.js test runner (node:test) with zero external dependencies:
npm test