Skip to content

Getting started

Build and print a two-column text layout. You need a TypeScript project and a runtime that can execute TypeScript, such as Bun or Node with tsx. You can follow this example without learning Effect services or layers first.

Install the library

Install effect-boxes with Effect 4:

npm install effect-boxes "effect@^4"

Effect is a peer dependency. Install it in your application alongside effect-boxes.

Save this as hello.ts:

import * as Box from "effect-boxes/Box";
 
const hello = Box.text("Hello, World!");
console.log(Box.renderPlainSync(hello));
// Hello, World!

Run bun hello.ts, or use npx tsx hello.ts with Node. The terminal prints Hello, World!.

Box.renderPlainSync returns a string. Box.render returns an Effect computation that needs a renderer layer before you run it. Start with the synchronous helper; Rendering covers layers and output targets.

Compose columns and rows

Replace the greeting with this layout:

import * as Box from "effect-boxes/Box";
 
const names = Box.vcat([Box.text("Name"), Box.text("Alice")], Box.left);
const ages = Box.vcat([Box.text("Age"), Box.text("30")], Box.left);
const table = Box.hsep([names, ages], 2, Box.top);
 
console.log(Box.renderPlainSync(table));
// Name   Age
// Alice  30

vcat stacks boxes vertically. hsep places them beside each other with a gap. Box.left aligns text in each column; Box.top aligns the columns at the top. All operations return new boxes without changing the originals.

Next steps