Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

kittik-shape-rectangle

ghaiklor6MIT6.0.0-rc.3TypeScript support: included

Shape for rendering rectangles in Kittik

kittik, shape, rectangle

readme

kittik

Travis (.com) branch Code Coverage GitHub code size in bytes GitHub last commit

GitHub followers Twitter Follow

Do you have a conference soon? Are you tired of presenting slides in Keynote, PowerPoint or any HTML based tool? Why not to create and present slides in the terminal using ASCII only!

NOTE: I’m not arguing that kittik is better than X tool designed for presentations. I’m saying that we can use it for fun in small topics or conferences.

Why

I was always in love with the terminal and what we can do with it, and still is, actually. Someday, I thought, why not to be a little creative and present speech on the conference in the terminal by using ASCII characters only? I tried and turned out that it is a hard task. That is why, I decided, we need a tooling for it!

That is how a name was born, Keynote In the Terminal (KIT) and a palindrome for KIT - KITTIK.

Features

  • Unique shapes rendered via ASCII characters only, e.g. rectangle, ASCII art (aka figlet), code with syntax highlighting and more.
  • Customize how shapes must look like in the terminal, their background and foreground color, positioning in the terminal, width and height.
  • Animate every shape you want. YES! Kittik supports animations and still uses ASCII only. Create a rectangle and slide it in from the left side or make a text printing on the screen.
  • Everything in kittik comes with a builder. No more typing JSON, YAML or objects and guessing keys.
  • Developer Experience is a key feature. Everything in kittik is typed, even your custom names will be typed and suggested to you through autocompletion.
  • Presenter mode. Run your slides and manage them with a keyboard (N - next slide, P - previous slide, Q - quit).

Demo

How to convert an RGB to HEX
demo.ts

Getting Started

All you need is a single dependency - kittik.

npm install kittik

The package provides everything you need to create your own slides - builders. There are builders for shapes, animations, slides and deck. Start with a builder for Deck.

import { DeckBuilder } from "kittik";

DeckBuilder
  .start()
  .end()
  .render();

Every builder has a start() and end() methods. So it is easier to write them down at first place before configuring, that way you will not forget about end(). Although, type check does not allow this situation.

Every deck comprises your slides. To add more slides, just call withSlide() method. It accepts a function where the slide builder will be passed by the deck.

NOTE: the builder is already started in withSlide(), so you need to end it only.

import { DeckBuilder } from "kittik";

DeckBuilder
  .start()
  .withSlide((slide) => slide.end())
  .end()
  .render();

Now, slide builder provides two essential methods withAnimation() and withShape(). withAnimation() accepts a name for your animation (for further references) and the animation that must be built through animation builder. The same applies to withShape(). It accepts a name, and a shape built with shape builder.

That way you can specify animations and shapes for your slide. But kittik does not know in what order to render those shapes and what animations animate what shape. To handle this situation there is withOrder() method. It accepts a name of the shape you defined before and an array of animation names you want to use.

import { DeckBuilder, ShapeBuilder } from "kittik";

DeckBuilder
  .start()
  .withSlide((slide) =>
    slide
      .withShape(
        "Hello, World!",
        ShapeBuilder.start("Text").withText("Hello, World!").end()
      )
      .withOrder("Hello, World!")
      .end()
  )
  .end()
  .render();

Congratulations, you just created a simple Deck with one slide and “Hello, World” in it. Add more slides, animate them and bring them to live.

More Examples

You can find more examples in examples folder.

FAQ

  • It is too hard to create a presentation even with builders and auto-completion

True, if you want to create a lot of slides, it will be not an exceptional experience in declaring them through builders. That is why there is work in progress (only in my mind) for the concept of themes and parsers for different input, e.g. Markdown.

  • Have questions?

Ask them in issues, I’ll be glad to answer them.

License

MIT

changelog

6.0.0-rc.3 (2020-09-27)

Features

  • 🎸 add re-export for Declaration types (4c7add3)

6.0.0-rc.2 (2020-06-13)

Bug Fixes

  • 🐛 issue with "Untitled Slide" already exists in builder (bdf598c)
  • 🐛 when animating code can throw an error "wrong syntax" (dbd1734)

6.0.0-rc.1 (2020-06-06)

Bug Fixes

  • 🐛 canvas is not cleaning up when switching slides (e6c6dd9)
  • 🐛 deck could exit while rendering (387c15f)
  • 🐛 deck is not clearing up canvas when showing\exiting (2224e57)
  • 🐛 Deck uses an old call signature for creating slides (f595679)
  • 🐛 image shape is not rendering in iTerm (c9b0942)
  • 🐛 update terminal-canvas with fixed eraseScreen behaviour (f580d68)
  • 🐛 when passing custom canvas, it still resets the original (0748ffb)

Code Refactoring

  • 💡 move canvas property from deck decl to constructor (104953f)
  • 💡 swap order for canvas and declaration args in Slide (3de450f)

Features

  • 🎸 add a meta package kittik that reexports everything (54fdf7e)
  • 🎸 Deck extends an EventEmitter and produces exit event (2d28c52)
  • 🎸 DeckBuilder can accept a predefined shapes\animations (64988f6)
  • 🎸 SlideBuilder can be started with predefined shapes\anim (1738ed1)

BREAKING CHANGES

  • 🧨 DeckBuilder has no longer methods withShape(), withAnimation(). If you want to add a "global" shape, you can create a predefined set of shapes\animations and pass them into DeckBuilder.start(shapes, animations).
  • 🧨 DeckDeclaration no longer accepts canvas property. Instead, it must go into Deck constructor as a separate argument.
  • 🧨 Slide constructor() has changed its signature from (canvas, declaration) to (declaration, canvas)

