0.6.0 • Published 4 years ago

apochromat v0.6.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

apochromat

Dynamic text rendering 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.

0.5.0

4 years ago

0.4.0

4 years ago

0.6.0

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago