celina

Celina CLI Library

A powerful Terminal User Interface library for Nim, inspired by Ratatui. Provides high-performance, type-safe components for building interactive terminal applications with both synchronous and asynchronous support.

Basic Usage:

import pkg/celina

proc main() =
  var app = newApp()
  app.run()

when isMainModule:
  main()

Async Usage (requires Chronos and -d:asyncBackend=chronos):

import pkg/celina

proc main() {.async.} =
  var app = newAsyncApp()
  await app.runAsync()

when isMainModule:
  waitFor main()

Procs

proc celinaVersion(): string {....raises: [], tags: [], forbids: [].}
Get the library version string
proc quickRun(eventHandler: proc (event: Event): bool;
              renderHandler: proc (buffer: var Buffer); config: AppConfig = AppConfig(
    title: "Celina App", alternateScreen: true, mouseCapture: false,
    rawMode: true, windowMode: false, targetFps: 60)) {.
    ...raises: [ValueError, Exception, TerminalError, CatchableError],
    tags: [TimeEffect, WriteIOEffect, RootEffect, ReadIOEffect], forbids: [].}

Quick way to run a simple CLI application

Example:

quickRun(
  eventHandler = proc(event: Event): bool =
    case event.kind
    of EventKind.Key:
      if event.key.code == KeyCode.Char and event.key.char == 'q':
        return false
    else: discard
    return true,
  
  renderHandler = proc(buffer: var Buffer) =
    buffer.clear()
    let area = buffer.area
    buffer.setString(10, area.height div 2, "Press 'q' to quit", defaultStyle())
)

Exports