5.1.0-beta.3 (2020-05-04)

Features

  • 🎸 improve type check and autocompletion for SlideBuilder (559e1b3)

5.1.0-beta.2 (2020-04-26)

Bug Fixes

  • 🐛 animation options are mandatory on creating animations (52665f7)
  • 🐛 when creating shape from object, all fields are mandator (ba02210)

Features

  • 🎸 generic interface AnimationObject over type and options (4e09ab7)
  • 🎸 generic interface ShapeObject over type and options (37bd243)

5.1.0-beta.1 (2020-04-20)

Features

  • 🎸 AnimationBuilder has more type info, which improves DX (76e35ce)
  • 🎸 improve type info in ShapeBuilder, improving overall DX (b621c43)
  • 🎸 re-export conditional types for options and objects (bdcaafe)

5.1.0-beta.0 (2020-04-19)

Bug Fixes

  • 🐛 issue when delay could accept NaN or Infinity values (1905b0d)
  • 🐛 issue when process.stdin could be not an interactive (5055370)
  • 🐛 issue with animating text with print animation (b55f6bd)
  • 🐛 issue with graceful closing the process (268dccf)
  • 🐛 issue with regular expression for base64 in image shape (c3f9be2)

Features

  • 🎸 add a possibility to override cursor when using builder (43b03aa)
  • 🎸 add Builder Pattern to Shape/Animation/Slide (d30c965)
  • 🎸 add name to the slides, so you can reference them later (f45e55c)
  • 🎸 DeckBuilder allows to create the whole decks via API (fc1eb56)
  • 🎸 implement more user-friendly error handling in slides (c494c26)
  • 🎸 implement passing cursor as an argument to renderer (594795c)

BREAKING CHANGES

  • 🧨 Any shape constructor now accept not the two argument (cursor, options) but only the one (options)

2.1.2 (2016-05-12)

Bug Fixes

  • slide: Fix issue with True Color support (3257f22)

2.1.1 (2016-05-10)

Bug Fixes

  • slide: Update kittik-shape-code with fixes (e2ff33b)

2.1.0 (2016-05-10)

Features

  • shape: Add new shape that renders code blocks (98cbd94)

2.0.0 (2016-05-04)

Bug Fixes

  • core: Fix issue with exports (da72012)
  • deck: Fix issue with check if cursor is not a tty stream (f29ca07)
  • deck: Fix issue with default declaration (b724e5b)
  • deck: Fix issue with exiting from deck (9722d62)
  • deck: Fix issue with restoring screen after exit (2b17ab7)
  • package: Fix issue with exports Deck class (ba9c35f)
  • slide: Fix issue with non-rendering slide (72eb302)
  • slide: Fix issue with serializing slides (46a6bc8)

Features

  • deck: Implement mixing global shapes\animations into slides (5138b2c)
  • package: Add all implemented shapes and animations (dfb19ca)
  • slide: Implement rendering slide with animations (2580e6e)
  • slide: Implement simple rendering of the slide (481920b)

1.0.1 (2015-12-08)

Bug Fixes

  • package: Fix issue with non-exists cli (673df76)

1.0.0 (2015-12-08)

Bug Fixes

  • cursor: Fixes issue with incorrect cursor position on exit (b3199d1)
  • cursor: Fixes issue with off is undefined (3750d1f)
  • cursor: Fixes issue with resetting the screen after exit from presentation (36f65ba)
  • shape: Fixes issue when class name is taken not from the correct source (f966b38)
  • shape: Fixes issue when options is undefined (7fd61cb)
  • shape: Fixes issue when test is not defined (2809c2f)
  • shape: Fixes issue with empty arguments in constructor (23274af)
  • shape: Fixes issue with float coordinates in Rectangle (915358c)
  • shape: Fixes issue with static property that is not supported (23ae97e)
  • slide: Fixes issue with passing slides array (a880a24)

Features

  • animation: Add basic print animation (86dfe4d)
  • cli: Implement simple CLI (4c69581)
  • cursor: Adds more wrap methods to work with cursor (8228a4a)
  • cursor: Implement basic wrapper around charm (e05a560)
  • cursor: Implements feature that allows to override stdout and stdin streams (2ce012d)
  • cursor: Implements fill method (f6a6cca)
  • cursor: Implements getting TTY size (7915319)
  • cursor: Implements on, off for cursor (c38d93a)
  • cursor: Implements possibility to add multiply pipes before\after cursor stream (1dfa32d)
  • loader: Implements basic loader (29fdc6a)
  • package: Initial release (9856348)
  • presentation: Implements exit method and supports keypress for switching the slides (4e8d731)
  • presentation: Implements rendering and switching between slides (215c667)
  • presentation: Implements simple presentation wrapper (b043617)
  • primitive: Implements basic primitives (a85ff1c)
  • shape: Adds checking for Shape instance when you add it to Slide (82eca71)
  • shape: Adds to base shape text property (9c16685)
  • shape: Implements background and foreground in basic shape (6c4fef9)
  • shape: Implements basic shapes (68bcdb3)
  • shape: Implements feature to check if fromObject is called with right Object representation (42205f9)
  • shape: Implements get and set of names from shape (de587ef)
  • shape: Implements JSON and Object serializer for shape (0d3dd5d)
  • shape: Implements Rectangle shape (f4c4376)
  • shape: Implements simple text shape (9dc1a52)
  • shape: Implements static method that creates new instances of shapes (75b8c20)
  • shape: Implements writing text in center of rectangle (0bbc828)
  • slide: Implements basic slide (9d1c05b)
  • slide: Implements simple Slide wrapper that allows to render the slide (881b956)