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