apochromat
    TypeScript icon, indicating that this package has built-in type declarations

    0.6.0 • Public • Published

    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.

    Keywords

    none

    Install

    npm i apochromat

    DownloadsWeekly Downloads

    13

    Version

    0.6.0

    License

    MIT

    Unpacked Size

    61.2 kB

    Total Files

    25

    Last publish

    Collaborators

    • clebert