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 7453bda  WIP.
7453bda is described below

commit 7453bda9244b79e385a7a1d689c08cf6cfa8fe9a
Author: Aaron Radzinski <[email protected]>
AuthorDate: Fri Oct 2 13:36:32 2020 -0700

    WIP.
---
 bin/nlpcraft.cmd                                   | 52 +++++++++++-----------
 bin/nlpcraft.sh                                    | 39 ++++++++--------
 nlpcraft/pom.xml                                   |  4 ++
 .../org/apache/nlpcraft/common/ansi/NCAnsi.scala   |  5 ++-
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 25 ++++++++++-
 pom.xml                                            |  7 +++
 6 files changed, 86 insertions(+), 46 deletions(-)

diff --git a/bin/nlpcraft.cmd b/bin/nlpcraft.cmd
index cd9433a..d312332 100644
--- a/bin/nlpcraft.cmd
+++ b/bin/nlpcraft.cmd
@@ -22,27 +22,25 @@
 :: See https://github.com/apache/ignite for more details.
 ::
 
+:: NOTE: ANSI colors sequences used by default.
+
 Setlocal EnableDelayedExpansion
 
 if "%OS%" == "Windows_NT"  setlocal
 
 :: Check JAVA_HOME.
 if defined JAVA_HOME goto checkJdk
-    echo ERROR:
-    echo ------
-    echo JAVA_HOME environment variable is not found.
-    echo Please point JAVA_HOME variable to location of JDK 11 or later.
-    echo You can also download latest JDK at http://java.com/download.
+    echo ERR: JAVA_HOME environment variable is not found.
+    echo ERR: Please point JAVA_HOME variable to location of JDK 11 
or later.
+    echo ERR: You can also download latest JDK at 
http://java.com/download.
 goto :eof
 
 :checkJdk
 :: Check that JDK is where it should be.
 if exist "%JAVA_HOME%\bin\java.exe" goto checkJdkVersion
-    echo ERROR:
-    echo ------
-    echo JAVA is not found in JAVA_HOME=%JAVA_HOME%.
-    echo Please point JAVA_HOME variable to installation of JDK 11 or later.
-    echo You can also download latest JDK at http://java.com/download.
+    echo ERR: JAVA is not found in  '%JAVA_HOME%'.
+    echo ERR: Please point JAVA_HOME variable to installation of JDK 
11 or later.
+    echo ERR: You can also download latest JDK at 
http://java.com/download.
 goto :eof
 
 :checkJdkVersion
@@ -60,11 +58,9 @@ for /f "tokens=1,2 delims=." %%a in ("%JAVA_VER_STR%.x") do 
set MAJOR_JAVA_VER=%
 if %MAJOR_JAVA_VER% == 1 set MAJOR_JAVA_VER=%MINOR_JAVA_VER%
 
 if %MAJOR_JAVA_VER% LSS 11 (
-    echo ERROR:
-    echo ------
-    echo The version of JAVA installed in %JAVA_HOME% is incorrect.
-    echo Please point JAVA_HOME variable to installation of JDK 11 or later.
-    echo You can also download latest JDK at http://java.com/download.
+    echo ERR: The version %MAJOR_JAVA_VER% of JAVA installed 
in '%JAVA_HOME%' is incompatible.
+    echo ERR: Please point JAVA_HOME variable to installation of JDK 
11 or later.
+    echo ERR: You can also download latest JDK at 
http://java.com/download.
        goto :eof
 )
 
@@ -81,19 +77,25 @@ pushd "%SCRIPT_HOME%"\..
 set INSTALL_HOME=%CD%
 popd
 