Position, size, position, isValid, contains, rect, size, shrink, isValid, contains, union, $, right, center, Area, $, Size, -, isEmpty, Rect, pos, area, area, expand, shrink, intersects, bottom, +, intersection, $, rect, indigo, color256, grayscale, toAnsiCode, ==, withModifiers, ColorKind, $, Style, $, deepSkyBlue, hotPink, toAnsiCode, bold, color256, reversed, hsv, Color, rgb, hsvToRgb, ColorValue, withBg, style, ==, withFg, brightColors, color, default, rgb, salmon, teal, addModifier, italic, violet, cubeColor, toAnsiSequence, RgbColor, crimson, limeGreen, withBg, $, style, ==, defaultColor, orange, lerp, underline, toAnsiCode, defaultStyle, withFg, darkColors, resetSequence, gold, toBgAnsiCode, lerp, StyleModifier, rgb, toAnsiCode, removeModifier, pastels, diff, clear, []=, isEmpty, isValidPos, fill, Buffer, ==, cell, Cell, ==, setString, merge, setRunes, isValidPos, setString, []=, $, $, [], runeWidth, runesWidth, width, cell, merge, newBuffer, cell, toStrings, setString, resize, setRunes, setString, newBuffer, [], readKeyInput, readKey, MouseEventKind, resizeDetected, KeyCode, KeyModifier, pollKey, waitForKey, initSignalHandling, waitForAnyKey, pollEvents, Event, checkResize, MouseButton, KeyEvent, MouseEvent, hasInput, EventKind, min, twoColumnPercent, withMargins, fill, percentage, Constraint, evenSplit, LayoutSolver, withMargin, Layout, length, layout, vertical, max, threeRow, twoColumn, ConstraintKind, $, split, Direction, ratio, horizontal, $, render, setCursorStyle, setupWithMouse, cleanup, enableRawMode, isRawMode, saveCursor, withTerminal, drawWithCursor, showCursor, disableAlternateScreen, getSize, clearToEndOfLine, clearLine, isAlternateScreen, clearScreen, TerminalError, updateSize, draw, restoreCursor, clearToStartOfLine, getTerminalSize, Terminal, withTerminal, moveCursorRight, moveCursorUp, moveCursorLeft, renderCell, disableMouse, setup, enableAlternateScreen, moveCursorDown, disableRawMode, setCursorPos, isMouseEnabled, renderFull, setCursorPos, hideCursor, getTerminalSizeOrDefault, enableMouse, newTerminal, setupWithHiddenCursor, getArea, moveCursor, EventError, tryRecover, ensureNotNil, newTerminalError, newLayoutError, checkSystemCall, checkSystemCallVoid, newRenderError, TerminalError, ensure, newEventError, tryIO, RenderError, LayoutError, newBufferError, withResource, withErrorContext, withContext, BufferError, debugLog, checkForLeaks, getStats, ResourceId, ==, getGlobalResourceManager, acquire, newResourceGuard, initGlobalResourceManager, isValid, withManagedResource, newResourceManager, $, ResourceType, release, withResourceGuard, touchResource, globalResourceManager, release, ResourceState, getResourceInfo, getResourceStats, clear, ResourceGuard, cleanupAllResources, hash, ResourceManager, ResourceInfo, unregisterResource, get, newResourcePool, registerResource, cleanupLeakedResources, getAllResources, ResourcePool, CursorUpSeq, RenderBatch, ClearScreenSeq, AlternateScreenEnter, enableMouseMode, applyTerminalConfig, generateRenderBatch, CursorStyleBlinkingBlock, CursorStyleBlinkingUnderline, getRawModeConfig, ClearToEndOfLineSeq, CursorRightSeq, makeCursorPositionSeq, makeCursorPositionSeq, ClearToStartOfLineSeq, MouseSequences, disableMouseMode, AnsiSequence, ShowCursorSeq, buildDifferentialOutput, CursorStyleSteadyUnderline, AlternateScreenExit, MouseMode, getCursorStyleSeq, CursorStyleSteadyBlock, CursorStyle, RestoreCursorSeq, CursorLeftSeq, parseMouseEvent, isTerminalInteractive, calculateRenderMetrics, supportsAnsi, CursorState, buildFullRenderOutput, buildOutputWithCursor, RenderMetrics, RenderCommandKind, CursorStyleDefault, CursorStyleBlinkingBar, CursorDownSeq, makeCursorMoveSeq, optimizeRenderBatch, getTerminalSizeFromSystem, buildOutputString, SaveCursorSeq, getTerminalCapabilities, HideCursorSeq, addCommand, TerminalConfig, RenderCommand, getTerminalSizeWithFallback, CursorStyleSteadyBar, ClearLineSeq, calculateSimpleDiff, getWindows, getWindow, setCursorStyle, isCursorVisible, newApp, setTargetFps, getFocusedWindow, addWindow, getCursorStyle, App, getWindowInfo, setCursor, onEvent, showCursor, removeWindow, getTargetFps, setCursorPos, enableWindowMode, getFocusedWindowId, run, focusWindow, resetCursor, quit, hideCursor, getCurrentFps, onRender, AppConfig, setCursor, getCursorPos, handleWindowEvent, getWindowCount, Renderer, render, setString, clear, showCursor, renderDiff, getCursorManager, isCursorVisible, forceRender, getBuffer, hideCursor, resize, newRenderer, resize, setCursor, getCursorPos, setCursor, setCursorStyle, newCursorManager, isVisible, setPosition, styleChanged, hide, setStyle, updateLastStyle, CursorState, CursorManager, reset, setPosition, show, getStyle, getState, hasPosition, getPosition, getRemainingFrameTime, getTargetFps, AsyncPerfMonitor, getFrameTimeout, endFrame, setTargetFps, getStats, newFpsMonitor, newAsyncPerfMonitor, shouldRender, getEventRate, getCurrentFps, FpsMonitor, recordFrame, startFrame, getFrameTime, PerfStats, recordEvent, getFPS, WindowState, render, WindowEvent, render, setBorder, destroyWindowManager, defaultBorder, move, WindowKeyHandler, ==, getVisibleWindows, Window, defaultBorderChars, dispatchEvent, setKeyHandler, stopPropagation, WindowBorder, hide, $, removeWindow, getContentBuffer, WindowManager, bringToFront, handleEvent, focusWindow, destroyWindow, findWindowAt, addWindow, newWindow, getWindow, setResizeHandler, resize, restore, WindowInfo, sendToBack, setArea, setEventHandler, setTitle, EventHandler, WindowMouseHandler, maximize, show, dispatchResize, WindowId, preventDefault, clearEventHandlers, minimize, toWindowInfo, WindowEventHandler, handleWindowEvent, newWindowManager, BorderChars, setMouseHandler, getContentSize, getFocusedWindow, WindowResizeHandler, EventPhase, asyncVersion, salmon, mergeAsync, AsyncAppError, setString, newWidget, WindowBorder, enableRawMode, waitForKeyAsync, cell, withAsyncBuffer, toBuffer, clear, newAsyncInputReader, AsyncBufferMetrics, hsvToRgb, renderAsync, drawAsync, newAsyncBuffer, setString, getTerminalSizeAsync, WindowId, ==, startAsync, disableRawMode, waitForMultipleEventsAsync, WindowEventHandler, ==, newBuffer, bottom, EventKind, onRenderAsync, hasChronos, waitForKey, $, violet, contains, getInputBufferStats, clearAsync, KeyCode, pollKeyAsync, lerp, AsyncAppConfig, pos, newAsyncWindowManager, setString, moveWindowAsync, $, cell, AsyncEventError, lerp, intersects, readCharAsync, KeyEvent, constrainSize, RgbColor, toBgAnsiCode, measureWidget, setCellAsync, getLastFrameTime, StyleModifier, initAsyncIO, getState, getMinSize, updateState, getAsyncBufferMetrics, clone, Wrap, writeStdoutAsync, withAlignment, setupWithMouseAsync, AsyncApp, deepSkyBlue, onEventAsync, destroyAsyncWindowManager, color256, resize, quitAsync, Size, AsyncTerminalError, ColorValue, checkResize, brightColors, fill, ColorKind, hideCursor, cleanupAsync, AsyncTerminal, renderAsync, hideCursorAsync, WindowKeyHandler, isRawMode, $, KeyModifier, ==, fillAsync, defaultColor, WindowState, $, initSignalHandling, right, showCursorAsync, MouseButton, clearScreenAsync, grayscale, ==, getSize, initAsyncEventSystem, hasInputAsync, getVisibleWindowsAsync, intersection, pollEventsAsync, withBg, stopAsync, resizeDetected, newAsyncBufferNoRM, updateFromBufferAsync, readKeyInput, sleepMs, width, toAnsiSequence, ==, asyncStdinFd, globalAsyncBufferMetrics, clearInputBuffer, writeEscapeAsync, italic, removeWindowAsync, pollKey, orange, addWindow, toAnsiCode, withFg, darkColors, center, resetSequence, isMouseEnabled, BorderChars, pastels, WindowResizeHandler, Position, bringToFrontAsync, render, getStats, shrink, newStatefulWidget, area, clearLine, hasAsyncDispatch, Window, reversed, getMinSize, AsyncBuffer, getWindowAsync, newAsyncBuffer, setStringAsync, rgb, canFocus, withAsyncTerminal, setString, runAsync, rgb, MouseEvent, color, WindowEvent, styledText, pollEvents, AsyncWindowError, isValid, AsyncInputReader, disableAlternateScreen, withBg, EventHandler, +, getCell, $, cell, rgb, setString, Rect, quickRunAsync, getCell, enableMouse, setString, AsyncIOError, getWindow, readKey, sendToBackAsync, withBufferAsync, AsyncBufferPool, enableWindowMode, focusWindowAsync, newAsyncBufferPool, newWindow, cleanupAsyncIO, moveCursorAsync, registerFD, isEmpty, toStringsAsync, diff, hasInput, merge, getFocusedWindowAsync, crimson, showCursor, style, handleEventAsync, waitForAnyKeyAsync, setCellAsync, peekCharAsync, boldText, []=, underline, getFrameCount, focusWindowAsync, $, withWrap, readKeyAsync, gold, [], newAsyncEventStream, StatefulWidget, [], $, diffAsync, withModifiers, addWindowAsync, toBufferAsync, getSize, trackAsyncBufferCreation, bold, hasDataAvailable, resizeDetected, Color, teal, renderCell, setRunes, enableAlternateScreen, $, setCursorPos, isEmpty, getArea, setStringAsync, renderWidgetAt, setState, rect, withBuffer, contains, newAsyncTerminal, destroyAsyncBufferPool, renderSync, Event, findWindowAtAsync, AsyncWindowManager, runesWidth, rect, setupAsync, updateFromBuffer, color256, toAnsiCode, getPreferredSize, default, withStyle, merge, isAlternateScreen, trackAsyncBufferDestroy, -, toAnsiCode, closeAsyncInputReader, withFg, resizeAsync, hsv, newText, isValidPos, asyncBackend, Buffer, disableMouse, resizeWindowAsync, Cell, area, drawAsync, newBuffer, withLock, unregisterFD, stats, MouseEventKind, $, text, cleanupAsyncEventSystem, newAsyncApp, size, clear, returnBuffer, readCharNonBlocking, setCursorPos, isValid, defaultStyle, getFocusedWindowAsync, getTerminalSize, newAsyncBufferNoRM, removeWindowAsync, toStrings, toAnsiCode, render, indigo, position, getWindowAsync, readNonBlocking, destroyAsync, runeWidth, AsyncEventStream, flushStdoutAsync, hotPink, updateSize, getWindow, readStdinAsync, Style, expand, style, isRunning, []=, addWindowAsync, isValidPos, renderFullAsync, shrink, setRunes, addModifier, getArea, cubeColor, Alignment, limeGreen, getPreferredSize, size, Widget, Text, clearScreen, Area, getBuffer, colorText, waitForAnyKey, WindowMouseHandler, testAsyncIO, renderStateful, union, hasAsyncSupport, checkResizeAsync, removeModifier, renderWidget, EventPhase, hasAsyncSupport, hasChronos, hasAsyncDispatch