• Stars
    star
    248
  • Rank 163,560 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 3 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿฆ• Deno module for creating Terminal User Interfaces

โŒจ๏ธ Tui

Deno mascot made as ASCII art

Deno Deno doc

Simple Deno module that allows easy creation of Terminal User Interfaces.

๐Ÿ”ฉ Features

  • ๐Ÿ”ฐ Ease of use
  • ๐Ÿ‘๏ธโ€๐Ÿ—จ๏ธ Reactivity
  • ๐Ÿ–‡๏ธ No dependencies
  • ๐Ÿ“„ Decent documentation
  • ๐Ÿ“ฆ Multiple ready-to-use components
  • ๐ŸŽจ Styling framework agnostic
    • This means you can use whatever terminal styling module you want
    • ๐Ÿ–๏ธ Crayon is recommended but not imposed as it greatly integrates with Tui
  • ๐Ÿชถ Relatively lightweight

๐Ÿ–ฅ๏ธ OS Support

Operating system Linux macOS Windowsยน,ยฒ WSL
Base โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ
Keyboard support โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ
Mouse support โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ
Required permissions none none none none

ยน - WSL is a heavily recommended way to run Tui on Windows, if you need to stick to clean Windows, please consider using Windows Terminal. Windows without WSL is slower at writing to the console, so performance might be worse on it.

ยฒ - If unicode characters are displayed incorrectly type chcp 65001 into the console to change active console code page to use UTF-8 encoding.

๐ŸŽ“ Get started

Replace {version} with relevant module versions

  1. Create Tui instance
import { crayon } from "https://deno.land/x/crayon@version/mod.ts";
import { Canvas, Tui } from "https://deno.land/x/tui@version/mod.ts";

const tui = new Tui({
  style: crayon.bgBlack, // Make background black
  refreshRate: 1000 / 60, // Run in 60FPS
});

tui.dispatch(); // Close Tui on CTRL+C
  1. Enable interaction using keyboard and mouse
import { handleInput, handleKeyboardControls, handleMouseControls } from "https://deno.land/x/tui@version/mod.ts";
...

handleInput(tui);
handleMouseControls(tui);
handleKeyboardControls(tui);
  1. Add some components
import { Button } from "https://deno.land/x/tui@version/src/components/mod.ts";
import { Signal, Computed } from "https://deno.land/x/tui@version/mod.ts";

...

// Create signal to make number automatically reactive
const number = new Signal(0);

const button = new Button({
  parent: tui,
  zIndex: 0,
  label: {
    text: new Computed(() => number.value.toString()), // cast number to string
  },
  theme: {
    base: crayon.bgRed,
    focused: crayon.bgLightRed,
    active: crayon.bgYellow,
  },
  rectangle: {
    column: 1,
    row: 1,
    height: 5,
    width: 10,
  },
});

// Subscribe for button state changes
button.state.subscribe((state) => {
  // If button is active (pressed) make number bigger by one
  if (state === "active")  {
    ++number.value;
  }
});

// Listen to mousePress event
button.on("mousePress", ({ drag, movementX, movementY }) => {
  if (!drag) return;

  // Use peek() to get signal's value when it happens outside of Signal/Computed/Effect
  const rectangle = button.rectangle.peek();
  // Move button by how much mouse has moved while dragging it
  rectangle.column += movementX;
  rectangle.row += movementY;
});
  1. Run Tui
...

tui.run();

๐Ÿค Contributing

Tui is open for any contributions.
If you feel like you can enhance this project - please open an issue and/or pull request.
Code should be well document and easy to follow what's going on.

This project follows conventional commits spec.
If your pull request's code can be hard to understand, please add comments to it.

๐Ÿ“ Licensing

This project is available under MIT License conditions.