apochromat
v0.6.0
Published
Dynamic text rendering for interactive command line apps.
Downloads
7
Readme
apochromat
Dynamic text rendering for interactive command line apps.
- @apochromat/print: Dynamic text output for interactive command line apps.
- @apochromat/animation: Dynamic text animations for interactive command line apps.
Installation
npm install apochromat --save
Usage
Hello World
import {Lens} from 'apochromat';
const greeting = new Lens();
const salutation = new Lens();
const subject = new Lens();
greeting.subscribe((event) => {
if (event === 'render') {
console.log(greeting.frame);
}
});
salutation.render`Hi`;
subject.render`everyone`;
greeting.render`${salutation}, ${subject}!`;
subject.render`world`;
salutation.render`Hello`;
Hi, everyone!
Hi, world!
Hello, world!
Rendering of dynamic lists
import {Lens, list} from 'apochromat';
const foobarbaz = new Lens();
const foo = new Lens();
const bar = new Lens();
const baz = new Lens();
foo.render`foo`;
bar.render`bar`;
baz.render`baz`;
foobarbaz.render(...list(',', foo, bar, baz));
console.log(foobarbaz.frame);
foo,bar,baz
Types
type LensListener = (event: LensEvent) => void;
type LensEvent = 'attach' | 'detach' | 'render';
class Lens {
get frame(): string;
render(segments: readonly string[], ...children: readonly unknown[]): boolean;
subscribe(listener: LensListener): () => void;
}
function list(
delimiter: string,
...elements: readonly unknown[]
): [readonly string[], ...(readonly unknown[])];
Copyright 2021 Clemens Akens. All rights reserved. MIT license.