]> git.r.bdr.sh - rbdr/tomato-sauce/blame - README.md
Merge branch 'develop'
[rbdr/tomato-sauce] / README.md
CommitLineData
ca0472aa
RBR
1# tomato-sauce
2Draw stuff via telnet
09ab7e98
BB
3
4## How to run
5
6`npm install` and then run ``./bin/server.js`. It will listen on port 9999
7by default.
8
9## Configuration variables
10
11Tomato Sauce can be configured using env variables:
12
13* `TOMATO_SAUCE_PORT`: The port to listen on. Defauts to 9999.
14* `TOMATO_SAUCE_FREQUENCY`: How often it will send a screen in
15 miliseconds. Defaults to 333.
16* `TOMATO_SAUCE_MODULATION`: How much the modulation counter will
17 increase per round. Defaults to 5.
18* `TOMATO_SAUCE_SCREEN_PATH`: Path from which we will load screens. It
19 defaults to `{project_root}/lib/screens`
20* `TOMATO_SAUCE_RENDERER_PATH`: Path from which we will load renderers. It
21 defaults to `{project_root}/lib/renderers`
22
23## Make your own screens
24
25A screen is a function that will receive a modulation value from 0-255,
26the width of the viewport, the height of the viewport, and a renderer
27function, and it returns a string that consists of the commands that
28will be sent to the socket.
29
30 * `TomatoSauce.IScreen(modulation <int>, width <int>, height <int>, renderer
31 <TomatoSauce.IRenderer>) -> payload <string>`
32
33It should output the required commands that telnet needs to move the
34cursor and draw. For convenience, a renderer function is passed so
35calculating color should not be a part of the screen, just moving the
36cursor around and calling specific colors.
37
38## Make your own renderers
39
40The included renderers are wrappers to some common ways of obtaining
41colors in the terminal: ANSI, 256 colors, 24-bit colors, and a fake
42color string that uses incorrect color strings to generate random
43variations.
44
45You can build your own renderer by building a function that receives a
46red, green, and blue component from 0 to 255 and returns the escape
47codes to generate the color.
48
49 * `TomatoSauce.IRenderer(red <int>, green <int>, blue <int>) ->
50 colorString <string>`
51
52## Using as a library
53
54The binary just serves as a wrapper to read configuration, and as a
55bridge to the console. It consumes `lib/tomato_sauce`. All configuration
56is optional, and should be passed as an object on instantiation. The
57instance is an event emitter that will emit a `listening` event with
58the server data, and an `error` event in case something goes wrong.
59
60```
61const TomatoSauce = require('tomato-sauce');
62
63const tomatoSauce = new TomatoSauce(config);
64
65tomatoSauce.on('listening', function () {
66 const address = event.data.server.address();
67 console.log(`Tomato Sauce listening on: ${address.address}:${address.port}`);
68});
69
70tomatoSauce.on('error', function (error) {
71 console.error(error);
72});
73
74tomatoSauce.run();
9a452988 75```
09ab7e98
BB
76
77### Configuration Values
78
79The config object should be a simple object with these keys (All are
80optional.)
81
82 * `port`: The port to listen on (Defaults to 9999)
83 * `frequency`: How often we'll send a new frame in milliseconds
84 (Defaults to 333)
85 * `modulation`: How fast the modulation counter will be increased
86 (Defaults to 5)
87 * `screens`: An array containing the screen functions (Defaults to [])
88 * `renderers`: An array containing the renderer functions (Defaults to [])
89```