Skip to main content

Constants & Enums

Kraken TUI exports several constant objects and enums for use in event handling, animation, theming, and accessibility.

Animation Constants

AnimProp

Animation property identifiers for Widget.animate().
import { AnimProp } from "kraken-tui";
ConstantValueDescription
AnimProp.Opacity0Widget opacity (0.0 to 1.0)
AnimProp.FgColor1Foreground color (RGB)
AnimProp.BgColor2Background color (RGB)
AnimProp.BorderColor3Border color (RGB)
AnimProp.PositionX4X offset for position animation
AnimProp.PositionY5Y offset for position animation

Example

// Fade out animation
widget.animate(AnimProp.Opacity, 0.0, 500, Easing.EaseOut);

// Position animation
widget.animate(AnimProp.PositionX, 100, 300, Easing.EaseInOut);

Easing

Easing function identifiers for animations.
import { Easing } from "kraken-tui";
ConstantValueDescription
Easing.Linear0Constant speed throughout
Easing.EaseIn1Slow start, accelerates
Easing.EaseOut2Fast start, decelerates
Easing.EaseInOut3Slow start and end, fast middle
Easing.CubicIn4Cubic acceleration
Easing.CubicOut5Cubic deceleration
Easing.Elastic6Elastic bounce effect
Easing.Bounce7Bouncing effect

Example

// Smooth ease-in-out
widget.animate(AnimProp.Opacity, 0.5, 400, Easing.EaseInOut);

// Bouncy animation
widget.animate(AnimProp.PositionY, 50, 600, Easing.Bounce);
Easing functions are implemented in the Rust core. See Animation Concepts for visual curves.

Event Constants

EventType

Event type identifiers.
import { EventType } from "kraken-tui";
ConstantValueDescription
EventType.None0No event (sentinel)
EventType.Key1Keyboard event
EventType.Mouse2Mouse event (click, scroll)
EventType.Resize3Terminal resize
EventType.FocusChange4Focus gained/lost
EventType.Change5Widget value changed
EventType.Submit6Form submitted
EventType.Accessibility7Accessibility event

Example

for (const event of app.drainEvents()) {
  if (event.type === "key" || event.eventType === EventType.Key) {
    console.log("Keyboard event");
  }
}
The KrakenEvent object has both a string type field and a numeric eventType field. Use whichever is more convenient.

KeyCode

Special key code constants (non-printable keys).
import { KeyCode } from "kraken-tui";
ConstantValueKey
KeyCode.Backspace0x0100Backspace
KeyCode.Enter0x0101Enter/Return
KeyCode.Left0x0102Left arrow
KeyCode.Right0x0103Right arrow
KeyCode.Up0x0104Up arrow
KeyCode.Down0x0105Down arrow
KeyCode.Home0x0106Home
KeyCode.End0x0107End
KeyCode.PageUp0x0108Page Up
KeyCode.PageDown0x0109Page Down
KeyCode.Tab0x010aTab
KeyCode.BackTab0x010bShift+Tab
KeyCode.Delete0x010cDelete
KeyCode.Insert0x010dInsert
KeyCode.Escape0x010eEscape
KeyCode.F10x0110F1 function key
Printable character keys (letters, numbers, symbols) use their Unicode codepoints directly. Only special keys use these 0x0100+ constants.

Example

// Check for Escape key
if (event.keyCode === KeyCode.Escape) {
  running = false;
}

// Check for Enter key
if (event.keyCode === KeyCode.Enter) {
  submitForm();
}

// Check for printable character
if (event.keyCode === 0x51) { // 'Q'
  quit();
}

Modifier

Keyboard modifier flags (bitfield).
import { Modifier } from "kraken-tui";
ConstantValueDescription
Modifier.Shift0x01Shift key held
Modifier.Ctrl0x02Control key held
Modifier.Alt0x04Alt/Option key held
Modifier.Super0x08Super/Windows/Command key held

Example

