This repository was archived by the owner on Mar 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.js
129 lines (108 loc) · 3.6 KB
/
client.js
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const EventEmitter = require("events");
class MinitelClient extends EventEmitter {
constructor(path) {
super();
this.minitelInputBuffer = [];
};
/* _handleInput(_data) {
this.lastInput = data;
this.emit("lineInput", this.lastInput);
} */
_rawSend(data) {
// Envoi de données vers le minitel
// Placeholder..
}
_handleLineStop() {
this.emit("newLine", this.minitelInputBuffer.join(""));
// flush
this.minitelInputBuffer = [];
// woaw
}
_sendASCII(asciiChr) {
this._rawSend(String.fromCharCode(asciiChr));
}
_format(texte) {
let _tempTexte = texte;
/*
Source:
https://github.com/cquest/pynitel/blob/master/pynitel.py#L415
*/
// Conversion des caractères accentués (cf STUM p 103)
_tempTexte = _tempTexte.replace("à", "\x19\x41a");
_tempTexte = _tempTexte.replace("â", "\x19\x43a");
_tempTexte = _tempTexte.replace("ä", "\x19\x48a");
_tempTexte = _tempTexte.replace("è", "\x19\x41e");
_tempTexte = _tempTexte.replace("é", "\x19\x42e");
_tempTexte = _tempTexte.replace("ê", "\x19\x43e");
_tempTexte = _tempTexte.replace("ë", "\x19\x48e");
_tempTexte = _tempTexte.replace("î", "\x19\x43i");
_tempTexte = _tempTexte.replace("ï", "\x19\x48i");
_tempTexte = _tempTexte.replace("ô", "\x19\x43o");
_tempTexte = _tempTexte.replace("ö", "\x19\x48o");
_tempTexte = _tempTexte.replace("ù", "\x19\x43u");
_tempTexte = _tempTexte.replace("û", "\x19\x43u");
_tempTexte = _tempTexte.replace("ü", "\x19\x48u");
_tempTexte = _tempTexte.replace("ç", "\x19\x4Bc");
_tempTexte = _tempTexte.replace("°", "\x19\x30");
_tempTexte = _tempTexte.replace("£", "\x19\x23");
_tempTexte = _tempTexte.replace("Œ", "\x19\x6A").replace("œ", "\x19\x7A");
_tempTexte = _tempTexte.replace("ß", "\x19\x7B");
// Caractères spéciaux
_tempTexte = _tempTexte.replace("¼", "\x19\x3C");
_tempTexte = _tempTexte.replace("½", "\x19\x3D");
_tempTexte = _tempTexte.replace("¾", "\x19\x3E");
_tempTexte = _tempTexte.replace("←", "\x19\x2C");
_tempTexte = _tempTexte.replace("↑", "\x19\x2D");
_tempTexte = _tempTexte.replace("→", "\x19\x2E");
_tempTexte = _tempTexte.replace("↓", "\x19\x2F");
_tempTexte = _tempTexte.replace('̶"', "\x60");
_tempTexte = _tempTexte.replace("|", "\x7C");
// Caractères accentués inexistants sur Minitel
_tempTexte = _tempTexte.replace("À", "A").replace("Â", "A").replace("Ä", "A");
_tempTexte = _tempTexte.replace("È", "E").replace("É", "E");
_tempTexte = _tempTexte.replace("Ê", "E").replace("Ë", "E");
_tempTexte = _tempTexte.replace("Ï", "I").replace("Î", "I");
_tempTexte = _tempTexte.replace("Ô", "O").replace("Ö", "O");
_tempTexte = _tempTexte.replace("Ù", "U").replace("Û", "U").replace("Ü", "U");
_tempTexte = _tempTexte.replace("Ç", "C");
return _tempTexte;
}
print(text) {
this._rawSend(this._format(text));
}
sendEsc(text) {
this._sendASCII(27);
this._rawSend(text);
}
setCursorPosition(rows = 1, columns = 1) {
/* if (rows < 1 || columns < 1) {
throw new Error("Rows/Columns can't go under 1!");
} else */ if (rows == 0 && columns === 0) {
this._sendASCII(30);
} else {
// Cursor changing mode
this._sendASCII(31);
// Set position
this._sendASCII(rows + 64);
this._sendASCII(columns + 64);
/* Beep for happiness :)
_sendASCII(7); */
}
}
cls() {
this.setCursorPosition(0, 1);
this._sendASCII(24)
this._sendASCII(12)
}
setBGColor(color) {
this.sendEsc(String.fromCharCode(color + 80));
}
setColor(color) {
this.sendEsc(String.fromCharCode(color + 64));
}
// BEEP
beep() {
this._sendASCII(7);
}
}
module.exports = MinitelClient;