Index: gc_lang/fr/nodejs/cli/bin/gramma-cli.js ================================================================== --- gc_lang/fr/nodejs/cli/bin/gramma-cli.js +++ gc_lang/fr/nodejs/cli/bin/gramma-cli.js @@ -21,82 +21,103 @@ 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 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: "", - description: "(on/off) Permet d'afficher le temps d'exécution des commandes.", + arg: "on/off", + description: "Permet d'afficher le temps d'exécution des commandes.", execute: "" }, json: { short: "", - description: "(on/off) Réponse en format format json.", + arg: "on/off", + description: "Réponse en format format json.", execute: "" }, exit: { short: "", - description: "Client intéractif: Permet de le quitter.", + arg: "", + description: "Client interactif: Permet de le quitter.", execute: "" }, text: { short: "", + arg: "texte", 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: "", + 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"]; @@ -138,11 +159,11 @@ } function repToText(oRep) { //console.log(oRep); let repText = ""; - for (const action of ["Json", "Perf", "GceOption"]) { + for (const action of ["json", "perf", "gceoption", "tfoption"]) { if (action in oRep) { repText += toTitle(action) + " " + oRep[action]; } } @@ -316,33 +337,36 @@ sText = aArg.text; } repAction["text"] = sText; - if (getArg(aArg, ["json"])) { - repJson = getArgVal(aArg, ["json"]); - repAction["Json"] = repJson ? "ON" : "OFF"; + for (const action of ["json", "perf"]) { + if (getArg(aArg, [action])) { + repPreference[action] = getArgVal(aArg, [action]); + repAction[action] = repPreference[action] ? "ON" : "OFF"; + } } - if (getArg(aArg, ["perf"])) { - repPerf = getArgVal(aArg, ["perf"]); - repAction["Perf"] = repPerf ? "ON" : "OFF"; - } - - if (repPerf) { + if (repPreference.perf) { 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 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 !== "") { @@ -371,11 +395,11 @@ repAction["help"].push(""); repAction["help"].push("========================= Les commandes/arguments: ========================"); repAction["help"].push(""); for (const action in cmdAction) { - repAction["help"].push(action.padEnd(15, ' ') + ': ' + cmdAction[action].description); + repAction["help"].push(action.padEnd(10, ' ') + ': ' + cmdAction[action].arg.padEnd(8, ' ') + ': ' + cmdAction[action].description); } repAction["help"].push(""); repAction["help"].push("================================== Note: =================================="); repAction["help"].push(""); repAction["help"].push("En mode client: les arguments sont de la forme «--argument» !"); @@ -382,17 +406,17 @@ repAction["help"].push("En mode client intéractif: pour les commandes concernant un texte, vous"); repAction["help"].push(" pouvez taper la commande puis entrer (pour saisir le texte) pour "); repAction["help"].push(" terminer la saisie du texte et exécuter la commande taper /\"commande\""); } - if (repPerf) { + if (repPreference.perf) { tEnd = performance.now(); //On ajoute l"information au résultat repAction["time"] = (Math.round((tEnd - tStart) * 1000) / 1000).toString(); } - if (repJson) { + if (repPreference.json) { return JSON.stringify(repAction); } else { return repToText(repAction); } } Index: gc_lang/fr/nodejs/cli/data/script.gramma ================================================================== --- gc_lang/fr/nodejs/cli/data/script.gramma +++ gc_lang/fr/nodejs/cli/data/script.gramma @@ -2,12 +2,16 @@ perf true spell salut suggest salut morph salut lemma salut -gceoption typo false +gceoption -typo check -salut comment,il vas???bienss et tu! salut commentss il vas??? +salut comment,il vas???bienss...et tu! "salut commentss il vas???" /check -gceoption typo true +gceoption +typo check/ -lexique/ +#lexique/ +tfoption +nnbsp_before_punctuation -ts_ellipsis +format/ +tfoption reset +format/ Index: gc_lang/fr/nodejs/cli/readme.md ================================================================== --- gc_lang/fr/nodejs/cli/readme.md +++ gc_lang/fr/nodejs/cli/readme.md @@ -12,23 +12,26 @@ > npm install grammalecte-cli -g ## Commandes -* help : Affiche les informations que vous lisez ;) -* perf : Permet d'afficher le temps d'exécution des commandes. -* json : Réponse en format format json. -* exit : Client interactif: Permet de le quitter. -* format : Permet de mettre en forme le texte. -* check : Vérifie la grammaire et l'orthographe d'un texte. -* lexique : Affiche le lexique du texte. -* spell : Vérifie l'existence d'un mot. -* suggest : Suggestion des orthographes possible d'un mot. -* morph : Affiche les informations pour un mot. -* lemma : Donne le lemme d'un mot. -* text : Client / Server: Définir un texte pour plusieurs actions. -* gceoption : Défini une option a utilisé par le correcteur de grammaire. +| Commande | Argument | Description | +| --------- | -------- | ------------------------------------------------------------- | +| help | | Affiche les informations que vous lisez ;) | +| perf | on/off | Permet d'afficher le temps d'exécution des commandes. | +| json | on/off | Réponse en format format json. | +| exit | | Client interactif: Permet de le quitter. | +| text | texte | Client / Server: Définir un texte pour plusieurs actions. | +| format | texte | Permet de mettre en forme le texte. | +| check | texte | Vérifie la grammaire et l'orthographe d'un texte. | +| lexique | texte | Affiche le lexique du texte. | +| spell | mot | Vérifie l'existence d'un mot. | +| suggest | mot | Suggestion des orthographes possible d'un mot. | +| morph | mot | Affiche les informations pour un mot. | +| lemma | mot | Donne le lemme d'un mot. | +| gceoption | +/-name | Défini les options à utiliser par le correcteur de grammaire. | +| tfoption | +/-name | Défini les options à utiliser par le formateur de texte. | ## Client interactif Le mode interactif est un mode question/réponse. Pour le lancer vous devez saisir `gramma-cli -i`. Index: gc_lang/fr/nodejs/core/api.js ================================================================== --- gc_lang/fr/nodejs/core/api.js +++ gc_lang/fr/nodejs/core/api.js @@ -130,13 +130,14 @@ } if (sOptName) { this._oGce.setOption(sOptName, bValue); return this._helpers.mapToObject(this._oGce.getOptions()); } + return false; } - resetOptions () { + resetGceOptions () { if (!this.isInit.Grammalecte) { this.load(["Grammalecte"]); } this._oGce.resetOptions(); return this._helpers.mapToObject(this._oGce.getOptions()); @@ -232,10 +233,39 @@ if (!this.isInit.TextFormatter) { this.load(["TextFormatter"]); } return this.oTextFormatter.formatText(sText); } + + setTfOptions(dOptions) { + if (!this.isInit.TextFormatter) { + this.load(["TextFormatter"]); + } + this.oTextFormatter.setUsedOptions(dOptions); + return this._helpers.mapToObject(this.oTextFormatter.getUsedOptions()); + } + + setTfOption(sOptName, bValue) { + if (!this.isInit.TextFormatter) { + this.load(["TextFormatter"]); + } + if (sOptName) { + let optionsTF = this.oTextFormatter.getUsedOptions(); + optionsTF.set(sOptName, bValue); + return this._helpers.mapToObject(this.oTextFormatter.getUsedOptions()); + } + return false; + } + + resetTfOptions() { + if (!this.isInit.TextFormatter) { + this.load(["TextFormatter"]); + } + let optionsTF = this.oTextFormatter.getDefaultOptions(); + this.oTextFormatter.setUsedOptions(optionsTF); + return this._helpers.mapToObject(this.oTextFormatter.getUsedOptions()); + } //fonctions concernant plussieurs parties verifParagraph(sText, bSuggest = true){ if (!this.isInit.Grammalecte || !this.isInit.Graphspell) { this.load(["Grammalecte"]);