Skip to content

alexlafroscia/d_ui

Repository files navigation

dui

CI deno doc

Terminal rendering for Deno

Note: This is a major work-in-progress. API will change without warning until a 1.0.0 release is made.

Usage

The following is a brief example of using this library; see the examples directory for more!

/** @jsx h */
import {
  Columns,
  Fill,
  h,
  Relative,
  Screen,
  Text,
} from "https://deno.land/x/d_ui/mod.ts";

// Create a `Screen` instance to get started
await using screen = await Screen.create();

// `screen` emits events from `STDOUT` by default
for await (const event of screen.events()) {
  // Stop the event loop if the user hits `CTL-C`
  if (event.type === "ControlInputEvent" && event.key === "ETX") {
    break;
  }

  await screen.render(
    <Columns sizes={[10, Relative.Third, Fill]}>
      <Text>Hello</Text>
      <Text>My</Text>
      <Text>Friend</Text>
    </Columns>,
  );
}

Prior Art

  • terminal: Much of the code around actually writing to STDOUT is borrowed or heavily inspired from here