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