Skip to content

Playground

Pouya Kary ✨ edited this page Jul 6, 2021 · 4 revisions

The playground is an interactive REPL with auto-complete suggestions and result previews that you can use to play around with TextKit and test your ideas in. It is always loaded with TextKit and shortcuts and provides some good debugging views for you so that you can easily see what is going right or wrong.

Screenshot showing the TextKit Playground


Box Preview Environment

The playground previews the results of your inputs right away. The value is mostly rendered in bold format whereas the type is indicated after a slash. For class instances the type is instance and the value becomes the name of the class:

An screenshot of Playground that renders different types along the value


Environment Context

  • The $ Renderer
    Its environment has a constant $ that represents a local ANSI Terminal Style Renderer as a shortcut for working with the ViewProtocol classes. Also if you use the $, the playground previews it for you with some debugging tools (the preview shows the bounds of the view as well as a bullet point that shows the baseline).

  • TextKit Namespace
    What is inside of TextKit can be accessed without the TextKit namespace inside of the playground. So you write something like new CanvasView( 20, 10, $ ) and it works.

  • Math Namespace
    Just like the TextKit you can easily access the Math functions without the Math. in the first of them. So you can write things like sqrt(abs(floor(-4 / 3)))


Commands

  • .exit gets out of the app
  • .clean cleans the screen
  • .clear cleans up and resets the context

Installation

% npm run build
% npm link

## in case the linking didn't work use:
% npm run fix-playground-setup

## once installed you can run the app via
% textkit

NOTE
Keep in mind that the environment is also for testing the development of the TextKit itself. So if you have the TypeScript compiler at the watch mode, then each time you enter into the playground you'll get the latest build.

Clone this wiki locally