]>
Commit | Line | Data |
---|---|---|
fd38d409 RBR |
1 | ## Tomato Sauce |
2 | ||
ca0472aa | 3 | Draw stuff via telnet |
09ab7e98 BB |
4 | |
5 | ## How to run | |
6 | ||
fd38d409 RBR |
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 | |
09ab7e98 BB |
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 | ||
fd38d409 RBR |
33 | * `IScreen(modulation <int>, width <int>, height <int>, renderer |
34 | <IRenderer>) -> payload <string>` | |
09ab7e98 BB |
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 | ||
fd38d409 | 52 | * `IRenderer(red <int>, green <int>, blue <int>) -> |
09ab7e98 BB |
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 | ||
fd38d409 RBR |
68 | tomatoSauce.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 |
74 | tomatoSauce.on('error', (error) => { |
75 | ||
09ab7e98 BB |
76 | console.error(error); |
77 | }); | |
78 | ||
79 | tomatoSauce.run(); | |
9a452988 | 80 | ``` |
09ab7e98 BB |
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 []) | |
fd38d409 RBR |
94 | |
95 | [node]: https://nodejs.org/en/ |