This is an automated email from the ASF dual-hosted git repository.

aradzinski pushed a commit to branch NLPCRAFT-108
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git


The following commit(s) were added to refs/heads/NLPCRAFT-108 by this push:
     new 171a9a3  WIP.
171a9a3 is described below

commit 171a9a3e4bc683dbb1a0c1461b6209a9c0769a53
Author: Aaron Radzinski <[email protected]>
AuthorDate: Thu Sep 24 00:26:55 2020 -0700

    WIP.
---
 .../main/scala/org/apache/nlpcraft/NCStart.scala   |  1 +
 .../apache/nlpcraft/common/ansi/NCAnsiColor.scala  | 28 ++++++++++++----
 .../model/tools/cmdline/NCCommandLine.scala        | 37 +++++++++++++++++++---
 .../scala/org/apache/nlpcraft/probe/NCProbe.scala  |  4 +++
 .../nlpcraft/probe/mgrs/model/NCModelManager.scala |  4 ++-
 .../org/apache/nlpcraft/server/NCServer.scala      |  7 ++--
 6 files changed, 67 insertions(+), 14 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCStart.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCStart.scala
index 4e4edbf..a4d86af 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCStart.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCStart.scala
@@ -22,6 +22,7 @@ import org.apache.nlpcraft.common.version.NCVersion
 import org.apache.nlpcraft.probe.NCProbe
 import org.apache.nlpcraft.server.NCServer
 import org.apache.nlpcraft.common._
