View
Launch View from a Bun script with a file, a directory, or your own content, and pick the guide for the next step.
import { createFileProvider, launch, launchDirectory } from "@tooee/view";
await launch({ contentProvider: createFileProvider("CHANGELOG.md") });
await launchDirectory({ dirPath: "docs" });Run it with bun view-changelog.ts. The first session opens the file. When the reader quits, the second session opens the directory view from View in the CLI section. Each launch() resolves with void after the reader quits with q or ctrl+c.
Launch options
| Option | Type | Meaning |
|---|---|---|
contentProvider | ContentProvider | Where the content comes from. See Content and providers. |
actions | ActionDefinition[] | Commands added to the screen. See Actions and command context. |
renderers | Record<string, ContentRenderer> | Renderers for your own content formats. See Custom renderers. |
codeBlockRenderers | Record<string, CodeBlockRenderer> | Renderers for fenced code blocks in markdown, keyed by the first word of the fence info string. |
filePath | string | The source file of the content. View needs it to follow local Markdown links. |
linkHandlers | readonly LinkHandler[] | Link handlers that run before the local file handler. See Links in markdown. |
outline | boolean | Open the heading outline beside Markdown content at start. |
launchDirectory takes dirPath and actions. The View component takes outline as a prop too.
The promise stays pending for the whole session. Work that must happen while the screen is open runs before the await.
View reads keys from the controlling terminal when process stdin supplies content. This keeps the reader interactive after the pipe closes.
Guides
| Guide | Read it when you want to |
|---|---|
| Content and providers | Give View content at once, later, or as a stream of chunks. |
| Content formats | Know what markdown, code, text, table, and image content accept. |
| Diffs | Show a unified patch as a navigable diff. |
| Actions and command context | Add commands to View and read the cursor row, the content, and the marks. |
| Custom renderers | Render a format of your own and keep navigation, search, and copy. |