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 @@ -15,15 +15,22 @@ */ const argCmd = require("../lib/minimist.js")(process.argv.slice(2)); const { performance } = require("perf_hooks"); +//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 ;)", @@ -280,11 +287,10 @@ } } } } - if ("help" in oRep) { let colorNum = 31; for (const action of oRep.help) { //Uniquement pour le fun on met de la couleur ;) if(action.indexOf('===')>-1){ @@ -300,20 +306,19 @@ repText += "\nExécuté en: " + oRep.time + " ms"; } return repText.trim("\n"); } -var sWord = ""; -var actionToExec = function(aArg) { +function actionToExec(aArg) { let repAction = {}; let tStart, tEnd; if (!isBool(aArg.text)) { - sWord = aArg.text; + sText = aArg.text; } - repAction["text"] = sWord; + repAction["text"] = sText; if (getArg(aArg, ["json"])) { repJson = getArgVal(aArg, ["json"]); repAction["Json"] = repJson ? "ON" : "OFF"; } @@ -326,11 +331,11 @@ if (repPerf) { tStart = performance.now(); } if (getArg(aArg, ["gceoption"])) { - let sOpt = sWord.split(" "); + let sOpt = sText.split(" "); if (sOpt[0] == "reset") { oGrammarChecker.resetGceOptions(); repAction["GceOption"] = "reset"; } else { let bOptVal = toBool(sOpt[1]); @@ -341,11 +346,11 @@ for (const action in aArg) { if (cmdAction[action] && cmdAction[action].execute !== "") { if (!isBool(aArg[action]) && aArg[action] !== "") { repAction.text = aArg[action]; - sWord = repAction.text; + sText = repAction.text; } if (!isBool(repAction.text)) { repAction[action] = oGrammarChecker[cmdAction[action].execute](repAction.text); } else { repAction[action] = "NoText"; @@ -388,11 +393,11 @@ if (repJson) { return JSON.stringify(repAction); } else { return repToText(repAction); } -}; +} function argToExec(aCommand, aText, rl, resetCmd = true){ let execAct = {}; aCommand = aCommand.toLowerCase(); @@ -408,11 +413,11 @@ if (resetCmd){ sCmdToExec = ""; } if (typeof(rl) !== "undefined"){ - rl.setPrompt("\x1b[36mGrammaJS\x1b[33m>\x1b[0m "); + rl.setPrompt(msgPrompt); } } function completer(line) { var hits = cmdAll.filter(function(c) { @@ -420,10 +425,11 @@ return c; } }); return [hits && hits.length ? hits : cmdAll, line]; } + if (process.argv.length <= 2) { console.log(actionToExec({help:true})); } else { //var GrammarChecker = require("./api.js"); @@ -476,45 +482,41 @@ } }); server.listen(argCmd.port || 2212); console.log("Server started on http://127.0.0.1:" + (argCmd.port || 2212) + "/"); } else if (getArg(argCmd, ["i", "interactive"])) { - const readline = require("readline"); - const reg = /(.*?) (.*)/gm; - process.stdin.setEncoding("utf8"); + const readline = require("readline"); const rl = readline.createInterface({ crlfDelay: Infinity, input: process.stdin, output: process.stdout, completer: completer, - prompt: "\x1b[36mGrammaJS\x1b[33m>\x1b[0m " + prompt: msgPrompt }); + //console.log( process.stdin.isTTY ); - process.stdout.write("\x1b[31mBienvenu sur Grammalecte pour NodeJS!!!\x1b[0m\n"); + console.log(msgStart); rl.prompt(); rl.on("line", sBuffer => { //process.stdout.write if (sBuffer == "exit") { - console.log("\x1b[31m\x1b[5m\x1b[5mBye bye!\x1b[0m"); + console.log(msgEnd); process.exit(0); } let lg = sBuffer.toLowerCase().trim(); let bSpace = lg.indexOf(" ") > -1; - //sBufferConsole - //console.log("\""+sBuffer+"\""); if (!bSpace) { - //console.log("=> ", lg.slice(0, lg.length-1), cmdAll.indexOf( lg.slice(-1) )); if (cmdOne.indexOf(lg) > -1){ argToExec(lg, sBuffer, rl, true); } else if (cmdAll.indexOf(lg) > -1) { sBufferConsole = ""; sCmdToExec = lg; //Prompt simple pour distinguer que c"est une suite d"une commande - rl.setPrompt("\x1b[33m>\x1b[0m "); + rl.setPrompt(msgSuite); } else if (lg.slice(1) == sCmdToExec) { argToExec(sCmdToExec, sBufferConsole, rl, true); } else if (cmdAll.indexOf(lg.slice(0, lg.length - 1)) > -1) { argToExec(lg.slice(0, lg.length - 1), sBufferConsole, rl, true); } else if (lg == "") { @@ -530,12 +532,12 @@ sBufferConsole += sBuffer + "\n"; } rl.prompt(); }).on("close", () => { - console.log("\n\x1b[31m\x1b[5mBye bye!\x1b[0m"); + console.log(msgEnd); process.exit(0); }); } else { console.log(actionToExec(argCmd)); } } Index: gc_lang/fr/nodejs/cli/package.json ================================================================== --- gc_lang/fr/nodejs/cli/package.json +++ gc_lang/fr/nodejs/cli/package.json @@ -16,11 +16,11 @@ }, "engines": { "node": ">=9.0.0" }, "scripts": { - "gramma-cli": "node bin/gramma-cli.js" + "test": "node bin/gramma-cli.js" }, "dependencies": { "grammalecte": "~1.0.0" }, "files": [ Index: gc_lang/fr/nodejs/core/package.json ================================================================== --- gc_lang/fr/nodejs/core/package.json +++ gc_lang/fr/nodejs/core/package.json @@ -13,8 +13,8 @@ "main": "api.js", "engines": { "node": ">=9.0.0" }, "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\"" } }