Overview

Display and scroll application logs.

Import

import { LogViewer } from 'nikcli-tui';

Usage

new LogViewer({ parent: screen, blessedProps: { content: 'log line 1' } as any });

Live Preview

Run Locally

npm run tsx:core-gallery

Props

  • maxLines?: number — Retained lines (default 500).
  • autoScroll?: boolean — Scroll to bottom on push (default true).
  • timestamp?: boolean — Prefix lines with [HH:MM:SS].
  • BaseProps: scrollable container with label ‘Logs’ by default.

Methods

  • push(line), clear().
  • setMaxLines(n), setAutoScroll(bool), setTimestamp(bool).
  • getLogCount(), scrollToTop(), scrollToBottom().

Installation

npm i nikcli-tui

Import

import { LogViewer } from 'nikcli-tui';

Quick Start

const logs = new LogViewer({ parent: screen, top: 1, left: 2, width: 60, height: 10, label: 'Logs' });
logs.push('Server started');

Production Examples

const lv = new LogViewer({ parent: screen, top: 1, left: 2, width: 60, height: 10, autoScroll: true, timestamp: true });
lv.push('Connected');

Testing

logs.push('A');
logs.push('B');
expect(logs.getLogCount()).toBeGreaterThan(0);

Best Practices

  • Mantieni maxLines ragionevole (200–1000) per performance ottimali.