Overview

Render static or formatted text.

Import

import { Text } from 'nikcli-tui';

Usage

new Text({ parent: screen, content: 'Hello', align: 'center' });

Live Preview

Run Locally

npm run tsx:core-gallery

Props

Text-specific Props

PropertyTypeRequiredDefaultDescription
contentstringYes-Text content to display (min 1 character)
align"left" | "center" | "right"No"left"Text alignment
wrapbooleanNofalseEnable text wrapping
shrinkbooleanNo-Shrink text to fit (from component-schemas)
boldbooleanNofalseApply bold styling
italicbooleanNofalseApply italic styling
underlinebooleanNofalseApply underline styling
blinkbooleanNo-Apply blink styling (from component-schemas)

Inherited Base Props

The Text component extends BasePropsSchema and includes all standard TUI component properties:
PropertyTypeDefaultDescription
parentblessed.Widgets.Node-Parent blessed element
variantComponentVariant"default"Component variant
sizeComponentSize-Component size
bgColorValue-Background color
fgColorValue-Foreground color
borderStyle"line" | "double" | "round" | "bold" | "classic" | "none""none"Border style (defaults to none)

Zod Schema Validation

The Text component uses Zod for runtime type validation:
import { TextSchema } from 'nikcli-tui';

const TextSchema = BasePropsSchema.extend({
  // Text content
  content: z.string().min(1, "Text content cannot be empty"),
  
  // Text display options
  align: z.enum(["left", "center", "right"]).optional(),
  wrap: z.boolean().optional(),
  
  // Text styling
  bold: z.boolean().optional(),
  italic: z.boolean().optional(),
  underline: z.boolean().optional(),
}).strict();

Methods

Instance Methods

MethodParametersReturn TypeDescription
setTexttext: stringvoidUpdates the text content with ANSI sanitization
destroy-voidCleanup method from base component

Static Methods

MethodParametersReturn TypeDescription
Text.createprops: TextPropsTextFactory method to create new text instance

Text Safety Features

  • ANSI Sanitization: Automatically strips unwanted ANSI sequences for safe rendering
  • Unicode Support: Handles Unicode characters properly
  • Content Validation: Ensures content is not empty via Zod schema

Installation

npm i nikcli-tui

Import

import { Text } from 'nikcli-tui';

Quick Start

new Text({ parent: screen, top: 1, left: 2, content: 'Welcome' });

Production Examples

new Text({ parent: screen, top: 2, left: 2, width: 30, content: 'Hello', align: 'center' });

Best Practices

  • Usa Paragraph per testo lungo; Text per brevi etichette/valori.