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