+import org.apache.nlpcraft.common.ansi.NCAnsiColor
 import org.apache.nlpcraft.common.ansi.NCAnsiColor._
 
 /**
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/ansi/NCAnsiColor.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/ansi/NCAnsiColor.scala
index cb8c287..8bced4f 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/ansi/NCAnsiColor.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/ansi/NCAnsiColor.scala
@@ -24,6 +24,8 @@ import org.apache.nlpcraft.common._
  * Scala 2.13 shim for `scala.io.AnsiColor`.
  */
 trait NCAnsiColor extends LazyLogging {
+    import NCAnsiColor._
+
     private final val BLACK = "\u001b[30m"
     private final val RED = "\u001b[31m"
     private final val GREEN = "\u001b[32m"
@@ -47,10 +49,6 @@ trait NCAnsiColor extends LazyLogging {
     private final val REVERSED = "\u001b[7m"
     private final val INVISIBLE = "\u001b[8m"
 
-    // Enabled by default.
-    // NOTE: it's not static as it can be changed at runtime.
-    private final val PROP = "NLPCRAFT_ANSI_COLOR_DISABLED"
-
     def isEnabled: Boolean = !U.isSysEnvTrue(PROP)
 
     def ansiBlackFg: String = if (isEnabled) BLACK else ""
@@ -78,6 +76,24 @@ trait NCAnsiColor extends LazyLogging {
 }
 
 object NCAnsiColor extends NCAnsiColor {
-    if (isEnabled)
-        logger.info(s"${U.bgRainbow("ANSI coloring")} ${U.fgRainbow("is 
enabled")}. Use '-D${ansiCyanFg}NLPCRAFT_ANSI_COLOR_DISABLED${ansiReset}=true' 
to disable it.")
+    // Enabled by default.
+    // NOTE: it's not static as it can be changed at runtime.
+    private final val PROP = "NLPCRAFT_ANSI_COLOR_DISABLED"
+
+    /**
+     *
+     * @param f
+     */
+    def setEnabled(f: Boolean): Unit =
+        System.setProperty(PROP, (!f).toString)
+
+    /**
+     *
+     */
+    def ackStatus(): Unit =
+        if (isEnabled)
+            logger.info(
+                s"${U.bgRainbow("ANSI coloring")} ${U.fgRainbow("is 
enabled")}. " +
+                s"Use 
'-D${ansiCyanFg}NLPCRAFT_ANSI_COLOR_DISABLED$ansiReset=true' to disable it."
+            )
 }
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCommandLine.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCommandLine.scala
index 540bce6..2f54737 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCommandLine.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCommandLine.scala
@@ -20,6 +20,7 @@ package org.apache.nlpcraft.model.tools.cmdline
 import org.apache.commons.lang3.SystemUtils
 import org.apache.nlpcraft.common.ascii.NCAsciiTable
 import org.apache.nlpcraft.common._
+import org.apache.nlpcraft.common.ansi.NCAnsiColor
 import org.apache.nlpcraft.common.ansi.NCAnsiColor._
 import org.apache.nlpcraft.common.version.NCVersion
 
@@ -144,6 +145,15 @@ object NCCommandLine extends App {
             )
         ),
         Command(
+            id = "no-ansi",
+            names = Seq("no-ansi"),
+            synopsis = s"Disables usage of ANSI escape codes (colors & 
terminal controls).",
+            desc = Some(
+                s"This is a special command that can be combined with any 
other commands."
+            ),
+            body = cmdNoAnsi
+        ),
+        Command(
             id = "stop-server",
             names = Seq("stop-server"),
             synopsis = s"Stops local REST server.",
@@ -222,6 +232,7 @@ object NCCommandLine extends App {
 
     private final val HELP_CMD = CMDS.find(_.id == "help").get
     private final val DFLT_CMD = CMDS.find(_.id ==  "repl").get
+    private final val NO_ANSI_CMD = CMDS.find(_.id ==  "no-ansi").get
 
     /**
      *
@@ -271,6 +282,14 @@ object NCCommandLine extends App {
      * @param cmd Command descriptor.
      * @param params Parameters, if any, for this command.
      */
+    private def cmdNoAnsi(cmd: Command, params: Seq[String]): Unit = {
+        NCAnsiColor.setEnabled(false)
+    }
+
+    /**
+     * @param cmd Command descriptor.
+     * @param params Parameters, if any, for this command.
+     */
     private def cmdHelp(cmd: Command, params: Seq[String]): Unit = {
         title()
 
@@ -374,7 +393,7 @@ object NCCommandLine extends App {
                             case Some(c) ⇒
                                 if (!seen.contains(c.id)) {
                                     tbl +/ (
-                                        "" → cmd.names.mkString(ansiGreenFg, 
", ", ansiReset),
+                                        "" → c.names.mkString(ansiGreenFg, ", 
", ansiReset),
                                         "align:left, maxWidth:65" → 
mkCmdLines(c)
                                     )
 
@@ -458,7 +477,7 @@ object NCCommandLine extends App {
      * Prints out the version and copyright title header.
      */
     private def title(): Unit = {
-        log(s"$NAME ver. ${VER.version}, rel. ${VER.date}")
+        log(s"$NAME ver. ${VER.version}")
         log(NCVersion.copyright)
         log()
     }
@@ -469,12 +488,20 @@ object NCCommandLine extends App {
      */
     private def boot(args: Array[String]): Unit = {
         if (args.isEmpty)
-            NCCommandLine.DFLT_CMD.body(DFLT_CMD, Seq.empty)
+            DFLT_CMD.body(DFLT_CMD, Seq.empty)
         else {
-            val cmdName = args.head
+            // Handle 'no-ansi' command right away and remove it from the list.
+            args.find(arg ⇒ NO_ANSI_CMD.names.contains(arg)) match {
+                case Some(_) ⇒ NO_ANSI_CMD.body(NO_ANSI_CMD, Seq.empty)
+                case None ⇒ ()
+            }
+
+            val xargs = args.filter(arg ⇒ !NO_ANSI_CMD.names.contains(arg))
+
+            val cmdName = xargs.head
 
             CMDS.find(_.extNames.contains(cmdName)) match {
-                case Some(cmd) ⇒ cmd.body(cmd, args.tail)
+                case Some(cmd) ⇒ cmd.body(cmd, xargs.tail)
                 case None ⇒ error(s"Unknown command: $cmdName")
             }
         }
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbe.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbe.scala
index b790055..3283e72 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbe.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbe.scala
@@ -19,6 +19,8 @@ package org.apache.nlpcraft.probe
 
 import java.util.concurrent.CompletableFuture
 
+import org.apache.nlpcraft.common.ansi.NCAnsiColor
+
 import scala.util.control.Exception.ignoring
 
 /**
@@ -27,6 +29,8 @@ import scala.util.control.Exception.ignoring
 object NCProbe extends App {
     val fut = new CompletableFuture[Integer]
 
+    NCAnsiColor.ackStatus()
+
     NCProbeBoot.start(args, fut)
 
     while (!fut.isDone)
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/model/NCModelManager.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/model/NCModelManager.scala
index 296a299..05b5210 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/model/NCModelManager.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/model/NCModelManager.scala
@@ -60,13 +60,15 @@ object NCModelManager extends NCService with 
DecorateAsScala {
 
                 val synCnt = w.synonyms.values.flatMap(_.values).flatten.size
                 val elmCnt = w.elements.keySet.size
+                val intentCnt = w.intents.size
 
                 tbl += (
                     Seq(
                         s"${mdl.getName}",
                         s"ID: $ansiBold${mdl.getId}$ansiReset, ver: 
${mdl.getVersion}",
                         s"Elements: $elmCnt" + (if (elmCnt == 0) s" 
$ansiRedFg(!)$ansiReset" else ""),
-                        s"Synonyms: $synCnt" + (if (synCnt == 0) s" 
$ansiRedFg(!)$ansiReset" else "")
+                        s"Synonyms: $synCnt" + (if (synCnt == 0) s" 
$ansiRedFg(!)$ansiReset" else ""),
+                        s"Intents: $intentCnt" + (if (intentCnt == 0) s" 
$ansiRedFg(!)$ansiReset" else "")
                     ),
                     w.intents
                         .map(_.toDslString)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/NCServer.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/NCServer.scala
index be565bb..a0dfd1b 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/NCServer.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/NCServer.scala
@@ -22,6 +22,7 @@ import java.util.concurrent.CountDownLatch
 import com.typesafe.config.Config
 import com.typesafe.scalalogging.LazyLogging
 import org.apache.nlpcraft.common._
+import org.apache.nlpcraft.common.ansi.NCAnsiColor
 import org.apache.nlpcraft.common.ansi.NCAnsiColor._
 import org.apache.nlpcraft.common.ascii.NCAsciiTable
 import org.apache.nlpcraft.common.config.NCConfigurable
@@ -154,7 +155,7 @@ object NCServer extends App with NCIgniteInstance with 
LazyLogging with NCOpenCe
       *
       * @return
       */
-    private def setParameters(): Unit = {
+    private def setSysProps(): Unit = {
         System.setProperty("java.net.preferIPv4Stack", "true")
     }
 
@@ -162,7 +163,9 @@ object NCServer extends App with NCIgniteInstance with 
LazyLogging with NCOpenCe
       *
       */
     private def start(): Unit = {
-        setParameters()
+        NCAnsiColor.ackStatus()
+
+        setSysProps()
 
         NCConfigurable.initialize(
             None, // No overrides.

Reply via email to