// Check for Ctrl+C
if (event.keyCode === 0x43 && event.modifiers & Modifier.Ctrl) {
  handleCopy();
}

// Check for Shift+Tab
if (event.keyCode === KeyCode.Tab && event.modifiers & Modifier.Shift) {
  focusPrevious();
}

// Check for multiple modifiers (Ctrl+Shift+S)
if (event.keyCode === 0x53 && 
    (event.modifiers & Modifier.Ctrl) && 
    (event.modifiers & Modifier.Shift)) {
  saveAs();
}
Modifier values are bitflags. Use bitwise AND (&) to check if a modifier is active, not equality (===).

Widget Constants

NodeType

Widget type identifiers (used internally by the FFI).
import { NodeType } from "kraken-tui";
ConstantValueWidget Class
NodeType.Box0Box
NodeType.Text1Text
NodeType.Input2Input
NodeType.Select3Select
NodeType.ScrollBox4ScrollBox
NodeType.TextArea5TextArea
You generally don’t need to use NodeType directly in application code. It’s primarily used internally by the FFI layer.

Accessibility Constants

AccessibilityRole

Accessibility role identifiers for assistive technologies.
import { AccessibilityRole } from "kraken-tui";
ConstantValueDescription
AccessibilityRole.Button0Button or clickable element
AccessibilityRole.Checkbox1Checkbox or toggle
AccessibilityRole.Input2Text input field
AccessibilityRole.TextArea3Multi-line text input
AccessibilityRole.List4List container
AccessibilityRole.ListItem5Item within a list
AccessibilityRole.Heading6Section heading
AccessibilityRole.Region7Landmark region
AccessibilityRole.Status8Status or live region

Example

import { AccessibilityRole } from "kraken-tui";

// Mark widget as a button
widget.setRole(AccessibilityRole.Button);
widget.setLabel("Submit");

// Mark heading
header.setRole(AccessibilityRole.Heading);
header.setLabel("Settings");
Use accessibility roles with setLabel() and setDescription() to improve screen reader support. See Advanced Patterns for more.

Theme Constants

DARK_THEME

Handle for the built-in dark theme.
import { DARK_THEME } from "kraken-tui";

app.switchTheme(DARK_THEME);
Value: 1

LIGHT_THEME

Handle for the built-in light theme.
import { LIGHT_THEME } from "kraken-tui";

app.switchTheme(LIGHT_THEME);
Value: 2
These constants represent theme handles. The actual theme definitions are built into the Rust core.

Performance Counter IDs

PERF_ACTIVE_ANIMATIONS

Performance counter ID for the number of active animations.
import { PERF_ACTIVE_ANIMATIONS } from "kraken-tui/loop";

const count = app.getPerfCounter(PERF_ACTIVE_ANIMATIONS);
console.log(`${count} animations running`);
Value: 6 See Kraken.getPerfCounter() for usage.

Usage Patterns

Import Only What You Need

// Specific imports
import { KeyCode, Modifier } from "kraken-tui";

// Use directly
if (event.keyCode === KeyCode.Enter) { /* ... */ }

Type-Safe Constant Objects

All constant objects are defined with as const to ensure type safety:
// This is type-safe
const prop: AnimProp = AnimProp.Opacity; // ✓

// This would fail type checking
const invalid: AnimProp = 99; // ✗ Type error

Bitfield Operations

For modifier flags:
// Check if Ctrl is pressed
if (event.modifiers & Modifier.Ctrl) { /* ... */ }

// Check if NO modifiers are pressed
if (event.modifiers === 0) { /* ... */ }

// Check if ONLY Shift is pressed
if (event.modifiers === Modifier.Shift) { /* ... */ }

// Check if Ctrl OR Alt is pressed
if (event.modifiers & (Modifier.Ctrl | Modifier.Alt)) { /* ... */ }

Source References

Animation

Widget animation methods

Event Handling

Working with events

Themes

Theme customization

Accessibility

Accessibility methods

Build docs developers (and LLMs) love