]> git.r.bdr.sh - rbdr/tomato-sauce/blob - README.md
Merge branch 'feature/rbdr-update-docs' into 'master'
[rbdr/tomato-sauce] / README.md
1 ## Tomato Sauce
2
3 Draw stuff via telnet
4
5 ## How to run
6
7 You will need [Node.js][node] installed, at least version 8. Install
8 dependencies by running `npm install` from the root of the project
9 and start the server by running `npm start`. It will listen on port 9999
10 by default.
11
12 ## Configuration variables
13
14 Tomato 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
28 A screen is a function that will receive a modulation value from 0-255,
29 the width of the viewport, the height of the viewport, and a renderer
30 function, and it returns a string that consists of the commands that
31 will be sent to the socket.
32
33 * `IScreen(modulation <int>, width <int>, height <int>, renderer
34 <IRenderer>) -> payload <string>`
35
36 It should output the required commands that telnet needs to move the
37 cursor and draw. For convenience, a renderer function is passed so
38 calculating color should not be a part of the screen, just moving the
39 cursor around and calling specific colors.
40
41 ## Make your own renderers
42
43 The included renderers are wrappers to some common ways of obtaining
44 colors in the terminal: ANSI, 256 colors, 24-bit colors, and a fake
45 color string that uses incorrect color strings to generate random
46 variations.
47
48 You can build your own renderer by building a function that receives a
49 red, green, and blue component from 0 to 255 and returns the escape
50 codes to generate the color.
51
52 * `IRenderer(red <int>, green <int>, blue <int>) ->
53 colorString <string>`
54
55 ## Using as a library
56
57 The binary just serves as a wrapper to read configuration, and as a
58 bridge to the console. It consumes `lib/tomato_sauce`. All configuration
59 is optional, and should be passed as an object on instantiation. The
60 instance is an event emitter that will emit a `listening` event with
61 the server data, and an `error` event in case something goes wrong.
62
63 ```
64 const TomatoSauce = require('tomato-sauce');
65
66 const tomatoSauce = new TomatoSauce(config);
67
68 tomatoSauce.on('listening', () => {
69
70 const address = event.data.server.address();
71 console.log(`Tomato Sauce listening on: ${address.address}:${address.port}`);
72 });
73
74 tomatoSauce.on('error', (error) => {
75
76 console.error(error);
77 });
78
79 tomatoSauce.run();
80 ```
81
82 ### Configuration Values
83
84 The config object should be a simple object with these keys (All are
85 optional.)
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 [])
94
95 [node]: https://nodejs.org/en/