-:: Directory containing JARs.
-set BUILD_HOME=%INSTALL_HOME%\build
-
-if not exist "%BUILD_HOME%" (
-    echo ERROR:
-    echo ------
-    echo Folder '%INSTALL_HOME%\build' does not exist.
-    echo This folder should contain NLPCraft JARs and is required to run this 
script.
-       goto :eof
+:: Directories containing JARs:
+::   'build' - JARs from binary distribution.
+::   'dev' - JARs from built sources by 'mvn clean package'.
+set BUILD_JARS=%INSTALL_HOME%\build
+set DEV_JARS=%INSTALL_HOME%\nlpcraft\target
+
+if not exist "%BUILD_JARS%" (
+    if not exist "%DEV_JARS%" (
+        echo ERR: Cannot find JARs for NLPCraft in either of these 
folders:
+        echo ERR:   +- %BUILD_JARS%
+        echo ERR:   +- %DEV_JARS%
+        goto :eof
+    )
 )
 
 :: Build classpath.
-for %%f in ("%BUILD_HOME%"\*.jar) do ( set CP=%%f;!CP! )
+:: NOTE: JARs from 'build' override JARs from 'dev'.
+for %%f in ("%DEV_JARS%"\*-all-deps.jar) do ( set CP=%%f;!CP! )
+for %%f in ("%BUILD_JARS%"\*-all-deps.jar) do ( set CP=%%f;!CP! )
 
 set MAIN_CLASS=org.apache.nlpcraft.model.tools.cmdline.NCCli
 set JVM_OPTS= ^
diff --git a/bin/nlpcraft.sh b/bin/nlpcraft.sh
index 77e982c..7656e07 100644
--- a/bin/nlpcraft.sh
+++ b/bin/nlpcraft.sh
@@ -25,8 +25,11 @@ SCRIPT_NAME="$(basename "$0")"
 # NLPCraft installation home.
 INSTALL_HOME="$(dirname "$SCRIPT_HOME")"
 
-# Directory containing JARs.
-BUILD_HOME="$INSTALL_HOME/build"
+# Directories containing JARs:
+#   'build' - JARs from binary distribution.
+#   'dev' - JARs from built sources by 'mvn clean package'.
+BUILD_JARS="$INSTALL_HOME/build"
+DEV_JARS="$INSTALL_HOME/nlpcraft/target"
 
 # Mac OS specific support to display correct name in the dock.
 if [ "${DOCK_OPTS:-}" == "" ]; then
@@ -64,11 +67,9 @@ checkJava() {
         RETCODE=$?
 
         if [ $RETCODE -ne 0 ]; then
-            echo "ERROR:"
-            echo "------"
-            echo "JAVA_HOME environment variable is not found."
-            echo "Please point JAVA_HOME variable to location of JDK 11 or 
later."
-            echo "You can also download latest JDK at http://java.com/download";
+            echo "\e[31mERR:\e[0m JAVA_HOME environment variable is not found."
+            echo "\e[31mERR:\e[0m Please point JAVA_HOME variable to location 
of JDK 11 or later."
+            echo "\e[31mERR:\e[0m You can also download latest JDK at 
http://java.com/download";
 
             exit 1
         fi
@@ -82,11 +83,9 @@ checkJava() {
     javaMajorVersion "$JAVA"
 
     if [ "$version" -lt 11 ]; then
-        echo "ERROR:"
-        echo "------"
-        echo "The $version version of JAVA installed in JAVA_HOME=$JAVA_HOME 
is incompatible."
-        echo "Please point JAVA_HOME variable to installation of JDK 11 or 
later."
-        echo "You can also download latest JDK at http://java.com/download";
+        echo "\e[31mERR:\e[0m The version \e[36m$version\e[0m of JAVA 
installed in \e[36m'$JAVA_HOME'\e[0m is incompatible."
+        echo "\e[31mERR:\e[0m Please point JAVA_HOME variable to installation 
of JDK 11 or later."
+        echo "\e[31mERR:\e[0m You can also download latest JDK at 
http://java.com/download";
 
         exit 1
     fi
@@ -106,17 +105,21 @@ case "${osname}" in
         ;;
 esac
 
-if ! [ -d "$BUILD_HOME" ]; then
-    echo "ERROR:"
-    echo "------"
-    echo "Folder '${INSTALL_HOME}\build' does not exist."
-    echo "This folder should contain NLPCraft JARs and is required to run this 
script."
+if ! [ -d "$BUILD_JARS" ] && ! [ -d "$DEV_JARS" ]; then
+    echo "\e[31mERR:\e[0m Cannot find JARs for NLPCraft in either of these 
folders:"
+    echo "\e[31mERR:\e[0m   \e[33m+-\e[0m $BUILD_JARS"
+    echo "\e[31mERR:\e[0m   \e[33m+-\e[0m $DEV_JARS"
 
     exit 1
 fi
 
 # Build classpath.
-for file in "$BUILD_HOME"/*.jar
+# NOTE: JARs from 'build' override JARs from 'dev'.
+for file in "$DEV_JARS"/*-all-deps.jar
+do
+    CP=$CP$SEP$file
+done
+for file in "$BUILD_JARS"/*-all-deps.jar
 do
     CP=$CP$SEP$file
 done
diff --git a/nlpcraft/pom.xml b/nlpcraft/pom.xml
index 10d1af0..48078d8 100644
--- a/nlpcraft/pom.xml
+++ b/nlpcraft/pom.xml
@@ -229,6 +229,10 @@
             <groupId>com.github.vertical-blank</groupId>
             <artifactId>sql-formatter</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.jline</groupId>
+            <artifactId>jline</artifactId>
+        </dependency>
 
         <!-- Test dependencies. -->
         <dependency>
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/ansi/NCAnsi.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/ansi/NCAnsi.scala
index f65e333..7066cad 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/ansi/NCAnsi.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/ansi/NCAnsi.scala
@@ -26,7 +26,9 @@ import org.apache.nlpcraft.common._
 sealed trait NCAnsi extends LazyLogging {
     import NCAnsi._
 
-    // Colors.
+    private final val RESET = "\u001b[0m"
+
+    // Colors &effects.
     private final val BLACK = "\u001b[30m"
     private final val RED = "\u001b[31m"
     private final val GREEN = "\u001b[32m"
@@ -43,7 +45,6 @@ sealed trait NCAnsi extends LazyLogging {
     private final val MAGENTA_B = "\u001b[45m"
     private final val CYAN_B = "\u001b[46m"
     private final val WHITE_B = "\u001b[47m"
-    private final val RESET = "\u001b[0m"
     private final val BOLD = "\u001b[1m"
     private final val UNDERLINED = "\u001b[4m"
     private final val BLINK = "\u001b[5m"
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
index 7331e24..45e0295 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
@@ -40,6 +40,12 @@ import java.text.DateFormat
 import java.util.Date
 
 import org.apache.nlpcraft.common.util.NCUtils.IntTimeUnits
+import org.jline.reader.impl.DefaultParser
+import org.jline.terminal.TerminalBuilder
+import org.jline.reader.LineReader
+import org.jline.reader.LineReaderBuilder
+import org.jline.reader.impl.DefaultParser.Bracket
+
 import resource.managed
 
 import scala.collection.mutable
@@ -849,10 +855,27 @@ object NCCli extends App {
 
         var exit = false
 
+        val term = TerminalBuilder.builder()
+            .system(true)
+            .build();
+
+        val parser = new DefaultParser()
+
+        parser.setEofOnUnclosedBracket(Bracket.CURLY, Bracket.ROUND, 
Bracket.SQUARE)
+
+        val reader = LineReaderBuilder
+            .builder
+            .terminal(term)
+//            .completer(completer)
+            .parser(parser)
+            .variable(LineReader.SECONDARY_PROMPT_PATTERN, "%M%P > ")
+            .variable(LineReader.INDENTATION, 2)
+            .build
+
         while (!exit) {
             log(s"${g(">")} ")
 
-            val rawLine = in.readLine()
+            val rawLine = reader.readLine()
 
             if (rawLine == null || QUITS.contains(rawLine.trim))
                 exit = true
diff --git a/pom.xml b/pom.xml
index f423ec3..bd73a7a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -129,6 +129,7 @@
         <diff.utils.ver>4.7</diff.utils.ver>
         <vertical.blank.ver>1.0.1</vertical.blank.ver>
         <fliptables.ver>1.1.0</fliptables.ver>
+        <jline.ver>3.16.0</jline.ver>
 
         <!--
             Following libraries versions are compatible:
@@ -195,6 +196,12 @@
             </dependency>
 
             <dependency>
+                <groupId>org.jline</groupId>
+                <artifactId>jline</artifactId>
+                <version>${jline.ver}</version>
+            </dependency>
+
+            <dependency>
                 <groupId>io.opencensus</groupId>
                 <artifactId>opencensus-exporter-trace-jaeger</artifactId>
                 <version>${opencensus.ver}</version>

Reply via email to