@jsvision/core / createHost
Function: createHost()
createHost(
options):Host
Defined in: host/host.ts:82
Create a terminal host. It wires the capability profile to the terminal modes it enables, stdin to the input decoder, and each frame to a diffed write, and it guarantees the terminal is restored on every exit path.
The returned host is idle until you await host.start(). Only caps is required; pass onInput/onResize to receive events, and drive the screen by building a ScreenBuffer and calling host.render(buffer).
Parameters
options
Host configuration; see HostOptions. Only caps is required.
Returns
A Host; call start() to take over the terminal and stop() to give it back.
Example
ts
import { createHost, resolveCapabilities, ScreenBuffer } from '@jsvision/core';
const caps = resolveCapabilities().profile;
const host = createHost({
caps,
onInput: (event) => {
if (event.type === 'key' && event.key === 'q') void host.stop();
},
onResize: (size) => console.error(`resized to ${size.columns}x${size.rows}`),
});
await host.start(); // raw mode + alternate screen; terminal restored on any exit
const frame = new ScreenBuffer(20, 1, { fg: 'default', bg: 'default' });
frame.set(0, 0, 'Hello — press q', { fg: 'white', bg: 'default' });
host.render(frame);