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
|
//Initialisation des messages
const msgStart = "\x1b[31mBienvenu sur Grammalecte pour NodeJS!!!\x1b[0m\n";
const msgPrompt = "\x1b[36mGrammaJS\x1b[33m>\x1b[0m ";
const msgSuite = "\x1b[33m…\x1b[0m ";
const msgEnd = "\x1b[31m\x1b[5m\x1b[5mBye bye!\x1b[0m";
var repJson = false;
var repPerf = false;
var sBufferConsole = "";
var sCmdToExec = "";
var sText = "";
var cmdAction = {
help: {
short: "",
description: "Affiche les informations que vous lisez ;)",
execute: ""
},
perf: {
short: "",
description: "(on/off) Permet d'afficher le temps d'exécution des commandes.",
execute: ""
},
json: {
short: "",
description: "(on/off) Réponse en format format json.",
execute: ""
},
exit: {
short: "",
description: "Client intéractif: Permet de le quitter.",
execute: ""
},
text: {
short: "",
description: "Client / Server: Définir un texte pour plusieurs actions.",
execute: ""
},
gceoption: {
short: "",
description: "Défini une option a utilisé par le correcteur de grammaire.",
execute: ""
},
format: {
short: "",
description: "Permet de mettre en forme le texte.",
execute: "formatText"
},
check: {
short: "",
description: "Vérifie la grammaire et l'orthographe d'un texte.",
execute: "verifParagraph"
},
lexique: {
short: "",
description: "Affiche le lexique du texte.",
execute: "lexique"
},
spell: {
short: "",
description: "Vérifie l'existence d'un mot.",
execute: "spell"
},
suggest: {
short: "",
description: "Suggestion des orthographes possible d'un mot.",
execute: "suggest"
},
morph: {
short: "",
description: "Affiche les informations pour un mot.",
execute: "morph"
},
lemma: {
short: "",
description: "Donne le lemme d'un mot.",
execute: "lemma"
}
};
var cmdOne = ["json", "perf", "help", "exit"];
var cmdMulti = ["text", "format", "check", "lexique", "spell", "suggest", "morph", "lemma"];
var cmdAll = [...cmdOne, ...cmdMulti];
|
>
|
|
>
>
>
|
>
|
>
|
>
<
<
<
<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
//Initialisation des messages
const msgStart = "\x1b[31mBienvenu sur Grammalecte pour NodeJS!!!\x1b[0m\n";
const msgPrompt = "\x1b[36mGrammaJS\x1b[33m>\x1b[0m ";
const msgSuite = "\x1b[33m…\x1b[0m ";
const msgEnd = "\x1b[31m\x1b[5m\x1b[5mBye bye!\x1b[0m";
var repPreference = {
json: false,
perf: false
};
var sBufferConsole = "";
var sCmdToExec = "";
var sText = "";
var cmdAction = {
help: {
short: "",
arg: "",
description: "Affiche les informations que vous lisez ;)",
execute: ""
},
perf: {
short: "",
arg: "on/off",
description: "Permet d'afficher le temps d'exécution des commandes.",
execute: ""
},
json: {
short: "",
arg: "on/off",
description: "Réponse en format format json.",
execute: ""
},
exit: {
short: "",
arg: "",
description: "Client interactif: Permet de le quitter.",
execute: ""
},
text: {
short: "",
arg: "texte",
description: "Client / Server: Définir un texte pour plusieurs actions.",
execute: ""
},
format: {
short: "",
arg: "texte",
description: "Permet de mettre en forme le texte.",
execute: "formatText"
},
check: {
short: "",
arg: "texte",
description: "Vérifie la grammaire et l'orthographe d'un texte.",
execute: "verifParagraph"
},
lexique: {
short: "",
arg: "texte",
description: "Affiche le lexique du texte.",
execute: "lexique"
},
spell: {
short: "",
arg: "mot",
description: "Vérifie l'existence d'un mot.",
execute: "spell"
},
suggest: {
short: "",
arg: "mot",
description: "Suggestion des orthographes possible d'un mot.",
execute: "suggest"
},
morph: {
short: "",
arg: "mot",
description: "Affiche les informations pour un mot.",
execute: "morph"
},
lemma: {
short: "",
arg: "mot",
description: "Donne le lemme d'un mot.",
execute: "lemma"
},
gceoption: {
short: "",
arg: "+/-name",
description: "Défini les options à utiliser par le correcteur de grammaire.",
execute: ""
},
tfoption: {
short: "",
arg: "+/-name",
description: "Défini les options à utiliser par le formateur de texte.",
execute: ""
}
};
var cmdOne = ["json", "perf", "help", "exit"];
var cmdMulti = ["text", "format", "check", "lexique", "spell", "suggest", "morph", "lemma"];
var cmdAll = [...cmdOne, ...cmdMulti];
|
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
if (!isBool(aArg.text)) {
sText = aArg.text;
}
repAction["text"] = sText;
if (getArg(aArg, ["json"])) {
repJson = getArgVal(aArg, ["json"]);
repAction["Json"] = repJson ? "ON" : "OFF";
}
if (getArg(aArg, ["perf"])) {
repPerf = getArgVal(aArg, ["perf"]);
repAction["Perf"] = repPerf ? "ON" : "OFF";
}
if (repPerf) {
tStart = performance.now();
}
if (getArg(aArg, ["gceoption"])) {
let sOpt = sText.split(" ");
if (sOpt[0] == "reset") {
oGrammarChecker.resetGceOptions();
repAction["GceOption"] = "reset";
} else {
let bOptVal = toBool(sOpt[1]);
oGrammarChecker.setGceOption(sOpt[0], bOptVal);
repAction["GceOption"] = sOpt[0] + " " + (bOptVal ? "ON" : "OFF");
}
}
for (const action in aArg) {
if (cmdAction[action] && cmdAction[action].execute !== "") {
if (!isBool(aArg[action]) && aArg[action] !== "") {
repAction.text = aArg[action];
|
>
|
|
|
|
|
<
<
<
|
<
|
>
|
>
|
|
|
|
|
>
|
>
|
|
>
>
|
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
if (!isBool(aArg.text)) {
sText = aArg.text;
}
repAction["text"] = sText;
for (const action of ["json", "perf"]) {
if (getArg(aArg, [action])) {
repPreference[action] = getArgVal(aArg, [action]);
repAction[action] = repPreference[action] ? "ON" : "OFF";
}
}
if (repPreference.perf) {
tStart = performance.now();
}
for (const action of ["gceoption", "tfoption"]) {
if (getArg(aArg, [action])) {
let sFonction = action == "gceoption" ? "GceOption" : "TfOption";
let sOpt = sText.split(" ");
if (sOpt[0] == "reset") {
oGrammarChecker["reset"+sFonction+"s"]();
repAction[action] = "reset";
} else {
for (const optAction of sOpt) {
let bOptVal = optAction[0] == '+' ? true : false;
let sOptName = optAction.slice(1, optAction.length);
oGrammarChecker["set"+sFonction](sOptName, bOptVal);
repAction[action] = sText;
}
}
}
}
for (const action in aArg) {
if (cmdAction[action] && cmdAction[action].execute !== "") {
if (!isBool(aArg[action]) && aArg[action] !== "") {
repAction.text = aArg[action];
|