This is an automated email from the ASF dual-hosted git repository.
aradzinski pushed a commit to branch NLPCRAFT-474
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-474 by this push:
new 0ec640b wip
0ec640b is described below
commit 0ec640b9db173c6341b664a70de7375170abcea3
Author: Aaron Radzinski <[email protected]>
AuthorDate: Mon Jan 24 13:00:30 2022 -0800
wip
---
.../main/scala/org/apache/nlpcraft/NCGlobals.scala | 63 ------
.../org/apache/nlpcraft/internal/ansi/NCAnsi.scala | 187 ------------------
.../nlpcraft/internal/antlr4/NCCompilerUtils.scala | 9 +-
.../nlpcraft/internal/ascii/NCAsciiTable.scala | 28 +--
.../nlpcraft/internal/intent/NCIDLTerm.scala | 4 +-
.../nlpcraft/internal/makro/NCMacroCompiler.scala | 4 +-
.../apache/nlpcraft/internal/util/NCUtils.scala | 211 +--------------------
7 files changed, 25 insertions(+), 481 deletions(-)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCGlobals.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCGlobals.scala
index 50e26c0..30560ad 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCGlobals.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCGlobals.scala
@@ -18,7 +18,6 @@
package org.apache.nlpcraft
import org.apache.nlpcraft.*
-import internal.ansi.NCAnsi.*
/**
* Global syntax sugar for throwing [[NCException]].
@@ -31,68 +30,6 @@ def E[T](msg: String, cause: Throwable = null): T = throw
new NCException(msg, c
// Internal deep debug flag (more verbose tracing).
final val DEEP_DEBUG = false
-// Re-route to 8-bit colors.
-def G: String = ansi256Fg(34)
-def M: String = ansi256Fg(177)
-def R: String = ansi256Fg(202)
-
-def C: String = ansiCyanFg
-def Y: String = ansiYellowFg
-def W: String = ansi256Fg(231)
-def B: String = ansiBlueFg
-def K: String = ansiBlackFg
-
-def GB: String = ansi256Bg(34)
-def MB: String = ansi256Bg(177)
-def RB: String = ansi256Bg(202)
-def CB: String = ansiCyanBg
-def YB: String = ansiYellowBg
-def WB: String = ansiWhiteBg
-def BB: String = ansiBlueBg
-def KB: String = ansiBlackBg
-
-def BO: String = ansiBold
-def RST: String = ansiReset
-
-def g(s: Any): String = s"$G${s.toString}$RST"
-def m(s: Any): String = s"$M${s.toString}$RST"
-def r(s: Any): String = s"$R${s.toString}$RST"
-def c(s: Any): String = s"$C${s.toString}$RST"
-def y(s: Any): String = s"$Y${s.toString}$RST"
-def w(s: Any): String = s"$W${s.toString}$RST"
-def b(s: Any): String = s"$B${s.toString}$RST"
-def k(s: Any): String = s"$K${s.toString}$RST"
-
-def green(s: Any): String = s"$G${s.toString}$RST"
-def magenta(s: Any): String = s"$M${s.toString}$RST"
-def red(s: Any): String = s"$R${s.toString}$RST"
-def cyan(s: Any): String = s"$C${s.toString}$RST"
-def yellow(s: Any): String = s"$Y${s.toString}$RST"
-def white(s: Any): String = s"$W${s.toString}$RST"
-def blue(s: Any): String = s"$B${s.toString}$RST"
-def black(s: Any): String = s"$K${s.toString}$RST"
-def gb(s: Any): String = s"$GB${s.toString}$RST"
-def rb(s: Any): String = s"$RB${s.toString}$RST"
-def cb(s: Any): String = s"$CB${s.toString}$RST"
-def yb(s: Any): String = s"$YB${s.toString}$RST"
-def wb(s: Any): String = s"$WB${s.toString}$RST"
-def bb(s: Any): String = s"$BB${s.toString}$RST"
-def kb(s: Any): String = s"$KB${s.toString}$RST"
-def greenBg(s: Any): String = s"$GB${s.toString}$RST"
-def magentaBg(s: Any): String = s"$MB${s.toString}$RST"
-def redBg(s: Any): String = s"$RB${s.toString}$RST"
-def cyanBg(s: Any): String = s"$CB${s.toString}$RST"
-def yellowBg(s: Any): String = s"$YB${s.toString}$RST"
-def whiteBg(s: Any): String = s"$WB${s.toString}$RST"
-def blueBg(s: Any): String = s"$BB${s.toString}$RST"
-def blackBg(s: Any): String = s"$KB${s.toString}$RST"
-
-// Effect shortcuts...
-def rv(s: Any): String = s"$ansiReversed${s.toString}$RST"
-def bo(s: Any): String = s"$ansiBold${s.toString}$RST"
-def reverse(s: Any): String = s"$ansiReversed${s.toString}$RST"
-def bold(s: Any): String = s"$ansiBold${s.toString}$RST"
-
extension(v: Int)
def MS: Int = v
def SECS: Int = v * 1000
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/ansi/NCAnsi.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/ansi/NCAnsi.scala
deleted file mode 100644
index 53cc52d..0000000
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/ansi/NCAnsi.scala
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.nlpcraft.internal.ansi
-
-import com.typesafe.scalalogging.LazyLogging
-import org.apache.nlpcraft.internal.*
-import org.apache.nlpcraft.internal.util.NCUtils
-
-/**
- *
- */
-sealed trait NCAnsi extends LazyLogging:
- import NCAnsi.*
-
- private final val ESC = "\u001b"
- private final val BELL = "\u0007"
- private final val CSI = s"$ESC["
- private final val OSC = s"$ESC]"
- private final val RESET = s"${CSI}0m"
-
- // 4-bit colors.
- private final val BLACK = s"${CSI}30m"
- private final val RED = s"${CSI}31m"
- private final val GREEN = s"${CSI}32m"
- private final val YELLOW = s"${CSI}33m"
- private final val BLUE = s"${CSI}34m"
- private final val MAGENTA = s"${CSI}35m"
- private final val CYAN = s"${CSI}36m"
- private final val WHITE = s"${CSI}37m"
- private final val BLACK_B = s"${CSI}40m"
- private final val RED_B = s"${CSI}41m"
- private final val GREEN_B = s"${CSI}42m"
- private final val YELLOW_B = s"${CSI}43m"
- private final val BLUE_B = s"${CSI}44m"
- private final val MAGENTA_B = s"${CSI}45m"
- private final val CYAN_B = s"${CSI}46m"
- private final val WHITE_B = s"${CSI}47m"
-
- def ansi256Fg(color: Int): String = if isEnabled then s"[38;5;${color}m"
else ""
- def ansi256Bg(color: Int): String = if isEnabled then s"[48;5;${color}m"
else ""
- def ansi256Fg(fgColor: Int, s: Any): String =
s"${ansi256Fg(fgColor)}${s.toString}$ansiReset"
- def ansi256(fgColor: Int, bgColor: Int, s: Any): String =
s"${ansi256Fg(fgColor)}${ansi256Bg(bgColor)}${s.toString}$ansiReset"
-
- // Effects.
- private final val BOLD = s"${CSI}1m"
- private final val UNDERLINED = s"${CSI}4m"
- private final val BLINK = s"${CSI}5m"
- private final val REVERSED = s"${CSI}7m"
- private final val INVISIBLE = s"${CSI}8m"
-
- def isEnabled: Boolean = !NCUtils.isSysEnvTrue(PROP)
-
-
- // Re-route to 8-bit colors.
- def G: String = ansi256Fg(34)
- def M: String = ansi256Fg(177)
- def R: String = ansi256Fg(202)
-
- def C: String = ansiCyanFg
- def Y: String = ansiYellowFg
- def W: String = ansi256Fg(231)
- def B: String = ansiBlueFg
- def K: String = ansiBlackFg
-
- def GB: String = ansi256Bg(34)
- def MB: String = ansi256Bg(177)
- def RB: String = ansi256Bg(202)
- def CB: String = ansiCyanBg
- def YB: String = ansiYellowBg
- def WB: String = ansiWhiteBg
- def BB: String = ansiBlueBg
- def KB: String = ansiBlackBg
-
- def BO: String = ansiBold
- def RST: String = ansiReset
-
- def g(s: Any): String = s"$G${s.toString}$RST"
- def m(s: Any): String = s"$M${s.toString}$RST"
- def r(s: Any): String = s"$R${s.toString}$RST"
- def c(s: Any): String = s"$C${s.toString}$RST"
- def y(s: Any): String = s"$Y${s.toString}$RST"
- def w(s: Any): String = s"$W${s.toString}$RST"
- def b(s: Any): String = s"$B${s.toString}$RST"
- def k(s: Any): String = s"$K${s.toString}$RST"
-
- def green(s: Any): String = s"$G${s.toString}$RST"
- def magenta(s: Any): String = s"$M${s.toString}$RST"
- def red(s: Any): String = s"$R${s.toString}$RST"
- def cyan(s: Any): String = s"$C${s.toString}$RST"
- def yellow(s: Any): String = s"$Y${s.toString}$RST"
- def white(s: Any): String = s"$W${s.toString}$RST"
- def blue(s: Any): String = s"$B${s.toString}$RST"
- def black(s: Any): String = s"$K${s.toString}$RST"
- def gb(s: Any): String = s"$GB${s.toString}$RST"
- def rb(s: Any): String = s"$RB${s.toString}$RST"
- def cb(s: Any): String = s"$CB${s.toString}$RST"
- def yb(s: Any): String = s"$YB${s.toString}$RST"
- def wb(s: Any): String = s"$WB${s.toString}$RST"
- def bb(s: Any): String = s"$BB${s.toString}$RST"
- def kb(s: Any): String = s"$KB${s.toString}$RST"
- def greenBg(s: Any): String = s"$GB${s.toString}$RST"
- def magentaBg(s: Any): String = s"$MB${s.toString}$RST"
- def redBg(s: Any): String = s"$RB${s.toString}$RST"
- def cyanBg(s: Any): String = s"$CB${s.toString}$RST"
- def yellowBg(s: Any): String = s"$YB${s.toString}$RST"
- def whiteBg(s: Any): String = s"$WB${s.toString}$RST"
- def blueBg(s: Any): String = s"$BB${s.toString}$RST"
- def blackBg(s: Any): String = s"$KB${s.toString}$RST"
-
- // Effect shortcuts...
- def rv(s: Any): String = s"$ansiReversed${s.toString}$RST"
- def bo(s: Any): String = s"$ansiBold${s.toString}$RST"
- def reverse(s: Any): String = s"$ansiReversed${s.toString}$RST"
- def bold(s: Any): String = s"$ansiBold${s.toString}$RST"
-
- // Color functions.
- def ansiBlackFg: String = if isEnabled then BLACK else ""
- def ansiBlackBg: String = if isEnabled then BLACK_B else ""
- def ansiRedFg: String = if isEnabled then RED else ""
- def ansiRedBg: String = if isEnabled then RED_B else ""
- def ansiGreenFg: String = if isEnabled then GREEN else ""
- def ansiGreenBg: String = if isEnabled then GREEN_B else ""
- def ansiYellowFg: String = if isEnabled then YELLOW else ""
- def ansiYellowBg: String = if isEnabled then YELLOW_B else ""
- def ansiBlueFg: String = if isEnabled then BLUE else ""
- def ansiBlueBg: String = if isEnabled then BLUE_B else ""
- def ansiMagentaFg: String = if isEnabled then MAGENTA else ""
- def ansiMagentaBg: String = if isEnabled then MAGENTA_B else ""
- def ansiCyanFg: String = if isEnabled then CYAN else ""
- def ansiCyanBg: String = if isEnabled then CYAN_B else ""
- def ansiWhiteFg: String = if isEnabled then WHITE else ""
- def ansiWhiteBg: String = if isEnabled then WHITE_B else ""
-
- // Effect functions.
- def ansiBold: String = if isEnabled then BOLD else ""
- def ansiUnderlined: String = if isEnabled then UNDERLINED else ""
- def ansiReset: String = if isEnabled then RESET else ""
- def ansiReversed: String = if isEnabled then REVERSED else ""
- def ansiBlink: String = if isEnabled then BLINK else ""
- def ansiInvisible: String = if isEnabled then INVISIBLE else ""
-
- def ansiGreen(s: Any): String = s"$ansiGreenFg${s.toString}$ansiReset"
- def ansiRed(s: Any): String = s"$ansiRedFg${s.toString}$ansiReset"
- def ansiCyan(s: Any): String = s"$ansiCyanFg${s.toString}s$ansiReset"
- def ansiYellow(s: Any): String = s"$ansiYellowFg${s.toString}$ansiReset"
- def ansiBlack(s: Any): String = s"$ansiBlackFg${s.toString}s$ansiReset"
- def ansiWhite(s: Any): String = s"$ansiWhiteFg${s.toString}$ansiReset"
- def ansiBlue(s: Any): String = s"$ansiBlueFg${s.toString}$ansiReset"
- def ansiMagenta(s: Any): String = s"$ansiMagentaFg${s.toString}$ansiReset"
- def ansiBold(s: Any): String = s"$ansiBold${s.toString}$ansiReset"
-
-/**
- *
- */
-object NCAnsi extends NCAnsi:
- // 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 then
- logger.info(s"${NCUtils.bgRainbow4Bit("ANSI")} coloring is
enabled. Use '-D${ansiCyanFg}NLPCRAFT_ANSI_COLOR_DISABLED$ansiReset=true' to
disable it.", 130, 147)
-
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/antlr4/NCCompilerUtils.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/antlr4/NCCompilerUtils.scala
index 4142ddc..846dcf1 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/antlr4/NCCompilerUtils.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/antlr4/NCCompilerUtils.scala
@@ -18,7 +18,6 @@
package org.apache.nlpcraft.internal.antlr4
import org.apache.nlpcraft.internal.*
-import org.apache.nlpcraft.internal.ansi.NCAnsi.*
case class CompilerErrorHolder(
ptrStr: String,
@@ -37,11 +36,11 @@ object NCCompilerUtils:
val in0 = in.strip()
val pos = Math.max(0, charPos0)
val dash = "-" * in0.length
- var ptrStr = s"${dash.substring(0, pos)}${r("^")}"
+ var ptrStr = s"${dash.substring(0, pos)}\"^\""
- if pos < dash.length - 1 then ptrStr =
s"$ptrStr${y("~")}${y(dash.substring(pos + 2))}"
- else ptrStr = s"$ptrStr${y(dash.substring(pos + 1))}"
+ if pos < dash.length - 1 then ptrStr = s"$ptrStr~${dash.substring(pos
+ 2)}"
+ else ptrStr = s"$ptrStr${dash.substring(pos + 1)}"
- val origStr = s"${in0.substring(0,
pos)}${r(in0.charAt(pos))}${y(in0.substring(pos + 1))}"
+ val origStr = s"${in0.substring(0,
pos)}${in0.charAt(pos)}${in0.substring(pos + 1)}"
CompilerErrorHolder(ptrStr, origStr)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/ascii/NCAsciiTable.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/ascii/NCAsciiTable.scala
index c1ac621..295cff3 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/ascii/NCAsciiTable.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/ascii/NCAsciiTable.scala
@@ -23,7 +23,6 @@ import com.typesafe.scalalogging.Logger
import org.apache.nlpcraft.*
import NCAsciiTable.*
import org.apache.nlpcraft.internal.util.NCUtils
-import org.apache.nlpcraft.internal.ansi.NCAnsi.*
import scala.collection.mutable
import scala.jdk.CollectionConverters.CollectionHasAsScala
@@ -85,7 +84,7 @@ class NCAsciiTable:
*/
private sealed case class Cell(style: Style, lines: Seq[String]):
// Cell's calculated width including padding.
- lazy val width: Int = style.padding + (if height > 0 then
lines.map(NCUtils.stripAnsi(_).length).max else 0)
+ lazy val width: Int = style.padding + (if height > 0 then
lines.map(_.length).max else 0)
// Gets height of the cell.
lazy val height: Int = lines.length
@@ -100,12 +99,12 @@ class NCAsciiTable:
)
// Table drawing symbols.
- private val HDR_HOR = ansi256Fg(105, "=")
- private val HDR_VER = ansi256Fg(105, "|")
- private val HDR_CRS = ansi256Fg(99, "+")
- private val ROW_HOR = ansi256Fg(39, "-")
- private val ROW_VER = ansi256Fg(39, "|")
- private val ROW_CRS = ansi256Fg(202, "+")
+ private val HDR_HOR = "="
+ private val HDR_VER = "|"
+ private val HDR_CRS = "+"
+ private val ROW_HOR = "-"
+ private val ROW_VER = "|"
+ private val ROW_CRS = "+"
// Headers & rows.
private var hdr = IndexedSeq.empty[Cell]
private var rows = IndexedSeq.empty[IndexedSeq[Cell]]
@@ -310,16 +309,13 @@ class NCAsciiTable:
/**
*
- * @param hdr
* @param style
* @param lines
* @return
*/
- private def mkStyledCell(hdr: Boolean, style: String, lines: Any*): Cell =
+ private def mkStyledCell(style: String, lines: Any*): Cell =
val st = Style(style)
- var strLines = lines.map(x)
-
- if hdr then strLines = strLines.map(s => s"$ansiBlueFg$s$ansiReset")
+ val strLines = lines.map(x)
Cell(
st,
@@ -337,7 +333,6 @@ class NCAsciiTable:
*/
def addHeaderCell(lines: Any*): NCAsciiTable =
hdr :+= mkStyledCell(
- true,
defaultHeaderStyle,
lines: _*
)
@@ -350,7 +345,6 @@ class NCAsciiTable:
*/
def addRowCell(lines: Any*): NCAsciiTable =
curRow :+= mkStyledCell(
- false,
defaultRowStyle,
lines: _*
)
@@ -364,7 +358,6 @@ class NCAsciiTable:
*/
def addStyledHeaderCell(style: String, lines: Any*): NCAsciiTable =
hdr :+= mkStyledCell(
- hdr = true,
if style.trim.isEmpty then defaultHeaderStyle else style,
lines: _*
)
@@ -378,7 +371,6 @@ class NCAsciiTable:
*/
def addStyledRowCell(style: String, lines: Any*): NCAsciiTable =
curRow :+= mkStyledCell(
- false,
if style.trim.isEmpty then defaultRowStyle else style,
lines: _*
)
@@ -391,7 +383,7 @@ class NCAsciiTable:
* @param sty Style.
*/
private def aligned(txt: String, width: Int, sty: Style): String =
- val d = width - NCUtils.stripAnsi(txt).length
+ val d = width - txt.length
sty.align match
case "center" => s"${space(d / 2)}$txt${space(d / 2 + d % 2)}"
case "left" => s"${space(sty.leftPad)}$txt${space(d -
sty.leftPad)}"
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/NCIDLTerm.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/NCIDLTerm.scala
index fd52a8b..9dbd6c4 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/NCIDLTerm.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/NCIDLTerm.scala
@@ -61,6 +61,4 @@ case class NCIDLTerm(
meta
)
- override def toString: String = idl
-
- def toAnsiString: String = g(idl)
\ No newline at end of file
+ override def toString: String = idl
\ No newline at end of file
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/makro/NCMacroCompiler.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/makro/NCMacroCompiler.scala
index fe17509..332139a 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/makro/NCMacroCompiler.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/makro/NCMacroCompiler.scala
@@ -215,8 +215,8 @@ object NCMacroCompiler extends LazyLogging:
case s: String if s.last == '.' => s
case s: String => s"$s."
s"""Macro compiler error at line $line - $aMsg
- |-- ${c("Macro:")} ${hldr.origStr}
- +-- ${c("Error:")} ${hldr.ptrStr}"""
+ |-- ${"Macro:"} ${hldr.origStr}
+ +-- ${"Error:"} ${hldr.ptrStr}"""
/**
*
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala
index 05ccd48..2d25e75 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala
@@ -19,7 +19,6 @@ package org.apache.nlpcraft.internal.util
import com.typesafe.scalalogging.*
import org.apache.nlpcraft.*
-import org.apache.nlpcraft.internal.ansi.*
import com.google.gson.*
import java.io.*
import java.net.*
@@ -44,28 +43,6 @@ object NCUtils extends LazyLogging:
private val RND = new Random()
private val sysProps = new SystemProperties
private final lazy val GSON = new
GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create()
- private final val ANSI_SEQ = Pattern.compile("\u001B\\[[?;\\d]*[a-zA-Z]")
- private val ANSI_FG_8BIT_COLORS = for (i <- 16 to 255) yield
NCAnsi.ansi256Fg(i)
- private val ANSI_BG_8BIT_COLORS = for (i <- 16 to 255) yield
NCAnsi.ansi256Bg(i)
- private val ANSI_FG_4BIT_COLORS = Seq(
- NCAnsi.ansiRedFg,
- NCAnsi.ansiGreenFg,
- NCAnsi.ansiBlueFg,
- NCAnsi.ansiYellowFg,
- NCAnsi.ansiWhiteFg,
- NCAnsi.ansiBlackFg,
- NCAnsi.ansiCyanFg
- )
- private val ANSI_BG_4BIT_COLORS = Seq(
- NCAnsi.ansiRedBg,
- NCAnsi.ansiGreenBg,
- NCAnsi.ansiBlueBg,
- NCAnsi.ansiYellowBg,
- NCAnsi.ansiWhiteBg,
- NCAnsi.ansiBlackBg,
- NCAnsi.ansiCyanBg
- )
- private val ANSI_4BIT_COLORS = for (fg <- ANSI_FG_4BIT_COLORS; bg <-
ANSI_BG_4BIT_COLORS) yield s"$fg$bg"
/**
* Gets system property, or environment variable (in that order), or
`None` if none exists.
@@ -116,152 +93,21 @@ object NCUtils extends LazyLogging:
dest.toSeq
/**
- * Prints 4-bit ASCII-logo.
+ * Prints ASCII-logo.
*/
- def asciiLogo4Bit(): String =
- import NCAnsi.*
- raw"$ansiBlueFg _ ____ $ansiCyanFg ______ ______
$ansiReset$NL" +
- raw"$ansiBlueFg / | / / /___ $ansiCyanFg/ ____/________ _/ __/ /_
$ansiReset$NL" +
- raw"$ansiBlueFg / |/ / / __ \$ansiCyanFg/ / / ___/ __ `/ /_/ __/
$ansiReset$NL" +
- raw"$ansiBlueFg / /| / / /_/ /$ansiCyanFg /___/ / / /_/ / __/ /_
$ansiReset$NL" +
- raw"$ansiBold$ansiRedFg/_/ |_/_/ .___/$ansiRedFg\____/_/ \__,_/_/
\__/ $ansiReset$NL" +
- raw"$ansiBold$ansiRedFg /_/
$ansiReset$NL"
-
- /**
- * Prints 8-bit ASCII-logo.
- */
- def asciiLogo8Bit1(): String =
- import NCAnsi.*
- fgRainbow4Bit(
- raw"${ansi256Fg(28)} _ ____ ______ ______
$ansiReset$NL" +
- raw"${ansi256Fg(64)} / | / / /___ / ____/________ _/ __/ /_
$ansiReset$NL" +
- raw"${ansi256Fg(100)} / |/ / / __ \/ / / ___/ __ `/ /_/ __/
$ansiReset$NL" +
- raw"${ansi256Fg(136)} / /| / / /_/ / /___/ / / /_/ / __/ /_
$ansiReset$NL" +
- raw"${ansi256Fg(172)}/_/ |_/_/ .___/\____/_/ \__,_/_/ \__/
$ansiReset$NL" +
- raw"${ansi256Fg(208)} /_/
$ansiReset$NL"
- )
-
- /**
- * Prints 8-bit ASCII-logo.
- */
- def asciiLogo8Bit(): String =
- val startColor = getRandom(Seq(16, 22, 28, 34, 40, 46))
- val range = 6
-
- (for (lineIdx <- Seq(
+ def asciiLogo(): String =
+ Seq(
raw" _ ____ ______ ______ $NL",
raw" / | / / /___ / ____/________ _/ __/ /_ $NL",
raw" / |/ / / __ \/ / / ___/ __ `/ /_/ __/ $NL",
raw" / /| / / /_/ / /___/ / / /_/ / __/ /_ $NL",
raw"/_/ |_/_/ .___/\____/_/ \__,_/_/ \__/ $NL",
raw" /_/ $NL"
- ).zipWithIndex) yield {
- val line = lineIdx._1
- val idx = lineIdx._2
- val start = startColor + (36 * idx)
- val end = start + range - 1
-
- gradAnsi8BitFgLine(line, start, end)
- })
+ )
.mkString("")
/**
*
- * @param line
- * @param startColor Inclusive.
- * @param endColor Inclusive.
- * @return
- */
- def gradAnsi8BitFgLine(line: String, startColor: Int, endColor: Int):
String =
- line.zipWithIndex.foldLeft(new StringBuilder())((buf, zip) => {
- val ch = zip._1
- val idx = zip._2
- val color = startColor + idx % (endColor - startColor + 1)
-
- buf ++= s"${NCAnsi.ansi256Fg(color)}$ch"
- })
- .toString + NCAnsi.ansiReset
-
- /**
- *
- * @param line
- * @param startColor Inclusive.
- * @param endColor Inclusive.
- * @return
- */
- def gradAnsi8BitBgLine(line: String, startColor: Int, endColor: Int):
String =
- line.zipWithIndex.foldLeft(new StringBuilder())((buf, zip) => {
- val ch = zip._1
- val idx = zip._2
- val color = startColor + idx % (endColor - startColor + 1)
-
- buf ++= s"${NCAnsi.ansi256Bg(color)}$ch"
- })
- .toString + NCAnsi.ansiReset
-
- /**
- *
- * @param s
- * @return
- */
- def fgRainbow4Bit(s: String, addOn: String = ""): String = rainbowImpl(s,
ANSI_FG_4BIT_COLORS, addOn)
-
- /**
- *
- * @param s
- * @return
- */
- def fgRainbow8Bit(s: String, addOn: String = ""): String = rainbowImpl(s,
ANSI_FG_8BIT_COLORS, addOn)
-
- /**
- *
- * @param s
- * @return
- */
- def bgRainbow4Bit(s: String, addOn: String = ""): String = rainbowImpl(s,
ANSI_BG_4BIT_COLORS, addOn)
-
- /**
- *
- * @param s
- * @return
- */
- def bgRainbow8Bit(s: String, addOn: String = ""): String = rainbowImpl(s,
ANSI_BG_8BIT_COLORS, addOn)
-
- /**
- *
- * @param s
- * @return
- */
- def rainbow4Bit(s: String, addOn: String = ""): String =
randomRainbowImpl(s, ANSI_4BIT_COLORS, addOn)
-
- /**
- *
- * @param s
- * @param colors
- * @param addOn
- * @return
- */
- private def randomRainbowImpl(s: String, colors: Seq[String], addOn:
String): String =
- s.zipWithIndex.foldLeft(new StringBuilder())((buf, zip) => {
- buf ++= s"${colors(RND.nextInt(colors.size))}$addOn${zip._1}"
- })
- .toString + NCAnsi.ansiReset
-
- /**
- *
- * @param s
- * @param colors
- * @param addOn
- * @return
- */
- private def rainbowImpl(s: String, colors: Seq[String], addOn: String):
String =
- s.zipWithIndex.foldLeft(new StringBuilder())((buf, zip) => {
- buf ++= s"${colors(zip._2 % colors.size)}$addOn${zip._1}"
- })
- .toString + NCAnsi.ansiReset
-
- /**
- *
* @param json
* @return
*/
@@ -353,37 +199,6 @@ object NCUtils extends LazyLogging:
catch case e: Exception => E(s"Cannot extract JSON field '$field'
from: '$json'", e)
/**
- * ANSI color JSON string.
- *
- * @param json JSON string to color.
- * @return
- */
- def colorJson(json: String): String =
- val buf = new StringBuilder
- var inQuotes = false
- var isValue = false
-
- for (ch <- json)
- ch match
- case ':' if !inQuotes => buf ++= r(":"); isValue = true
- case '[' | ']' | '{' | '}' if !inQuotes => buf ++= y(s"$ch");
isValue = false
- case ',' if !inQuotes => buf ++= NCAnsi.ansi256Fg(213,
s"$ch"); isValue = false
- case '"' =>
- if inQuotes then
- buf ++= NCAnsi.ansi256Fg(105, s"$ch")
- else
- buf ++= s"${NCAnsi.ansi256Fg(105)}$ch"
- buf ++= (if isValue then G else NCAnsi.ansiCyanFg)
-
- inQuotes = !inQuotes
-
- case _ => buf ++= s"$ch"
-
-
- buf.append(RST)
- buf.toString()
-
- /**
* Shortcut - current timestamp in milliseconds.
*/
def now(): Long = System.currentTimeMillis()
@@ -398,15 +213,6 @@ object NCUtils extends LazyLogging:
def notNull[T <: AnyRef](v: T, dflt: T): T = if v == null then dflt else v
/**
- * Strips ANSI escape sequences from the given string.
- *
- * @param s
- * @return
- */
- def stripAnsi(s: String): String =
- ANSI_SEQ.matcher(s).replaceAll("")
-
- /**
* Trims each sequence string and filters out empty ones.
*
* @param s String to process.
@@ -547,7 +353,6 @@ object NCUtils extends LazyLogging:
* @param e
*/
private def prettyErrorImpl(logger: PrettyErrorLogger, title: String, e:
Throwable): Unit =
- import NCAnsi.*
logger.log(title)
val INDENT = 2
@@ -557,7 +362,7 @@ object NCUtils extends LazyLogging:
var first = true
var errMsg = x.getLocalizedMessage
if errMsg == null then errMsg = "<null>"
- val exClsName = if !x.isInstanceOf[NCException] then
s"$ansiRedFg[${x.getClass.getCanonicalName}]$ansiReset " else ""
+ val exClsName = if !x.isInstanceOf[NCException] then
s"[${x.getClass.getCanonicalName}] " else ""
val trace =
x.getStackTrace.find(!_.getClassName.startsWith("scala.")).getOrElse(x.getStackTrace.head)
val fileName = trace.getFileName
val lineNum = trace.getLineNumber
@@ -565,10 +370,10 @@ object NCUtils extends LazyLogging:
if fileName == null || lineNum < 0 then
s"$exClsName$errMsg"
else
- s"$exClsName$errMsg $ansiCyanFg->$ansiReset
($fileName:$lineNum)"
+ s"$exClsName$errMsg -> ($fileName:$lineNum)"
msg.split("\n").foreach(line => {
- val s = s"${" " * indent}${if first then ansiBlue("+-+ ") else
" "}${bo(y(line))}"
+ val s = s"${" " * indent}${if first then "+-+ " else "
"}$line}"
logger.log(s)
first = false
})
@@ -589,7 +394,7 @@ object NCUtils extends LazyLogging:
val mtdName = trace.getMethodName
val clsName =
trace.getClassName.replace("org.apache.nlpcraft", "o.a.n")
- logger.log(s"${" " * indent} ${b("|")} $clsName.$mtdName
$ansiCyanFg->$ansiReset ($fileName:$lineNum)")
+ logger.log(s"${" " * indent} | ${clsName}.$mtdName ->
($fileName:$lineNum)")
indent += INDENT