You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2016/08/26 20:25:08 UTC
[01/18] tinkerpop git commit: refactoring, added vertex, edge,
path coloring
Repository: tinkerpop
Updated Branches:
refs/heads/master ae1978d53 -> 3f722e661
refactoring, added vertex, edge, path coloring
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/8b58d9b3
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/8b58d9b3
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/8b58d9b3
Branch: refs/heads/master
Commit: 8b58d9b32e1426dccee1d4581bf4b8d672ef20dc
Parents: 2bd80d9
Author: Robert Dale <ro...@gmail.com>
Authored: Fri Aug 19 06:17:53 2016 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Fri Aug 19 14:44:10 2016 -0400
----------------------------------------------------------------------
.../tinkerpop/gremlin/console/Console.groovy | 80 ++++++++++++++------
.../console/commands/GremlinSetCommand.groovy | 2 +
2 files changed, 58 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8b58d9b3/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
index ad56460..841d670 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
@@ -18,8 +18,14 @@
*/
package org.apache.tinkerpop.gremlin.console
+import static org.fusesource.jansi.Ansi.ansi
+
+import java.util.prefs.PreferenceChangeEvent
+import java.util.prefs.PreferenceChangeListener
+
import jline.TerminalFactory
import jline.console.history.FileHistory
+
import org.apache.commons.cli.Option
import org.apache.tinkerpop.gremlin.console.commands.GremlinSetCommand
import org.apache.tinkerpop.gremlin.console.commands.InstallCommand
@@ -30,7 +36,10 @@ import org.apache.tinkerpop.gremlin.console.commands.UninstallCommand
import org.apache.tinkerpop.gremlin.console.plugin.PluggedIn
import org.apache.tinkerpop.gremlin.groovy.loaders.GremlinLoader
import org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin
+import org.apache.tinkerpop.gremlin.process.traversal.Path
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalExplanation
+import org.apache.tinkerpop.gremlin.structure.Edge
+import org.apache.tinkerpop.gremlin.structure.Vertex
import org.apache.tinkerpop.gremlin.util.Gremlin
import org.apache.tinkerpop.gremlin.util.iterator.ArrayIterator
import org.codehaus.groovy.tools.shell.AnsiDetector
@@ -42,13 +51,8 @@ import org.codehaus.groovy.tools.shell.commands.SetCommand
import org.codehaus.groovy.tools.shell.util.HelpFormatter
import org.codehaus.groovy.tools.shell.util.Preferences
import org.fusesource.jansi.Ansi
-import static org.fusesource.jansi.Ansi.ansi
-import org.fusesource.jansi.Ansi.Color
import org.fusesource.jansi.AnsiConsole
-import java.util.prefs.PreferenceChangeEvent
-import java.util.prefs.PreferenceChangeListener
-
/**
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
@@ -72,6 +76,12 @@ class Console {
public static final String PREF_GREMLIN_COLOR = "gremlin.color"
def gremlinColor = { Preferences.get(PREF_GREMLIN_COLOR, "green") }
+ public static final String PREF_VERTEX_COLOR = "vertex.color"
+ def vertexColor = { Preferences.get(PREF_GREMLIN_COLOR, "green") }
+
+ public static final String PREF_EDGE_COLOR = "edge.color"
+ def edgeColor = { Preferences.get(PREF_GREMLIN_COLOR, "bg_blue,bold") }
+
public static final String PREF_ERROR_COLOR = "error.color"
def errorColor = { Preferences.get(PREF_ERROR_COLOR, "bold,red") }
@@ -117,9 +127,9 @@ class Console {
if (!io.quiet) {
io.out.println()
- io.out.println(String.format("@|%s \\,,,/|@", gremlinColor.call()))
- io.out.println(String.format("@|%s (o o)|@", gremlinColor.call()))
- io.out.println(String.format("@|%s -----oOOo-(3)-oOOo-----|@", gremlinColor.call()))
+ io.out.println(ansiRender(gremlinColor, " \\,,,/"))
+ io.out.println(ansiRender(gremlinColor, " (o o)"))
+ io.out.println(ansiRender(gremlinColor, "-----oOOo-(3)-oOOo-----"))
}
maxIteration = Preferences.get(PREFERENCE_ITERATION_MAX, DEFAULT_ITERATION_MAX.toString()).toInteger()
@@ -163,7 +173,7 @@ class Console {
groovy.setHistory(history)
runner.setHistory(history)
} catch (IOException ignored) {
- io.err.println(String.format("@|%s Unable to create history file: %s |@ ", errorColor.call(), ConsoleFs.HISTORY_FILE))
+ io.err.println(ansiRender(errorColor, "Unable to create history file: " + ConsoleFs.HISTORY_FILE))
}
GremlinLoader.load()
@@ -179,7 +189,7 @@ class Console {
pluggedIn.activate()
if (!io.quiet)
- io.out.println(String.format("@|%s plugin activated: %s |@", infoColor.call(), plugin.getName()))
+ io.out.println(ansiRender(infoColor, "plugin activated: " + plugin.getName()))
}
}
}
@@ -214,7 +224,7 @@ class Console {
groovy.setResultHook(handleResultShowNothing)
}
- private def handlePrompt = { interactive ? Ansi.ansi().render(String.format("@|%s %s |@", inputPromptColor.call(), inputPrompt.call())) : "" }
+ private def handlePrompt = { interactive ? ansiRender(inputPromptColor, inputPrompt.call() + " ") : "" }
private def handleResultShowNothing = { args -> null }
@@ -231,11 +241,31 @@ class Console {
int counter = 0;
while (this.tempIterator.hasNext() && (maxIteration == -1 || counter < maxIteration)) {
final Object object = this.tempIterator.next()
- io.out.println(String.format("@|%s %s|@", resultPromptColor.call(), (buildResultPrompt() + ((null == object) ? emptyResult.doCall() : object.toString()))))
+ String prompt = ansiRender(resultPromptColor, buildResultPrompt())
+ if (object instanceof Vertex) {
+ io.out.println(prompt + ansiRender(vertexColor, object.toString()))
+ } else if (object instanceof Edge) {
+ io.out.println(prompt + ansiRender(edgeColor, object.toString()))
+ } else if (object instanceof Path) {
+ List<String> buf = new ArrayList<>();
+ Path path = (Path) object
+ def pathIter = path.iterator()
+ while (pathIter.hasNext()) {
+ object = pathIter.next()
+ if (object instanceof Vertex) {
+ buf.add(ansiRender(vertexColor, object.toString()))
+ } else if (object instanceof Edge) {
+ buf.add(ansiRender(edgeColor, object.toString()))
+ }
+ }
+ io.out.println(prompt + "[" + buf.join(",") + "]")
+ } else {
+ io.out.println(ansiRender(resultPromptColor, (buildResultPrompt() + ((null == object) ? emptyResult.doCall() : object.toString()))))
+ }
counter++;
}
if (this.tempIterator.hasNext())
- io.out.println(String.format("@|%s %s|@", resultPromptColor.call(),ELLIPSIS));
+ io.out.println(ansiRender(resultPromptColor,ELLIPSIS));
this.tempIterator = Collections.emptyIterator();
return null
} else {
@@ -276,10 +306,10 @@ class Console {
}
} else if (result instanceof TraversalExplanation) {
final int width = TerminalFactory.get().getWidth();
- io.out.println(String.format("@|%s %s|@", resultPromptColor.call(),(buildResultPrompt() + result.prettyPrint(width < 20 ? 80 : width))))
+ io.out.println(ansiRender(resultPromptColor,(buildResultPrompt() + result.prettyPrint(width < 20 ? 80 : width))))
return null
} else {
- io.out.println(String.format("@|%s %s|@", resultPromptColor.call(),(buildResultPrompt() + ((null == result) ? emptyResult.doCall() : result.toString()))))
+ io.out.println(ansiRender(resultPromptColor,(buildResultPrompt() + ((null == result) ? emptyResult.doCall() : result.toString()))))
return null
}
} catch (final Exception e) {
@@ -298,14 +328,14 @@ class Console {
String message = e.getMessage()
if (null != message) {
message = message.replace("startup failed:", "")
- io.err.println(String.format("@|%s %s |@", errorColor.call(), message.trim()))
+ io.err.println(ansiRender(errorColor, message.trim()))
} else {
- io.err.println(String.format("@|%s %s |@", errorColor.call(),e))
+ io.err.println(ansiRender(errorColor,e))
}
if (interactive) {
- io.err.println(String.format("@|%s %s |@", infoColor.call(),"Type ':help' or ':h' for help."))
- io.err.print(String.format("@|%s %s |@", errorColor.call(), "Display stack trace? [yN]"))
+ io.err.println(ansiRender(infoColor,"Type ':help' or ':h' for help."))
+ io.err.print(ansiRender(errorColor, "Display stack trace? [yN]"))
io.err.flush()
String line = new BufferedReader(io.in).readLine()
if (null == line)
@@ -320,11 +350,11 @@ class Console {
System.exit(1)
}
} catch (Exception ignored) {
- io.err.println(String.format("@|%s %s |@", errorColor.call(), "An undefined error has occurred: " + err))
+ io.err.println(ansiRender(errorColor, "An undefined error has occurred: " + err))
if (!interactive) System.exit(1)
}
} else {
- io.err.println(String.format("@|%s %s |@", errorColor.call(), "An undefined error has occurred: " + err.toString()))
+ io.err.println(ansiRender(errorColor, "An undefined error has occurred: " + err.toString()))
if (!interactive) System.exit(1)
}
@@ -362,7 +392,7 @@ class Console {
lineNumber++
groovy.execute(line)
} catch (Exception ex) {
- io.err.println(String.format("@|%s %s |@", errorColor.call(), "Error in $scriptFile at [$lineNumber: $line] - ${ex.message}"))
+ io.err.println(ansiRender(errorColor, "Error in $scriptFile at [$lineNumber: $line] - ${ex.message}"))
if (interactive)
break
else {
@@ -375,13 +405,15 @@ class Console {
if (!interactive) System.exit(0)
} catch (FileNotFoundException ignored) {
- io.err.println(String.format("@|%s %s |@", errorColor.call(), "Gremlin file not found at [$scriptFile]."))
+ io.err.println(ansiRender(errorColor, "Gremlin file not found at [$scriptFile]."))
if (!interactive) System.exit(1)
} catch (Exception ex) {
- io.err.println(String.format("@|%s %s |@", errorColor.call(), "Failure processing Gremlin script [$scriptFile] - ${ex.message}"))
+ io.err.println(ansiRender(errorColor, "Failure processing Gremlin script [$scriptFile] - ${ex.message}"))
if (!interactive) System.exit(1)
}
}
+
+ def ansiRender = { color, text -> Ansi.ansi().render(String.format("@|%s %s|@", color.call(), text)) }
public static void main(final String[] args) {
// need to do some up front processing to try to support "bin/gremlin.sh init.groovy" until this deprecated
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8b58d9b3/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy
index a7ac760..53de643 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy
@@ -69,6 +69,8 @@ class GremlinSetCommand extends SetCommand {
set << Console.PREF_EMPTY_RESULT_COLOR
set << Console.PREF_INPUT_PROMPT
set << Console.PREF_RESULT_PROMPT
+ set << Console.PREF_EDGE_COLOR
+ set << Console.PREF_VERTEX_COLOR
return set.toList()
}
[04/18] tinkerpop git commit: fixed some color names
Posted by sp...@apache.org.
fixed some color names
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/fb86b184
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/fb86b184
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/fb86b184
Branch: refs/heads/master
Commit: fb86b1848fb681800b83b731c0d47eb847f60780
Parents: 22dfeff
Author: Robert Dale <ro...@gmail.com>
Authored: Fri Aug 19 14:30:28 2016 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Fri Aug 19 14:46:20 2016 -0400
----------------------------------------------------------------------
.../org/apache/tinkerpop/gremlin/console/Console.groovy | 8 ++++----
.../gremlin/console/commands/GremlinSetCommand.groovy | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fb86b184/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
index 6eb70cb..e752149 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
@@ -77,10 +77,10 @@ class Console {
def gremlinColor = { Preferences.get(PREF_GREMLIN_COLOR, "reset") }
public static final String PREF_VERTEX_COLOR = "vertex.color"
- def vertexColor = { Preferences.get(PREF_GREMLIN_COLOR, "reset") }
+ def vertexColor = { Preferences.get(PREF_VERTEX_COLOR, "reset") }
public static final String PREF_EDGE_COLOR = "edge.color"
- def edgeColor = { Preferences.get(PREF_GREMLIN_COLOR, "reset") }
+ def edgeColor = { Preferences.get(PREF_EDGE_COLOR, "reset") }
public static final String PREF_ERROR_COLOR = "error.color"
def errorColor = { Preferences.get(PREF_ERROR_COLOR, "reset") }
@@ -103,8 +103,8 @@ class Console {
public static final String PREF_RESULT_PROMPT_COLOR = "result.prompt.color"
def resultPromptColor = { Preferences.get(PREF_RESULT_PROMPT_COLOR, "reset") }
- public static final String PREF_EMPTY_RESULT_COLOR = "empty.result.indicator"
- def emptyResult = { Preferences.get(PREF_EMPTY_RESULT_COLOR, "null") }
+ public static final String PREF_EMPTY_RESULT_IND = "empty.result.indicator"
+ def emptyResult = { Preferences.get(PREF_EMPTY_RESULT_IND, "null") }
public static final String PREF_INPUT_PROMPT = "input.prompt"
def inputPrompt = { Preferences.get(PREF_INPUT_PROMPT, "gremlin>") }
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fb86b184/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy
index 3e7dcef..297737c 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy
@@ -66,7 +66,7 @@ class GremlinSetCommand extends SetCommand {
set << Console.PREF_INFO_COLOR
set << Console.PREF_INPUT_PROMPT_COLOR
set << Console.PREF_RESULT_PROMPT_COLOR
- set << Console.PREF_EMPTY_RESULT_COLOR
+ set << Console.PREF_EMPTY_RESULT_IND
set << Console.PREF_INPUT_PROMPT
set << Console.PREF_RESULT_PROMPT
set << Console.PREF_EDGE_COLOR
[10/18] tinkerpop git commit: replaced tabs with space for @pluradj
Posted by sp...@apache.org.
replaced tabs with space for @pluradj
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/72a54f59
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/72a54f59
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/72a54f59
Branch: refs/heads/master
Commit: 72a54f5921be5c8e75feaa84bbc24dd6f82617cf
Parents: 2297100
Author: Robert Dale <ro...@gmail.com>
Authored: Fri Aug 19 16:52:22 2016 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Fri Aug 19 16:52:22 2016 -0400
----------------------------------------------------------------------
.../tinkerpop/gremlin/console/Console.groovy | 128 +++++++++----------
1 file changed, 64 insertions(+), 64 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/72a54f59/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
index c0db789..896cdf5 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
@@ -73,43 +73,43 @@ class Console {
private static final int DEFAULT_ITERATION_MAX = 100
private static int maxIteration = DEFAULT_ITERATION_MAX
- public static final String PREF_GREMLIN_COLOR = "gremlin.color"
+ public static final String PREF_GREMLIN_COLOR = "gremlin.color"
def gremlinColor = { Preferences.get(PREF_GREMLIN_COLOR, "reset") }
-
- public static final String PREF_VERTEX_COLOR = "vertex.color"
- def vertexColor = { Preferences.get(PREF_VERTEX_COLOR, "reset") }
-
- public static final String PREF_EDGE_COLOR = "edge.color"
- def edgeColor = { Preferences.get(PREF_EDGE_COLOR, "reset") }
-
- public static final String PREF_ERROR_COLOR = "error.color"
+
+ public static final String PREF_VERTEX_COLOR = "vertex.color"
+ def vertexColor = { Preferences.get(PREF_VERTEX_COLOR, "reset") }
+
+ public static final String PREF_EDGE_COLOR = "edge.color"
+ def edgeColor = { Preferences.get(PREF_EDGE_COLOR, "reset") }
+
+ public static final String PREF_ERROR_COLOR = "error.color"
def errorColor = { Preferences.get(PREF_ERROR_COLOR, "reset") }
-
- public static final String PREF_INFO_COLOR = "info.color"
+
+ public static final String PREF_INFO_COLOR = "info.color"
def infoColor = { Preferences.get(PREF_INFO_COLOR, "reset") }
-
- public static final String PREF_STRING_COLOR = "string.color"
- def stringColor = { Preferences.get(PREF_STRING_COLOR, "reset") }
-
- public static final String PREF_NUMBER_COLOR = "number.color"
- def numberColor = { Preferences.get(PREF_NUMBER_COLOR, "reset") }
-
- public static final String PREF_T_COLOR = "T.color"
- def tColor = { Preferences.get(PREF_T_COLOR, "reset") }
-
- public static final String PREF_INPUT_PROMPT_COLOR = "input.prompt.color"
+
+ public static final String PREF_STRING_COLOR = "string.color"
+ def stringColor = { Preferences.get(PREF_STRING_COLOR, "reset") }
+
+ public static final String PREF_NUMBER_COLOR = "number.color"
+ def numberColor = { Preferences.get(PREF_NUMBER_COLOR, "reset") }
+
+ public static final String PREF_T_COLOR = "T.color"
+ def tColor = { Preferences.get(PREF_T_COLOR, "reset") }
+
+ public static final String PREF_INPUT_PROMPT_COLOR = "input.prompt.color"
def inputPromptColor = { Preferences.get(PREF_INPUT_PROMPT_COLOR, "reset") }
-
- public static final String PREF_RESULT_PROMPT_COLOR = "result.prompt.color"
+
+ public static final String PREF_RESULT_PROMPT_COLOR = "result.prompt.color"
def resultPromptColor = { Preferences.get(PREF_RESULT_PROMPT_COLOR, "reset") }
- public static final String PREF_EMPTY_RESULT_IND = "empty.result.indicator"
- def emptyResult = { Preferences.get(PREF_EMPTY_RESULT_IND, "null") }
-
- public static final String PREF_INPUT_PROMPT = "input.prompt"
+ public static final String PREF_EMPTY_RESULT_IND = "empty.result.indicator"
+ def emptyResult = { Preferences.get(PREF_EMPTY_RESULT_IND, "null") }
+
+ public static final String PREF_INPUT_PROMPT = "input.prompt"
def inputPrompt = { Preferences.get(PREF_INPUT_PROMPT, "gremlin>") }
- public static final String PREF_RESULT_PROMPT = "result.prompt"
+ public static final String PREF_RESULT_PROMPT = "result.prompt"
static def resultPrompt = { Preferences.get(PREF_RESULT_PROMPT, "==>") }
private static final String IMPORT_SPACE = "import "
@@ -250,9 +250,9 @@ class Console {
int counter = 0;
while (this.tempIterator.hasNext() && (maxIteration == -1 || counter < maxIteration)) {
final Object object = this.tempIterator.next()
- String prompt = ansiRender(resultPromptColor, buildResultPrompt())
- String colorizedResult = colorizeResult(object)
- io.out.println(prompt + ((null == object) ? emptyResult.call() : colorizedResult))
+ String prompt = ansiRender(resultPromptColor, buildResultPrompt())
+ String colorizedResult = colorizeResult(object)
+ io.out.println(prompt + ((null == object) ? emptyResult.call() : colorizedResult))
counter++;
}
if (this.tempIterator.hasNext())
@@ -310,36 +310,36 @@ class Console {
}
}
}
-
- def colorizeResult = { object ->
- if (object instanceof Vertex) {
- return ansiRender(vertexColor, object.toString())
- } else if (object instanceof Edge) {
- return ansiRender(edgeColor, object.toString())
- } else if (object instanceof Iterable) {
- List<String> buf = new ArrayList<>();
- def pathIter = object.iterator()
- while (pathIter.hasNext()) {
- Object n = pathIter.next()
- buf.add(colorizeResult(n))
- }
- return ("[" + buf.join(",") + "]")
- } else if (object instanceof Map) {
- List<String> buf = new ArrayList<>();
- object.each{k, v ->
- buf.add(colorizeResult(k) + ":" + colorizeResult(v))
- }
- return ("[" + buf.join(",") + "]")
- } else if (object instanceof String) {
- return ansiRender(stringColor, object)
- } else if (object instanceof Number) {
- return ansiRender(numberColor, object)
- } else if (object instanceof T) {
- return ansiRender(tColor, object)
- } else {
- return object.toString()
- }
- }
+
+ def colorizeResult = { object ->
+ if (object instanceof Vertex) {
+ return ansiRender(vertexColor, object.toString())
+ } else if (object instanceof Edge) {
+ return ansiRender(edgeColor, object.toString())
+ } else if (object instanceof Iterable) {
+ List<String> buf = new ArrayList<>();
+ def pathIter = object.iterator()
+ while (pathIter.hasNext()) {
+ Object n = pathIter.next()
+ buf.add(colorizeResult(n))
+ }
+ return ("[" + buf.join(",") + "]")
+ } else if (object instanceof Map) {
+ List<String> buf = new ArrayList<>();
+ object.each{k, v ->
+ buf.add(colorizeResult(k) + ":" + colorizeResult(v))
+ }
+ return ("[" + buf.join(",") + "]")
+ } else if (object instanceof String) {
+ return ansiRender(stringColor, object)
+ } else if (object instanceof Number) {
+ return ansiRender(numberColor, object)
+ } else if (object instanceof T) {
+ return ansiRender(tColor, object)
+ } else {
+ return object.toString()
+ }
+ }
private def handleError = { err ->
this.tempIterator = Collections.emptyIterator();
@@ -433,8 +433,8 @@ class Console {
if (!interactive) System.exit(1)
}
}
-
- def ansiRender = { color, text -> Ansi.ansi().render(String.format("@|%s %s|@", color.call(), text)).toString() }
+
+ def ansiRender = { color, text -> Ansi.ansi().render(String.format("@|%s %s|@", color.call(), text)).toString() }
public static void main(final String[] args) {
// need to do some up front processing to try to support "bin/gremlin.sh init.groovy" until this deprecated
[13/18] tinkerpop git commit: separated gremlin preferences node from
groovysh preferences node
Posted by sp...@apache.org.
separated gremlin preferences node from groovysh preferences node
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/04bc602b
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/04bc602b
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/04bc602b
Branch: refs/heads/master
Commit: 04bc602bea652c28d1e1f050ff89f95dbc544e14
Parents: bdded27
Author: Robert Dale <ro...@gmail.com>
Authored: Mon Aug 22 09:36:19 2016 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Mon Aug 22 09:36:19 2016 -0400
----------------------------------------------------------------------
.../tinkerpop/gremlin/console/Console.groovy | 35 ++++---
.../gremlin/console/Preferences.groovy | 102 +++++++++++++++++++
2 files changed, 124 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/04bc602b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
index 896cdf5..a9854db 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
@@ -72,7 +72,7 @@ class Console {
public static final String PREFERENCE_ITERATION_MAX = "max-iteration"
private static final int DEFAULT_ITERATION_MAX = 100
private static int maxIteration = DEFAULT_ITERATION_MAX
-
+
public static final String PREF_GREMLIN_COLOR = "gremlin.color"
def gremlinColor = { Preferences.get(PREF_GREMLIN_COLOR, "reset") }
@@ -102,13 +102,13 @@ class Console {
public static final String PREF_RESULT_PROMPT_COLOR = "result.prompt.color"
def resultPromptColor = { Preferences.get(PREF_RESULT_PROMPT_COLOR, "reset") }
-
+
public static final String PREF_EMPTY_RESULT_IND = "empty.result.indicator"
def emptyResult = { Preferences.get(PREF_EMPTY_RESULT_IND, "null") }
public static final String PREF_INPUT_PROMPT = "input.prompt"
def inputPrompt = { Preferences.get(PREF_INPUT_PROMPT, "gremlin>") }
-
+
public static final String PREF_RESULT_PROMPT = "result.prompt"
static def resultPrompt = { Preferences.get(PREF_RESULT_PROMPT, "==>") }
@@ -127,7 +127,7 @@ class Console {
*/
@Deprecated
public Console(final String initScriptFile) {
- this(new IO(System.in, System.out, System.err), initScriptFile.size() != null ? [initScriptFile] : null, true)
+ this(new IO(System.in, System.out, System.err), initScriptFile.size() != null ? [initScriptFile]: null, true)
}
public Console(final IO io, final List<String> scriptAndArgs, final boolean interactive) {
@@ -143,12 +143,17 @@ class Console {
maxIteration = Preferences.get(PREFERENCE_ITERATION_MAX, DEFAULT_ITERATION_MAX.toString()).toInteger()
Preferences.addChangeListener(new PreferenceChangeListener() {
- @Override
- void preferenceChange(PreferenceChangeEvent evt) {
- if (evt.key == PREFERENCE_ITERATION_MAX)
- maxIteration = Integer.parseInt(evt.newValue)
- }
- })
+ @Override
+ void preferenceChange(PreferenceChangeEvent evt) {
+ if (evt.key == PREFERENCE_ITERATION_MAX && null != evt.newValue)
+ try {
+ maxIteration = Integer.parseInt(evt.newValue)
+ } catch (NumberFormatException e) {
+ io.out.println(ansiRender(errorColor,"Unable to convert '${evt.newValue}' to integer. Using default ${DEFAULT_ITERATION_MAX}"))
+ maxIteration = DEFAULT_ITERATION_MAX
+ }
+ }
+ })
final Mediator mediator = new Mediator(this)
@@ -310,10 +315,10 @@ class Console {
}
}
}
-
+
def colorizeResult = { object ->
if (object instanceof Vertex) {
- return ansiRender(vertexColor, object.toString())
+ return ansiRender(vertexColor, object.toString())
} else if (object instanceof Edge) {
return ansiRender(edgeColor, object.toString())
} else if (object instanceof Iterable) {
@@ -433,10 +438,14 @@ class Console {
if (!interactive) System.exit(1)
}
}
-
+
def ansiRender = { color, text -> Ansi.ansi().render(String.format("@|%s %s|@", color.call(), text)).toString() }
public static void main(final String[] args) {
+
+// ExpandoMetaClass.enableGlobally()
+ org.apache.tinkerpop.gremlin.console.Preferences.expandoMagic()
+
// need to do some up front processing to try to support "bin/gremlin.sh init.groovy" until this deprecated
// feature can be removed. ultimately this should be removed when a breaking change can go in
IO io = new IO(System.in, System.out, System.err)
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/04bc602b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Preferences.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Preferences.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Preferences.groovy
new file mode 100644
index 0000000..699d602
--- /dev/null
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Preferences.groovy
@@ -0,0 +1,102 @@
+/*
+ * 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
+ *
+ * http://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.tinkerpop.gremlin.console;
+
+import java.util.prefs.PreferenceChangeEvent
+import java.util.prefs.PreferenceChangeListener
+
+import org.codehaus.groovy.tools.shell.IO
+
+public class Preferences {
+
+ private static final java.util.prefs.Preferences STORE = java.util.prefs.Preferences.userRoot().node("/org/apache/tinkerpop/gremlin/console");
+
+ public static void expandoMagic() {
+ org.codehaus.groovy.tools.shell.util.Preferences.getMetaClass().'static'.getShowLastResult = {
+ return STORE.getBoolean(org.codehaus.groovy.tools.shell.util.Preferences.SHOW_LAST_RESULT_KEY, true);
+ }
+
+ org.codehaus.groovy.tools.shell.util.Preferences.getMetaClass().'static'.getSanitizeStackTrace = {
+ return STORE.getBoolean(org.codehaus.groovy.tools.shell.util.Preferences.SANITIZE_STACK_TRACE_KEY, true);
+ }
+
+ org.codehaus.groovy.tools.shell.util.Preferences.getMetaClass().'static'.getEditor = {
+ return STORE.get(org.codehaus.groovy.tools.shell.util.Preferences.EDITOR_KEY, System.getenv("EDITOR"));
+ }
+
+ org.codehaus.groovy.tools.shell.util.Preferences.getMetaClass().'static'.getParserFlavor = {
+ return STORE.get(org.codehaus.groovy.tools.shell.util.Preferences.PARSER_FLAVOR_KEY, org.codehaus.groovy.tools.shell.util.Preferences.PARSER_RIGID);
+ }
+
+ //
+ // Store Access
+ //
+
+ org.codehaus.groovy.tools.shell.util.Preferences.getMetaClass().'static'.keys = {
+ return STORE.keys();
+ }
+
+ org.codehaus.groovy.tools.shell.util.Preferences.getMetaClass().'static'.get = { String name, String defaultValue ->
+ return STORE.get(name, defaultValue);
+ }
+
+ org.codehaus.groovy.tools.shell.util.Preferences.getMetaClass().'static'.get = { String name ->
+ return get(name, null);
+ }
+
+ org.codehaus.groovy.tools.shell.util.Preferences.getMetaClass().'static'.put = { String name, String value ->
+ STORE.put(name, value);
+ }
+
+ org.codehaus.groovy.tools.shell.util.Preferences.getMetaClass().'static'.clear = { STORE.clear(); }
+
+ org.codehaus.groovy.tools.shell.util.Preferences.getMetaClass().'static'.addChangeListener = { PreferenceChangeListener listener ->
+ STORE.addPreferenceChangeListener(listener);
+ }
+
+ // reinstall change handler
+ String tmp = STORE.get(org.codehaus.groovy.tools.shell.util.Preferences.VERBOSITY_KEY, IO.Verbosity.INFO.name);
+ try {
+ org.codehaus.groovy.tools.shell.util.Preferences.verbosity = IO.Verbosity.forName(tmp);
+ }
+ catch (IllegalArgumentException e) {
+ org.codehaus.groovy.tools.shell.util.Preferences.verbosity = IO.Verbosity.INFO;
+ STORE.remove(org.codehaus.groovy.tools.shell.util.Preferences.VERBOSITY_KEY);
+ }
+
+ org.codehaus.groovy.tools.shell.util.Preferences.addChangeListener(new PreferenceChangeListener() {
+ public void preferenceChange(final PreferenceChangeEvent event) {
+ if (event.getKey().equals(org.codehaus.groovy.tools.shell.util.Preferences.VERBOSITY_KEY)) {
+ String name = event.getNewValue();
+
+ if (name == null) {
+ name = IO.Verbosity.INFO.name;
+ }
+
+ try {
+ org.codehaus.groovy.tools.shell.util.Preferences.verbosity = IO.Verbosity.forName(name);
+ }
+ catch (Exception e) {
+ event.getNode().put(event.getKey(), org.codehaus.groovy.tools.shell.util.Preferences.verbosity.name);
+ }
+ }
+ }
+ });
+ }
+}
[02/18] tinkerpop git commit: added color preferences: -
gremlin.color - error.color - info.color - input.prompt.color -
result.prompt.color
Posted by sp...@apache.org.
added color preferences:
- gremlin.color
- error.color
- info.color
- input.prompt.color
- result.prompt.color
Also added ability to change input,result prompts and empty indicator (null)
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/2bd80d96
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/2bd80d96
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/2bd80d96
Branch: refs/heads/master
Commit: 2bd80d960b4b6fb54e6cafb93c4c64f35dbda0f2
Parents: 56175fb
Author: Robert Dale <ro...@gmail.com>
Authored: Thu Aug 18 18:50:38 2016 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Fri Aug 19 14:44:10 2016 -0400
----------------------------------------------------------------------
.../tinkerpop/gremlin/console/Console.groovy | 69 +++++++++++++-------
.../console/commands/GremlinSetCommand.groovy | 8 +++
2 files changed, 53 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2bd80d96/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
index 96fcbed..ad56460 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
@@ -68,12 +68,33 @@ class Console {
public static final String PREFERENCE_ITERATION_MAX = "max-iteration"
private static final int DEFAULT_ITERATION_MAX = 100
private static int maxIteration = DEFAULT_ITERATION_MAX
+
+ public static final String PREF_GREMLIN_COLOR = "gremlin.color"
+ def gremlinColor = { Preferences.get(PREF_GREMLIN_COLOR, "green") }
+
+ public static final String PREF_ERROR_COLOR = "error.color"
+ def errorColor = { Preferences.get(PREF_ERROR_COLOR, "bold,red") }
+
+ public static final String PREF_INFO_COLOR = "info.color"
+ def infoColor = { Preferences.get(PREF_INFO_COLOR, "reset") }
+
+ public static final String PREF_INPUT_PROMPT_COLOR = "input.prompt.color"
+ def inputPromptColor = { Preferences.get(PREF_INPUT_PROMPT_COLOR, "white") }
+
+ public static final String PREF_RESULT_PROMPT_COLOR = "result.prompt.color"
+ def resultPromptColor = { Preferences.get(PREF_RESULT_PROMPT_COLOR, "white") }
+
+ public static final String PREF_EMPTY_RESULT_COLOR = "empty.result.indicator"
+ def emptyResult = { Preferences.get(PREF_EMPTY_RESULT_COLOR, "null") }
+
+ public static final String PREF_INPUT_PROMPT = "input.prompt"
+ def inputPrompt = { Preferences.get(PREF_INPUT_PROMPT, "gremlin>") }
+
+ public static final String PREF_RESULT_PROMPT = "result.prompt"
+ static def resultPrompt = { Preferences.get(PREF_RESULT_PROMPT, "==>") }
- private static final String STANDARD_INPUT_PROMPT = "gremlin> "
- private static final String STANDARD_RESULT_PROMPT = "==>"
private static final String IMPORT_SPACE = "import "
private static final String IMPORT_STATIC_SPACE = "import static "
- private static final String NULL = "null"
private static final String ELLIPSIS = "..."
private Iterator tempIterator = Collections.emptyIterator()
@@ -96,12 +117,12 @@ class Console {
if (!io.quiet) {
io.out.println()
- io.out.println(" " + ansi().fg(Ansi.Color.GREEN).a("\\").fg(Ansi.Color.YELLOW).a(",").fg(Ansi.Color.GREEN).a(",").fg(Ansi.Color.YELLOW).a(",").fg(Ansi.Color.GREEN).a("/").reset())
- io.out.println(" " + ansi().fg(Ansi.Color.GREEN).a("(o o)").reset())
- io.out.println(ansi().fg(Ansi.Color.BLUE).a("-----").fg(Ansi.Color.GREEN).a("oOOo").fg(Ansi.Color.BLUE).a("-").fg(Ansi.Color.GREEN).a("(3)").fg(Ansi.Color.BLUE).a("-").fg(Ansi.Color.GREEN).a("oOOo").fg(Ansi.Color.BLUE).a("-----").reset())
+ io.out.println(String.format("@|%s \\,,,/|@", gremlinColor.call()))
+ io.out.println(String.format("@|%s (o o)|@", gremlinColor.call()))
+ io.out.println(String.format("@|%s -----oOOo-(3)-oOOo-----|@", gremlinColor.call()))
}
- maxIteration = Integer.parseInt(Preferences.get(PREFERENCE_ITERATION_MAX, Integer.toString(DEFAULT_ITERATION_MAX)))
+ maxIteration = Preferences.get(PREFERENCE_ITERATION_MAX, DEFAULT_ITERATION_MAX.toString()).toInteger()
Preferences.addChangeListener(new PreferenceChangeListener() {
@Override
void preferenceChange(PreferenceChangeEvent evt) {
@@ -142,7 +163,7 @@ class Console {
groovy.setHistory(history)
runner.setHistory(history)
} catch (IOException ignored) {
- io.err.println("Unable to create history file: " + ConsoleFs.HISTORY_FILE)
+ io.err.println(String.format("@|%s Unable to create history file: %s |@ ", errorColor.call(), ConsoleFs.HISTORY_FILE))
}
GremlinLoader.load()
@@ -158,7 +179,7 @@ class Console {
pluggedIn.activate()
if (!io.quiet)
- io.out.println("plugin activated: " + plugin.getName())
+ io.out.println(String.format("@|%s plugin activated: %s |@", infoColor.call(), plugin.getName()))
}
}
}
@@ -193,7 +214,7 @@ class Console {
groovy.setResultHook(handleResultShowNothing)
}
- private def handlePrompt = { interactive ? STANDARD_INPUT_PROMPT : "" }
+ private def handlePrompt = { interactive ? Ansi.ansi().render(String.format("@|%s %s |@", inputPromptColor.call(), inputPrompt.call())) : "" }
private def handleResultShowNothing = { args -> null }
@@ -210,11 +231,11 @@ class Console {
int counter = 0;
while (this.tempIterator.hasNext() && (maxIteration == -1 || counter < maxIteration)) {
final Object object = this.tempIterator.next()
- io.out.println(buildResultPrompt() + ((null == object) ? NULL : object.toString()))
+ io.out.println(String.format("@|%s %s|@", resultPromptColor.call(), (buildResultPrompt() + ((null == object) ? emptyResult.doCall() : object.toString()))))
counter++;
}
if (this.tempIterator.hasNext())
- io.out.println(ELLIPSIS);
+ io.out.println(String.format("@|%s %s|@", resultPromptColor.call(),ELLIPSIS));
this.tempIterator = Collections.emptyIterator();
return null
} else {
@@ -255,10 +276,10 @@ class Console {
}
} else if (result instanceof TraversalExplanation) {
final int width = TerminalFactory.get().getWidth();
- io.out.println(buildResultPrompt() + result.prettyPrint(width < 20 ? 80 : width))
+ io.out.println(String.format("@|%s %s|@", resultPromptColor.call(),(buildResultPrompt() + result.prettyPrint(width < 20 ? 80 : width))))
return null
} else {
- io.out.println(buildResultPrompt() + ((null == result) ? NULL : result.toString()))
+ io.out.println(String.format("@|%s %s|@", resultPromptColor.call(),(buildResultPrompt() + ((null == result) ? emptyResult.doCall() : result.toString()))))
return null
}
} catch (final Exception e) {
@@ -277,14 +298,14 @@ class Console {
String message = e.getMessage()
if (null != message) {
message = message.replace("startup failed:", "")
- io.err.println("@|bold,red " + message.trim() +" |@ ")
+ io.err.println(String.format("@|%s %s |@", errorColor.call(), message.trim()))
} else {
- io.err.println("@|bold,red " + e + " |@ ")
+ io.err.println(String.format("@|%s %s |@", errorColor.call(),e))
}
if (interactive) {
- io.err.print("@|bold Type ':help' or ':h' for help.|@ \n")
- io.err.print("@|bold,red Display stack trace? [yN]|@ ")
+ io.err.println(String.format("@|%s %s |@", infoColor.call(),"Type ':help' or ':h' for help."))
+ io.err.print(String.format("@|%s %s |@", errorColor.call(), "Display stack trace? [yN]"))
io.err.flush()
String line = new BufferedReader(io.in).readLine()
if (null == line)
@@ -299,11 +320,11 @@ class Console {
System.exit(1)
}
} catch (Exception ignored) {
- io.err.println("@|bold,red An undefined error has occurred: " + err + "|@ ")
+ io.err.println(String.format("@|%s %s |@", errorColor.call(), "An undefined error has occurred: " + err))
if (!interactive) System.exit(1)
}
} else {
- io.err.println("@|bold,red An undefined error has occurred: " + err.toString() + "|@ ")
+ io.err.println(String.format("@|%s %s |@", errorColor.call(), "An undefined error has occurred: " + err.toString()))
if (!interactive) System.exit(1)
}
@@ -319,7 +340,7 @@ class Console {
if (groovyshellEnv != null)
return groovyshellEnv
- return STANDARD_RESULT_PROMPT
+ return resultPrompt.call()
}
private void executeInShell(final List<String> scriptAndArgs) {
@@ -341,7 +362,7 @@ class Console {
lineNumber++
groovy.execute(line)
} catch (Exception ex) {
- io.err.println("Error in $scriptFile at [$lineNumber: $line] - ${ex.message}")
+ io.err.println(String.format("@|%s %s |@", errorColor.call(), "Error in $scriptFile at [$lineNumber: $line] - ${ex.message}"))
if (interactive)
break
else {
@@ -354,10 +375,10 @@ class Console {
if (!interactive) System.exit(0)
} catch (FileNotFoundException ignored) {
- io.err.println("Gremlin file not found at [$scriptFile].")
+ io.err.println(String.format("@|%s %s |@", errorColor.call(), "Gremlin file not found at [$scriptFile]."))
if (!interactive) System.exit(1)
} catch (Exception ex) {
- io.err.println("Failure processing Gremlin script [$scriptFile] - ${ex.message}")
+ io.err.println(String.format("@|%s %s |@", errorColor.call(), "Failure processing Gremlin script [$scriptFile] - ${ex.message}"))
if (!interactive) System.exit(1)
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2bd80d96/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy
index 492fe4d..a7ac760 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy
@@ -61,6 +61,14 @@ class GremlinSetCommand extends SetCommand {
// add Gremlin Console specific preferences here
set << Console.PREFERENCE_ITERATION_MAX
+ set << Console.PREF_GREMLIN_COLOR
+ set << Console.PREF_ERROR_COLOR
+ set << Console.PREF_INFO_COLOR
+ set << Console.PREF_INPUT_PROMPT_COLOR
+ set << Console.PREF_RESULT_PROMPT_COLOR
+ set << Console.PREF_EMPTY_RESULT_COLOR
+ set << Console.PREF_INPUT_PROMPT
+ set << Console.PREF_RESULT_PROMPT
return set.toList()
}
[09/18] tinkerpop git commit: bug fix
Posted by sp...@apache.org.
bug fix
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/2297100d
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/2297100d
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/2297100d
Branch: refs/heads/master
Commit: 2297100d81eacd89cde5b8b48927787eaf40d67d
Parents: e025d30
Author: Robert Dale <ro...@gmail.com>
Authored: Fri Aug 19 15:41:38 2016 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Fri Aug 19 15:41:38 2016 -0400
----------------------------------------------------------------------
.../groovy/org/apache/tinkerpop/gremlin/console/Console.groovy | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2297100d/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
index 3849c24..c0db789 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
@@ -300,7 +300,7 @@ class Console {
io.out.println(ansiRender(resultPromptColor,(buildResultPrompt() + result.prettyPrint(width < 20 ? 80 : width))))
return null
} else {
- io.out.println(ansiRender(resultPromptColor,(buildResultPrompt() + ((null == result) ? emptyResult.call() : result.toString()))))
+ io.out.println(ansiRender(resultPromptColor,buildResultPrompt()).toString() + ((null == result) ? emptyResult.call() : colorizeResult(result)))
return null
}
} catch (final Exception e) {
[17/18] tinkerpop git commit: extra paranoia; refactored
Posted by sp...@apache.org.
extra paranoia; refactored
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/8b3e1413
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/8b3e1413
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/8b3e1413
Branch: refs/heads/master
Commit: 8b3e1413cc7f240f4e071ed93c97307b0926a990
Parents: 7e70540
Author: Robert Dale <ro...@gmail.com>
Authored: Mon Aug 22 19:26:34 2016 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Mon Aug 22 19:26:34 2016 -0400
----------------------------------------------------------------------
.../gremlin/console/Preferences.groovy | 120 ++++++++-----------
1 file changed, 47 insertions(+), 73 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8b3e1413/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Preferences.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Preferences.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Preferences.groovy
index 6cc7664..5403ae8 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Preferences.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Preferences.groovy
@@ -193,84 +193,44 @@ public class Preferences {
@Override
void preferenceChange(PreferenceChangeEvent evt) {
if (evt.key == PREF_GREMLIN_COLOR) {
- if (null == evt.newValue) {
- gremlinColor = STORE.get(PREF_GREMLIN_COLOR, PREF_GREMLIN_COLOR_DEFAULT)
- } else {
- gremlinColor = evt.newValue
- }
- } else if (evt.key == PREF_VERTEX_COLOR) {
- if (null == evt.newValue) {
- vertexColor = STORE.get(PREF_VERTEX_COLOR, PREF_VERTEX_COLOR_DEFAULT)
- } else {
- vertexColor = evt.newValue
- }
- } else if (evt.key == PREF_EDGE_COLOR) {
- if (null == evt.newValue) {
- edgeColor = STORE.get(PREF_EDGE_COLOR, PREF_EDGE_COLOR_DEFAULT)
- } else {
- edgeColor = evt.newValue
- }
- } else if (evt.key == PREF_ERROR_COLOR) {
- if (null == evt.newValue) {
- errorColor = STORE.get(PREF_ERROR_COLOR, PREF_ERROR_COLOR_DEFAULT)
- } else {
- errorColor = evt.newValue
- }
- } else if (evt.key == PREF_INFO_COLOR) {
- if (null == evt.newValue) {
- infoColor = STORE.get(PREF_INFO_COLOR, PREF_INFO_COLOR_DEFAULT)
- } else {
- infoColor = evt.newValue
- }
- } else if (evt.key == PREF_STRING_COLOR) {
- if (null == evt.newValue) {
- stringColor = STORE.get(PREF_STRING_COLOR, PREF_STRING_COLOR_DEFAULT)
- } else {
- stringColor = evt.newValue
- }
- } else if (evt.key == PREF_NUMBER_COLOR) {
- if (null == evt.newValue) {
- numberColor = STORE.get(PREF_NUMBER_COLOR, PREF_NUMBER_COLOR_DEFAULT)
- } else {
- numberColor = evt.newValue
- }
- } else if (evt.key == PREF_T_COLOR) {
- if (null == evt.newValue) {
- tColor = STORE.get(PREF_T_COLOR, PREF_T_COLOR_DEFAULT)
- } else {
- tColor = evt.newValue
- }
- } else if (evt.key == PREF_INPUT_PROMPT_COLOR) {
- if (null == evt.newValue) {
- inputPromptColor = STORE.get(PREF_INPUT_PROMPT_COLOR, PREF_INPUT_PROMPT_COLOR_DEFAULT)
- } else {
- inputPromptColor = evt.newValue
- }
- } else if (evt.key == PREF_RESULT_PROMPT_COLOR) {
- if (null == evt.newValue) {
- resultPromptColor = STORE.get(PREF_RESULT_PROMPT_COLOR, PREF_RESULT_PROMPT_COLOR_DEFAULT)
- } else {
- resultPromptColor = evt.newValue
- }
- } else if (evt.key == PREF_EMPTY_RESULT_IND) {
+ gremlinColor = getValidColor(PREF_GREMLIN_COLOR, evt.newValue, PREF_GREMLIN_COLOR_DEFAULT)
+ } else if (evt.key == PREF_VERTEX_COLOR) {
+ vertexColor = getValidColor(PREF_VERTEX_COLOR, evt.newValue, PREF_VERTEX_COLOR_DEFAULT)
+ } else if (evt.key == PREF_EDGE_COLOR) {
+ edgeColor = getValidColor(PREF_EDGE_COLOR, evt.newValue, PREF_EDGE_COLOR_DEFAULT)
+ } else if (evt.key == PREF_ERROR_COLOR) {
+ errorColor = getValidColor(PREF_ERROR_COLOR, evt.newValue, PREF_ERROR_COLOR_DEFAULT)
+ } else if (evt.key == PREF_INFO_COLOR) {
+ infoColor = getValidColor(PREF_INFO_COLOR, evt.newValue, PREF_INFO_COLOR_DEFAULT)
+ } else if (evt.key == PREF_STRING_COLOR) {
+ stringColor = getValidColor(PREF_STRING_COLOR, evt.newValue, PREF_STRING_COLOR_DEFAULT)
+ } else if (evt.key == PREF_NUMBER_COLOR) {
+ numberColor = getValidColor(PREF_NUMBER_COLOR, evt.newValue, PREF_NUMBER_COLOR_DEFAULT)
+ } else if (evt.key == PREF_T_COLOR) {
+ tColor = getValidColor(PREF_T_COLOR, evt.newValue, PREF_T_COLOR_DEFAULT)
+ } else if (evt.key == PREF_INPUT_PROMPT_COLOR) {
+ inputPromptColor = getValidColor(PREF_INPUT_PROMPT_COLOR, evt.newValue, PREF_INPUT_PROMPT_COLOR_DEFAULT)
+ } else if (evt.key == PREF_RESULT_PROMPT_COLOR) {
+ resultPromptColor = getValidColor(PREF_RESULT_PROMPT_COLOR, evt.newValue, PREF_RESULT_PROMPT_COLOR_DEFAULT)
+ } else if (evt.key == PREF_EMPTY_RESULT_IND) {
if (null == evt.newValue) {
emptyResult = STORE.get(PREF_EMPTY_RESULT_IND, PREF_EMPTY_RESULT_IND_DEFAULT)
} else {
emptyResult = evt.newValue
}
- } else if (evt.key == PREF_INPUT_PROMPT) {
+ } else if (evt.key == PREF_INPUT_PROMPT) {
if (null == evt.newValue) {
inputPrompt = STORE.get(PREF_INPUT_PROMPT, PREF_INPUT_PROMPT_DEFAULT)
} else {
inputPrompt = evt.newValue
}
- } else if (evt.key == PREF_RESULT_PROMPT) {
+ } else if (evt.key == PREF_RESULT_PROMPT) {
if (null == evt.newValue) {
resultPrompt = STORE.get(PREF_RESULT_PROMPT, PREF_RESULT_PROMPT_DEFAULT)
} else {
resultPrompt = evt.newValue
}
- } else if (evt.key == PREF_COLORS) {
+ } else if (evt.key == PREF_COLORS) {
if (null == evt.newValue) {
colors = Boolean.valueOf(STORE.get(PREF_COLORS, PREF_COLORS_DEFAULT.toString()))
} else {
@@ -282,6 +242,20 @@ public class Preferences {
}
+ private static String getValidColor(String key, Object desired, String defaultValue) {
+ String result = desired
+ if (null == result) {
+ result = STORE.get(key, defaultValue)
+ }
+ try {
+ Colorizer.render(result, "test")
+ } catch (Exception e) {
+ println(Colorizer.render(errorColor, "Invalid color option for ${key}: ${result}"))
+ result = defaultValue
+ }
+ return result
+ }
+
private static loadDefaultValues() {
try {
maxIteration = STORE.get(PREFERENCE_ITERATION_MAX, DEFAULT_ITERATION_MAX.toString()).toInteger()
@@ -291,25 +265,25 @@ public class Preferences {
maxIteration = DEFAULT_ITERATION_MAX
}
- gremlinColor = STORE.get(PREF_GREMLIN_COLOR, PREF_GREMLIN_COLOR_DEFAULT)
+ gremlinColor = getValidColor(PREF_GREMLIN_COLOR, null, PREF_GREMLIN_COLOR_DEFAULT)
- vertexColor = STORE.get(PREF_VERTEX_COLOR, PREF_VERTEX_COLOR_DEFAULT)
+ vertexColor = getValidColor(PREF_VERTEX_COLOR, null, PREF_VERTEX_COLOR_DEFAULT)
- edgeColor = STORE.get(PREF_EDGE_COLOR, PREF_EDGE_COLOR_DEFAULT)
+ edgeColor = getValidColor(PREF_EDGE_COLOR, null, PREF_EDGE_COLOR_DEFAULT)
- errorColor = STORE.get(PREF_ERROR_COLOR, PREF_ERROR_COLOR_DEFAULT)
+ errorColor = getValidColor(PREF_ERROR_COLOR, null, PREF_ERROR_COLOR_DEFAULT)
- infoColor = STORE.get(PREF_INFO_COLOR, PREF_INFO_COLOR_DEFAULT)
+ infoColor = getValidColor(PREF_INFO_COLOR, null, PREF_INFO_COLOR_DEFAULT)
- stringColor = STORE.get(PREF_STRING_COLOR, PREF_STRING_COLOR_DEFAULT)
+ stringColor = getValidColor(PREF_STRING_COLOR, null, PREF_STRING_COLOR_DEFAULT)
- numberColor = STORE.get(PREF_NUMBER_COLOR, PREF_NUMBER_COLOR_DEFAULT)
+ numberColor = getValidColor(PREF_NUMBER_COLOR, null, PREF_NUMBER_COLOR_DEFAULT)
- tColor = STORE.get(PREF_T_COLOR, PREF_T_COLOR_DEFAULT)
+ tColor = getValidColor(PREF_T_COLOR, null, PREF_T_COLOR_DEFAULT)
- inputPromptColor = STORE.get(PREF_INPUT_PROMPT_COLOR, PREF_INPUT_PROMPT_COLOR_DEFAULT)
+ inputPromptColor = getValidColor(PREF_INPUT_PROMPT_COLOR, null, PREF_INPUT_PROMPT_COLOR_DEFAULT)
- resultPromptColor = STORE.get(PREF_RESULT_PROMPT_COLOR, PREF_RESULT_PROMPT_COLOR_DEFAULT)
+ resultPromptColor = getValidColor(PREF_RESULT_PROMPT_COLOR, null, PREF_RESULT_PROMPT_COLOR_DEFAULT)
emptyResult = STORE.get(PREF_EMPTY_RESULT_IND, PREF_EMPTY_RESULT_IND_DEFAULT)
[05/18] tinkerpop git commit: colors enabled,
but no color scheme by default
Posted by sp...@apache.org.
colors enabled, but no color scheme by default
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/22dfeff4
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/22dfeff4
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/22dfeff4
Branch: refs/heads/master
Commit: 22dfeff4dbc07163c24782b84fa4979de962e7f5
Parents: a443d6a
Author: Robert Dale <ro...@gmail.com>
Authored: Fri Aug 19 14:23:13 2016 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Fri Aug 19 14:46:20 2016 -0400
----------------------------------------------------------------------
.../org/apache/tinkerpop/gremlin/console/Console.groovy | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/22dfeff4/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
index e79800e..6eb70cb 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
@@ -66,7 +66,7 @@ class Console {
AnsiConsole.systemInstall()
// Register jline ansi detector
Ansi.setDetector(new AnsiDetector())
- Ansi.enabled = false
+ Ansi.enabled = true
}
public static final String PREFERENCE_ITERATION_MAX = "max-iteration"
@@ -136,9 +136,9 @@ class Console {
if (!io.quiet) {
io.out.println()
- io.out.println(ansiRender(gremlinColor, " \\,,,/"))
- io.out.println(ansiRender(gremlinColor, " (o o)"))
- io.out.println(ansiRender(gremlinColor, "-----oOOo-(3)-oOOo-----"))
+ io.out.println(" " + ansiRender(gremlinColor, "\\,,,/"))
+ io.out.println(" " + ansiRender(gremlinColor, "(o o)"))
+ io.out.println("" + ansiRender(gremlinColor, "-----oOOo-(3)-oOOo-----"))
}
maxIteration = Preferences.get(PREFERENCE_ITERATION_MAX, DEFAULT_ITERATION_MAX.toString()).toInteger()
[08/18] tinkerpop git commit: updated docs
Posted by sp...@apache.org.
updated docs
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/e025d30f
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/e025d30f
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/e025d30f
Branch: refs/heads/master
Commit: e025d30fbd979de9753952adaa5ca3c96768242e
Parents: 012bd08
Author: Robert Dale <ro...@gmail.com>
Authored: Fri Aug 19 15:29:48 2016 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Fri Aug 19 15:29:48 2016 -0400
----------------------------------------------------------------------
.../src/reference/gremlin-applications.asciidoc | 53 +++++++++++++++-----
1 file changed, 41 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e025d30f/docs/src/reference/gremlin-applications.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-applications.asciidoc b/docs/src/reference/gremlin-applications.asciidoc
index 76dd45e..b138e6c 100644
--- a/docs/src/reference/gremlin-applications.asciidoc
+++ b/docs/src/reference/gremlin-applications.asciidoc
@@ -150,19 +150,48 @@ some other useful operations. The following table outlines the most commonly us
|:submit |:> |Submit Gremlin to the currently active context defined by `:remote`.
|=========================================================
-Gremlin Console adds a special `max-iteration` preference that can be configured with the standard `:set` command
-from the Groovy Shell. Use this setting to control the maximum number of results that the Console will display.
-Consider the following usage:
+Console Preferences
+~~~~~~~~~~~~~~~~~~~
-[gremlin-groovy]
-----
-:set max-iteration 10
-(0..200)
-:set max-iteration 5
-(0..200)
-----
+Preferences are set with `:set name value`. Value can not contain spaces. Preferences are removed by `:purge preferences`
+
+[width="100%",cols="3,^2,10",options="header"]
+|=========================================================
+|Preference |Type |Description
+|max-iteration | int | Controls the maximum number of results that the Console will display. Default: 100 results.
+|gremlin.color | colors | Color of the ASCII art gremlin on startup.
+|info.color | colors | Color of "info" type messages.
+|error.color | colors | Color of "error" type messages.
+|vertex.color | colors | Color of vertices results.
+|edge.color | colors | Color of edges in results.
+|string.color | colors | Colors of strings in results.
+|number.color | colors | Color of numbers in results.
+|T.color | colors| Color of Tokens in results.
+|input.prompt.color | colors | Color of the input prompt.
+|result.prompt.color | colors | Color of the result prompt.
+|input.prompt | string | Text of the input prompt.
+|result.prompt | string | Text of the result prompt.
+|empty.result.indicator | string | Text of the void/no results indicator.
+|=========================================================
+
+Colors can contain a comma-separated combination of 1 each of foreground, background, and attribute.
+
+[width="100%",cols="3,^2,10",options="header"]
+|=========================================================
+|Foreground |Background |Attributes
+|black|bg_black|bold
+|blue|bg_blue|faint
+|cyan|bg_cyan|underline
+|green|bg_green|
+|magenta|bg_magenta|
+|red|bg_red|
+|white|bg_white|
+|yellow|bg_yellow|
+|=========================================================
+
+Example:
+```:set gremlin.color bg_black,green,bold```
-If this setting is not present, the console will default the maximum to 100 results.
Dependencies and Plugin Usage
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1838,7 +1867,7 @@ g.V.map{it.name} // sugar
Utilities Plugin
~~~~~~~~~~~~~~~~
-The Utilities Plugin provides various functions, helper methods and imports of external classes that are useful in the console.
+The Utilities Plugin provides various functions, helper methods and imports of external classes that are useful in the console.
NOTE: The Utilities Plugin is enabled in the Gremlin Console by default.
[18/18] tinkerpop git commit: Merge branch 'pr-384'
Posted by sp...@apache.org.
Merge branch 'pr-384'
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/3f722e66
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/3f722e66
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/3f722e66
Branch: refs/heads/master
Commit: 3f722e66178c8e904082eccde1baf5d19560d903
Parents: ae1978d 8b3e141
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Aug 26 16:24:47 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Aug 26 16:24:47 2016 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 2 +
.../src/reference/gremlin-applications.asciidoc | 54 +++-
.../upgrade/release-3.2.x-incubating.asciidoc | 22 ++
.../tinkerpop/gremlin/console/Colorizer.groovy | 45 +++
.../tinkerpop/gremlin/console/Console.groovy | 117 ++++----
.../gremlin/console/GremlinGroovysh.groovy | 19 +-
.../gremlin/console/Preferences.groovy | 296 +++++++++++++++++++
.../console/commands/GremlinSetCommand.groovy | 22 +-
8 files changed, 507 insertions(+), 70 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3f722e66/CHANGELOG.asciidoc
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3f722e66/docs/src/upgrade/release-3.2.x-incubating.asciidoc
----------------------------------------------------------------------
[11/18] tinkerpop git commit: fixed bug where :set didn't allow
spaces. but what else did it break???
Posted by sp...@apache.org.
fixed bug where :set didn't allow spaces. but what else did it break???
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/5bd11526
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/5bd11526
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/5bd11526
Branch: refs/heads/master
Commit: 5bd115266ef7a27abf1a34547fca720ad46c115e
Parents: 72a54f5
Author: Robert Dale <ro...@gmail.com>
Authored: Fri Aug 19 18:10:57 2016 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Fri Aug 19 18:10:57 2016 -0400
----------------------------------------------------------------------
docs/src/reference/gremlin-applications.asciidoc | 2 +-
.../tinkerpop/gremlin/console/GremlinGroovysh.groovy | 10 ++++++----
2 files changed, 7 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5bd11526/docs/src/reference/gremlin-applications.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-applications.asciidoc b/docs/src/reference/gremlin-applications.asciidoc
index b138e6c..7074fb9 100644
--- a/docs/src/reference/gremlin-applications.asciidoc
+++ b/docs/src/reference/gremlin-applications.asciidoc
@@ -153,7 +153,7 @@ some other useful operations. The following table outlines the most commonly us
Console Preferences
~~~~~~~~~~~~~~~~~~~
-Preferences are set with `:set name value`. Value can not contain spaces. Preferences are removed by `:purge preferences`
+Preferences are set with `:set name value`. Values can contain spaces when quoted. Preferences are removed by `:purge preferences`
[width="100%",cols="3,^2,10",options="header"]
|=========================================================
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5bd11526/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy
index 31a8ba8..fdf799a 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy
@@ -22,6 +22,7 @@ import org.codehaus.groovy.tools.shell.Command
import org.codehaus.groovy.tools.shell.Groovysh
import org.codehaus.groovy.tools.shell.ParseCode
import org.codehaus.groovy.tools.shell.Parser
+import org.codehaus.groovy.tools.shell.util.CommandArgumentParser
/**
* Overrides the posix style parsing of Groovysh allowing for commands to parse prior to Groovy 2.4.x.
@@ -45,12 +46,13 @@ class GremlinGroovysh extends Groovysh {
Command findCommand(final String line, final List<String> parsedArgs = null) {
def l = line ?: ""
- final List<String> args = parseLine(l)
- if (args.size() == 0) return null
+ final List<String> linetokens = parseLine(l)
+ if (linetokens.size() == 0) return null
- def cmd = registry.find(args[0])
+ def cmd = registry.find(linetokens[0])
- if (cmd != null && args.size() > 1 && parsedArgs != null) {
+ if (cmd != null && linetokens.size() > 1 && parsedArgs != null) {
+ List<String> args = CommandArgumentParser.parseLine(line, parsedArgs == null ? 1 : -1)
parsedArgs.addAll(args[1..-1])
}
[12/18] tinkerpop git commit: :remote commands had trouble with the
line parsing so made a special case just for GremlinSetCommand
Posted by sp...@apache.org.
:remote commands had trouble with the line parsing so made a special case just for GremlinSetCommand
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/bdded273
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/bdded273
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/bdded273
Branch: refs/heads/master
Commit: bdded27325fc5c10f41ef44f5d422b39b9ccbb51
Parents: 5bd1152
Author: Robert Dale <ro...@gmail.com>
Authored: Sat Aug 20 09:05:07 2016 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Sat Aug 20 09:05:07 2016 -0400
----------------------------------------------------------------------
.../tinkerpop/gremlin/console/GremlinGroovysh.groovy | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/bdded273/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy
index fdf799a..2da0100 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy
@@ -18,6 +18,7 @@
*/
package org.apache.tinkerpop.gremlin.console
+import org.apache.tinkerpop.gremlin.console.commands.GremlinSetCommand
import org.codehaus.groovy.tools.shell.Command
import org.codehaus.groovy.tools.shell.Groovysh
import org.codehaus.groovy.tools.shell.ParseCode
@@ -52,8 +53,14 @@ class GremlinGroovysh extends Groovysh {
def cmd = registry.find(linetokens[0])
if (cmd != null && linetokens.size() > 1 && parsedArgs != null) {
- List<String> args = CommandArgumentParser.parseLine(line, parsedArgs == null ? 1 : -1)
- parsedArgs.addAll(args[1..-1])
+ if (cmd instanceof GremlinSetCommand) {
+ // the following line doesn't play well with :remote scripts because it tokenizes quoted args as single args
+ // but at this point only the set command had trouble with quoted params/args with spaces
+ List<String> args = CommandArgumentParser.parseLine(line, parsedArgs == null ? 1 : -1)
+ parsedArgs.addAll(args[1..-1])
+ } else {
+ parsedArgs.addAll(linetokens[1..-1])
+ }
}
return cmd
[07/18] tinkerpop git commit: minor edit
Posted by sp...@apache.org.
minor edit
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/012bd089
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/012bd089
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/012bd089
Branch: refs/heads/master
Commit: 012bd089f684332fa9c1547a18577c134109586a
Parents: fb86b18
Author: Robert Dale <ro...@gmail.com>
Authored: Fri Aug 19 14:33:39 2016 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Fri Aug 19 14:46:20 2016 -0400
----------------------------------------------------------------------
.../groovy/org/apache/tinkerpop/gremlin/console/Console.groovy | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/012bd089/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
index e752149..3849c24 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
@@ -300,7 +300,7 @@ class Console {
io.out.println(ansiRender(resultPromptColor,(buildResultPrompt() + result.prettyPrint(width < 20 ? 80 : width))))
return null
} else {
- io.out.println(ansiRender(resultPromptColor,(buildResultPrompt() + ((null == result) ? emptyResult.doCall() : result.toString()))))
+ io.out.println(ansiRender(resultPromptColor,(buildResultPrompt() + ((null == result) ? emptyResult.call() : result.toString()))))
return null
}
} catch (final Exception e) {
[03/18] tinkerpop git commit: made life more colorful
Posted by sp...@apache.org.
made life more colorful
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/56175fb7
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/56175fb7
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/56175fb7
Branch: refs/heads/master
Commit: 56175fb714e6b8ec516fce57a27c4679a5b253ad
Parents: da47a21
Author: Robert Dale <ro...@gmail.com>
Authored: Thu Aug 18 13:34:04 2016 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Fri Aug 19 14:44:10 2016 -0400
----------------------------------------------------------------------
.../tinkerpop/gremlin/console/Console.groovy | 24 +++++++++++++-------
1 file changed, 16 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/56175fb7/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
index 8dcb272..96fcbed 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
@@ -42,6 +42,8 @@ import org.codehaus.groovy.tools.shell.commands.SetCommand
import org.codehaus.groovy.tools.shell.util.HelpFormatter
import org.codehaus.groovy.tools.shell.util.Preferences
import org.fusesource.jansi.Ansi
+import static org.fusesource.jansi.Ansi.ansi
+import org.fusesource.jansi.Ansi.Color
import org.fusesource.jansi.AnsiConsole
import java.util.prefs.PreferenceChangeEvent
@@ -94,9 +96,9 @@ class Console {
if (!io.quiet) {
io.out.println()
- io.out.println(" \\,,,/")
- io.out.println(" (o o)")
- io.out.println("-----oOOo-(3)-oOOo-----")
+ io.out.println(" " + ansi().fg(Ansi.Color.GREEN).a("\\").fg(Ansi.Color.YELLOW).a(",").fg(Ansi.Color.GREEN).a(",").fg(Ansi.Color.YELLOW).a(",").fg(Ansi.Color.GREEN).a("/").reset())
+ io.out.println(" " + ansi().fg(Ansi.Color.GREEN).a("(o o)").reset())
+ io.out.println(ansi().fg(Ansi.Color.BLUE).a("-----").fg(Ansi.Color.GREEN).a("oOOo").fg(Ansi.Color.BLUE).a("-").fg(Ansi.Color.GREEN).a("(3)").fg(Ansi.Color.BLUE).a("-").fg(Ansi.Color.GREEN).a("oOOo").fg(Ansi.Color.BLUE).a("-----").reset())
}
maxIteration = Integer.parseInt(Preferences.get(PREFERENCE_ITERATION_MAX, Integer.toString(DEFAULT_ITERATION_MAX)))
@@ -275,13 +277,14 @@ class Console {
String message = e.getMessage()
if (null != message) {
message = message.replace("startup failed:", "")
- io.err.println(message.trim())
+ io.err.println("@|bold,red " + message.trim() +" |@ ")
} else {
- io.err.println(e)
+ io.err.println("@|bold,red " + e + " |@ ")
}
if (interactive) {
- io.err.print("Display stack trace? [yN] ")
+ io.err.print("@|bold Type ':help' or ':h' for help.|@ \n")
+ io.err.print("@|bold,red Display stack trace? [yN]|@ ")
io.err.flush()
String line = new BufferedReader(io.in).readLine()
if (null == line)
@@ -296,11 +299,11 @@ class Console {
System.exit(1)
}
} catch (Exception ignored) {
- io.err.println("An undefined error has occurred: " + err)
+ io.err.println("@|bold,red An undefined error has occurred: " + err + "|@ ")
if (!interactive) System.exit(1)
}
} else {
- io.err.println("An undefined error has occurred: " + err.toString())
+ io.err.println("@|bold,red An undefined error has occurred: " + err.toString() + "|@ ")
if (!interactive) System.exit(1)
}
@@ -379,6 +382,7 @@ class Console {
D(longOpt: 'debug', "Enabled debug Console output")
i(longOpt: 'interactive', argName: "SCRIPT ARG1 ARG2 ...", args: Option.UNLIMITED_VALUES, valueSeparator: ' ' as char, "Execute the specified script and leave the console open on completion")
e(longOpt: 'execute', argName: "SCRIPT ARG1 ARG2 ...", args: Option.UNLIMITED_VALUES, valueSeparator: ' ' as char, "Execute the specified script (SCRIPT ARG1 ARG2 ...) and close the console on completion")
+ C(longOpt: 'color', "Disable use of ANSI colors")
}
OptionAccessor options = cli.parse(args)
@@ -387,6 +391,10 @@ class Console {
System.exit(22) // Invalid Args
}
+ if (options.C) {
+ Ansi.enabled = false
+ }
+
if (options.h) {
cli.usage()
System.exit(0)
[14/18] tinkerpop git commit: - Preferences store no longer conflicts
with groovysh - colors can be enabled/disable with :set colors [true|false] -
all preferences moved to Preferences class - all (almost) ansi methods moved
to Colorizer class - replaced
Posted by sp...@apache.org.
- Preferences store no longer conflicts with groovysh
- colors can be enabled/disable with :set colors [true|false]
- all preferences moved to Preferences class
- all (almost) ansi methods moved to Colorizer class
- replaced all color closure evaluations with static strings (faster)
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/34dc8e40
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/34dc8e40
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/34dc8e40
Branch: refs/heads/master
Commit: 34dc8e40932810c5198e2da489ff9a178d602008
Parents: 04bc602
Author: Robert Dale <ro...@gmail.com>
Authored: Mon Aug 22 11:17:48 2016 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Mon Aug 22 11:17:48 2016 -0400
----------------------------------------------------------------------
.../tinkerpop/gremlin/console/Colorizer.groovy | 45 ++++
.../tinkerpop/gremlin/console/Console.groovy | 132 +++--------
.../gremlin/console/Preferences.groovy | 220 +++++++++++++++++++
.../console/commands/GremlinSetCommand.groovy | 37 ++--
4 files changed, 314 insertions(+), 120 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/34dc8e40/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Colorizer.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Colorizer.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Colorizer.groovy
new file mode 100644
index 0000000..908d0ff
--- /dev/null
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Colorizer.groovy
@@ -0,0 +1,45 @@
+/*
+ * 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
+ *
+ * http://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.tinkerpop.gremlin.console;
+
+import org.codehaus.groovy.tools.shell.AnsiDetector
+import org.fusesource.jansi.Ansi
+import org.fusesource.jansi.AnsiConsole
+
+public class Colorizer {
+
+ public static void installAnsi() {
+ // must be called before IO(), since it modifies System.in
+ // Install the system adapters, replaces System.out and System.err
+ // Must be called before using IO(), because IO stores refs to System.out and System.err
+ AnsiConsole.systemInstall()
+ // Register jline ansi detector
+ Ansi.setDetector(new AnsiDetector())
+ Ansi.enabled = true
+ }
+
+ public static String render(String color, String text) {
+ if (Ansi.isEnabled() && Preferences.colors) {
+ Ansi.ansi().render(String.format("@|%s %s|@", color, text)).toString()
+ } else {
+ return text
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/34dc8e40/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
index a9854db..202f068 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
@@ -18,11 +18,6 @@
*/
package org.apache.tinkerpop.gremlin.console
-import static org.fusesource.jansi.Ansi.ansi
-
-import java.util.prefs.PreferenceChangeEvent
-import java.util.prefs.PreferenceChangeListener
-
import jline.TerminalFactory
import jline.console.history.FileHistory
@@ -42,16 +37,13 @@ import org.apache.tinkerpop.gremlin.structure.T
import org.apache.tinkerpop.gremlin.structure.Vertex
import org.apache.tinkerpop.gremlin.util.Gremlin
import org.apache.tinkerpop.gremlin.util.iterator.ArrayIterator
-import org.codehaus.groovy.tools.shell.AnsiDetector
import org.codehaus.groovy.tools.shell.ExitNotification
import org.codehaus.groovy.tools.shell.Groovysh
import org.codehaus.groovy.tools.shell.IO
import org.codehaus.groovy.tools.shell.InteractiveShellRunner
import org.codehaus.groovy.tools.shell.commands.SetCommand
import org.codehaus.groovy.tools.shell.util.HelpFormatter
-import org.codehaus.groovy.tools.shell.util.Preferences
import org.fusesource.jansi.Ansi
-import org.fusesource.jansi.AnsiConsole
/**
* @author Stephen Mallette (http://stephen.genoprime.com)
@@ -60,58 +52,9 @@ class Console {
static {
// this is necessary so that terminal doesn't lose focus to AWT
System.setProperty("java.awt.headless", "true")
- // must be called before IO(), since it modifies System.in
- // Install the system adapters, replaces System.out and System.err
- // Must be called before using IO(), because IO stores refs to System.out and System.err
- AnsiConsole.systemInstall()
- // Register jline ansi detector
- Ansi.setDetector(new AnsiDetector())
- Ansi.enabled = true
+ Colorizer.installAnsi()
}
- public static final String PREFERENCE_ITERATION_MAX = "max-iteration"
- private static final int DEFAULT_ITERATION_MAX = 100
- private static int maxIteration = DEFAULT_ITERATION_MAX
-
- public static final String PREF_GREMLIN_COLOR = "gremlin.color"
- def gremlinColor = { Preferences.get(PREF_GREMLIN_COLOR, "reset") }
-
- public static final String PREF_VERTEX_COLOR = "vertex.color"
- def vertexColor = { Preferences.get(PREF_VERTEX_COLOR, "reset") }
-
- public static final String PREF_EDGE_COLOR = "edge.color"
- def edgeColor = { Preferences.get(PREF_EDGE_COLOR, "reset") }
-
- public static final String PREF_ERROR_COLOR = "error.color"
- def errorColor = { Preferences.get(PREF_ERROR_COLOR, "reset") }
-
- public static final String PREF_INFO_COLOR = "info.color"
- def infoColor = { Preferences.get(PREF_INFO_COLOR, "reset") }
-
- public static final String PREF_STRING_COLOR = "string.color"
- def stringColor = { Preferences.get(PREF_STRING_COLOR, "reset") }
-
- public static final String PREF_NUMBER_COLOR = "number.color"
- def numberColor = { Preferences.get(PREF_NUMBER_COLOR, "reset") }
-
- public static final String PREF_T_COLOR = "T.color"
- def tColor = { Preferences.get(PREF_T_COLOR, "reset") }
-
- public static final String PREF_INPUT_PROMPT_COLOR = "input.prompt.color"
- def inputPromptColor = { Preferences.get(PREF_INPUT_PROMPT_COLOR, "reset") }
-
- public static final String PREF_RESULT_PROMPT_COLOR = "result.prompt.color"
- def resultPromptColor = { Preferences.get(PREF_RESULT_PROMPT_COLOR, "reset") }
-
- public static final String PREF_EMPTY_RESULT_IND = "empty.result.indicator"
- def emptyResult = { Preferences.get(PREF_EMPTY_RESULT_IND, "null") }
-
- public static final String PREF_INPUT_PROMPT = "input.prompt"
- def inputPrompt = { Preferences.get(PREF_INPUT_PROMPT, "gremlin>") }
-
- public static final String PREF_RESULT_PROMPT = "result.prompt"
- static def resultPrompt = { Preferences.get(PREF_RESULT_PROMPT, "==>") }
-
private static final String IMPORT_SPACE = "import "
private static final String IMPORT_STATIC_SPACE = "import static "
private static final String ELLIPSIS = "..."
@@ -136,25 +79,11 @@ class Console {
if (!io.quiet) {
io.out.println()
- io.out.println(" " + ansiRender(gremlinColor, "\\,,,/"))
- io.out.println(" " + ansiRender(gremlinColor, "(o o)"))
- io.out.println("" + ansiRender(gremlinColor, "-----oOOo-(3)-oOOo-----"))
+ io.out.println(" " + Colorizer.render(Preferences.gremlinColor, "\\,,,/"))
+ io.out.println(" " + Colorizer.render(Preferences.gremlinColor, "(o o)"))
+ io.out.println("" + Colorizer.render(Preferences.gremlinColor, "-----oOOo-(3)-oOOo-----"))
}
- maxIteration = Preferences.get(PREFERENCE_ITERATION_MAX, DEFAULT_ITERATION_MAX.toString()).toInteger()
- Preferences.addChangeListener(new PreferenceChangeListener() {
- @Override
- void preferenceChange(PreferenceChangeEvent evt) {
- if (evt.key == PREFERENCE_ITERATION_MAX && null != evt.newValue)
- try {
- maxIteration = Integer.parseInt(evt.newValue)
- } catch (NumberFormatException e) {
- io.out.println(ansiRender(errorColor,"Unable to convert '${evt.newValue}' to integer. Using default ${DEFAULT_ITERATION_MAX}"))
- maxIteration = DEFAULT_ITERATION_MAX
- }
- }
- })
-
final Mediator mediator = new Mediator(this)
// make sure that remotes are closed if console takes a ctrl-c
@@ -187,7 +116,7 @@ class Console {
groovy.setHistory(history)
runner.setHistory(history)
} catch (IOException ignored) {
- io.err.println(ansiRender(errorColor, "Unable to create history file: " + ConsoleFs.HISTORY_FILE))
+ io.err.println(Colorizer.render(Preferences.errorColor, "Unable to create history file: " + ConsoleFs.HISTORY_FILE))
}
GremlinLoader.load()
@@ -203,7 +132,7 @@ class Console {
pluggedIn.activate()
if (!io.quiet)
- io.out.println(ansiRender(infoColor, "plugin activated: " + plugin.getName()))
+ io.out.println(Colorizer.render(Preferences.infoColor, "plugin activated: " + plugin.getName()))
}
}
}
@@ -238,7 +167,7 @@ class Console {
groovy.setResultHook(handleResultShowNothing)
}
- private def handlePrompt = { interactive ? ansiRender(inputPromptColor, inputPrompt.call() + " ") : "" }
+ private def handlePrompt = { interactive ? Colorizer.render(Preferences.inputPromptColor, Preferences.inputPrompt + " ") : "" }
private def handleResultShowNothing = { args -> null }
@@ -253,15 +182,15 @@ class Console {
while (true) {
if (this.tempIterator.hasNext()) {
int counter = 0;
- while (this.tempIterator.hasNext() && (maxIteration == -1 || counter < maxIteration)) {
+ while (this.tempIterator.hasNext() && (Preferences.maxIteration == -1 || counter < Preferences.maxIteration)) {
final Object object = this.tempIterator.next()
- String prompt = ansiRender(resultPromptColor, buildResultPrompt())
+ String prompt = Colorizer.render(Preferences.resultPromptColor, buildResultPrompt())
String colorizedResult = colorizeResult(object)
- io.out.println(prompt + ((null == object) ? emptyResult.call() : colorizedResult))
+ io.out.println(prompt + ((null == object) ? emptyResult : colorizedResult))
counter++;
}
if (this.tempIterator.hasNext())
- io.out.println(ansiRender(resultPromptColor,ELLIPSIS));
+ io.out.println(Colorizer.render(Preferences.resultPromptColor,ELLIPSIS));
this.tempIterator = Collections.emptyIterator();
return null
} else {
@@ -302,10 +231,10 @@ class Console {
}
} else if (result instanceof TraversalExplanation) {
final int width = TerminalFactory.get().getWidth();
- io.out.println(ansiRender(resultPromptColor,(buildResultPrompt() + result.prettyPrint(width < 20 ? 80 : width))))
+ io.out.println(Colorizer.render(Preferences.resultPromptColor,(buildResultPrompt() + result.prettyPrint(width < 20 ? 80 : width))))
return null
} else {
- io.out.println(ansiRender(resultPromptColor,buildResultPrompt()).toString() + ((null == result) ? emptyResult.call() : colorizeResult(result)))
+ io.out.println(Colorizer.render(Preferences.resultPromptColor,buildResultPrompt()).toString() + ((null == result) ? emptyResult : colorizeResult(result)))
return null
}
} catch (final Exception e) {
@@ -318,9 +247,9 @@ class Console {
def colorizeResult = { object ->
if (object instanceof Vertex) {
- return ansiRender(vertexColor, object.toString())
+ return Colorizer.render(Preferences.vertexColor, object.toString())
} else if (object instanceof Edge) {
- return ansiRender(edgeColor, object.toString())
+ return Colorizer.render(Preferences.edgeColor, object.toString())
} else if (object instanceof Iterable) {
List<String> buf = new ArrayList<>();
def pathIter = object.iterator()
@@ -336,11 +265,11 @@ class Console {
}
return ("[" + buf.join(",") + "]")
} else if (object instanceof String) {
- return ansiRender(stringColor, object)
+ return Colorizer.render(Preferences.stringColor, object)
} else if (object instanceof Number) {
- return ansiRender(numberColor, object)
+ return Colorizer.render(Preferences.numberColor, object)
} else if (object instanceof T) {
- return ansiRender(tColor, object)
+ return Colorizer.render(Preferences.tColor, object)
} else {
return object.toString()
}
@@ -354,14 +283,14 @@ class Console {
String message = e.getMessage()
if (null != message) {
message = message.replace("startup failed:", "")
- io.err.println(ansiRender(errorColor, message.trim()))
+ io.err.println(Colorizer.render(Preferences.errorColor, message.trim()))
} else {
- io.err.println(ansiRender(errorColor,e))
+ io.err.println(Colorizer.render(Preferences.errorColor,e))
}
if (interactive) {
- io.err.println(ansiRender(infoColor,"Type ':help' or ':h' for help."))
- io.err.print(ansiRender(errorColor, "Display stack trace? [yN]"))
+ io.err.println(Colorizer.render(Preferences.infoColor,"Type ':help' or ':h' for help."))
+ io.err.print(Colorizer.render(Preferences.errorColor, "Display stack trace? [yN]"))
io.err.flush()
String line = new BufferedReader(io.in).readLine()
if (null == line)
@@ -376,11 +305,11 @@ class Console {
System.exit(1)
}
} catch (Exception ignored) {
- io.err.println(ansiRender(errorColor, "An undefined error has occurred: " + err))
+ io.err.println(Colorizer.render(Preferences.errorColor, "An undefined error has occurred: " + err))
if (!interactive) System.exit(1)
}
} else {
- io.err.println(ansiRender(errorColor, "An undefined error has occurred: " + err.toString()))
+ io.err.println(Colorizer.render(Preferences.errorColor, "An undefined error has occurred: " + err.toString()))
if (!interactive) System.exit(1)
}
@@ -396,7 +325,7 @@ class Console {
if (groovyshellEnv != null)
return groovyshellEnv
- return resultPrompt.call()
+ return Preferences.resultPrompt
}
private void executeInShell(final List<String> scriptAndArgs) {
@@ -418,7 +347,7 @@ class Console {
lineNumber++
groovy.execute(line)
} catch (Exception ex) {
- io.err.println(ansiRender(errorColor, "Error in $scriptFile at [$lineNumber: $line] - ${ex.message}"))
+ io.err.println(Colorizer.render(Preferences.errorColor, "Error in $scriptFile at [$lineNumber: $line] - ${ex.message}"))
if (interactive)
break
else {
@@ -431,20 +360,17 @@ class Console {
if (!interactive) System.exit(0)
} catch (FileNotFoundException ignored) {
- io.err.println(ansiRender(errorColor, "Gremlin file not found at [$scriptFile]."))
+ io.err.println(Colorizer.render(Preferences.errorColor, "Gremlin file not found at [$scriptFile]."))
if (!interactive) System.exit(1)
} catch (Exception ex) {
- io.err.println(ansiRender(errorColor, "Failure processing Gremlin script [$scriptFile] - ${ex.message}"))
+ io.err.println(Colorizer.render(Preferences.errorColor, "Failure processing Gremlin script [$scriptFile] - ${ex.message}"))
if (!interactive) System.exit(1)
}
}
- def ansiRender = { color, text -> Ansi.ansi().render(String.format("@|%s %s|@", color.call(), text)).toString() }
-
public static void main(final String[] args) {
-// ExpandoMetaClass.enableGlobally()
- org.apache.tinkerpop.gremlin.console.Preferences.expandoMagic()
+ Preferences.expandoMagic()
// need to do some up front processing to try to support "bin/gremlin.sh init.groovy" until this deprecated
// feature can be removed. ultimately this should be removed when a breaking change can go in
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/34dc8e40/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Preferences.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Preferences.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Preferences.groovy
index 699d602..6cc7664 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Preferences.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Preferences.groovy
@@ -16,18 +16,82 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.tinkerpop.gremlin.console;
import java.util.prefs.PreferenceChangeEvent
import java.util.prefs.PreferenceChangeListener
+import org.codehaus.groovy.tools.shell.Groovysh
import org.codehaus.groovy.tools.shell.IO
public class Preferences {
private static final java.util.prefs.Preferences STORE = java.util.prefs.Preferences.userRoot().node("/org/apache/tinkerpop/gremlin/console");
+ public static final String PREFERENCE_ITERATION_MAX = "max-iteration"
+ private static final int DEFAULT_ITERATION_MAX = 100
+ public static int maxIteration = DEFAULT_ITERATION_MAX
+
+ public static final String PREF_GREMLIN_COLOR = "gremlin.color"
+ public static final String PREF_GREMLIN_COLOR_DEFAULT = "reset"
+ public static String gremlinColor = PREF_GREMLIN_COLOR_DEFAULT
+
+ public static final String PREF_VERTEX_COLOR = "vertex.color"
+ public static final String PREF_VERTEX_COLOR_DEFAULT = "reset"
+ public static String vertexColor = PREF_VERTEX_COLOR_DEFAULT
+
+ public static final String PREF_EDGE_COLOR = "edge.color"
+ public static final String PREF_EDGE_COLOR_DEFAULT = "reset"
+ public static String edgeColor = PREF_EDGE_COLOR_DEFAULT
+
+ public static final String PREF_ERROR_COLOR = "error.color"
+ public static final String PREF_ERROR_COLOR_DEFAULT = "reset"
+ public static String errorColor = PREF_ERROR_COLOR_DEFAULT
+
+ public static final String PREF_INFO_COLOR = "info.color"
+ public static final String PREF_INFO_COLOR_DEFAULT = "reset"
+ public static String infoColor = PREF_INFO_COLOR_DEFAULT
+
+ public static final String PREF_STRING_COLOR = "string.color"
+ public static final String PREF_STRING_COLOR_DEFAULT = "reset"
+ public static String stringColor = PREF_STRING_COLOR_DEFAULT
+
+ public static final String PREF_NUMBER_COLOR = "number.color"
+ public static final String PREF_NUMBER_COLOR_DEFAULT = "reset"
+ public static String numberColor = PREF_NUMBER_COLOR_DEFAULT
+
+ public static final String PREF_T_COLOR = "T.color"
+ public static final String PREF_T_COLOR_DEFAULT = "reset"
+ public static String tColor = PREF_T_COLOR_DEFAULT
+
+ public static final String PREF_INPUT_PROMPT_COLOR = "input.prompt.color"
+ public static final String PREF_INPUT_PROMPT_COLOR_DEFAULT = "reset"
+ public static String inputPromptColor = PREF_INPUT_PROMPT_COLOR_DEFAULT
+
+ public static final String PREF_RESULT_PROMPT_COLOR = "result.prompt.color"
+ public static final String PREF_RESULT_PROMPT_COLOR_DEFAULT = "reset"
+ public static String resultPromptColor = PREF_RESULT_PROMPT_COLOR_DEFAULT
+
+ public static final String PREF_EMPTY_RESULT_IND = "empty.result.indicator"
+ public static final String PREF_EMPTY_RESULT_IND_DEFAULT = "null"
+ public static String emptyResult = PREF_EMPTY_RESULT_IND_DEFAULT
+
+ public static final String PREF_INPUT_PROMPT = "input.prompt"
+ public static final String PREF_INPUT_PROMPT_DEFAULT = "gremlin>"
+ public static String inputPrompt = PREF_INPUT_PROMPT_DEFAULT
+
+ public static final String PREF_RESULT_PROMPT = "result.prompt"
+ public static final String PREF_RESULT_PROMPT_DEFAULT = "==>"
+ public static String resultPrompt = PREF_RESULT_PROMPT_DEFAULT
+
+ public static final String PREF_COLORS = Groovysh.COLORS_PREFERENCE_KEY
+ public static final Boolean PREF_COLORS_DEFAULT = true;
+ public static boolean colors = PREF_COLORS_DEFAULT
+
public static void expandoMagic() {
+
+ // Override all GroovySH Preference methods
org.codehaus.groovy.tools.shell.util.Preferences.getMetaClass().'static'.getShowLastResult = {
return STORE.getBoolean(org.codehaus.groovy.tools.shell.util.Preferences.SHOW_LAST_RESULT_KEY, true);
}
@@ -98,5 +162,161 @@ public class Preferences {
}
}
});
+
+ // Gremlin Handlers
+
+ // Initial Load
+ loadDefaultValues()
+
+ // Listeners
+ installPropertyListeners()
+ }
+
+ private static installPropertyListeners() {
+ org.codehaus.groovy.tools.shell.util.Preferences.addChangeListener(new PreferenceChangeListener() {
+ @Override
+ void preferenceChange(PreferenceChangeEvent evt) {
+ if (evt.key == PREFERENCE_ITERATION_MAX && null != evt.newValue) {
+ try {
+ maxIteration = Integer.parseInt(evt.newValue)
+ } catch (NumberFormatException e) {
+ println(Colorizer.render(errorColor,"Unable to convert '${evt.newValue}' to integer. Using default ${DEFAULT_ITERATION_MAX}"))
+ maxIteration = DEFAULT_ITERATION_MAX
+ }
+ } else if (evt.key == PREFERENCE_ITERATION_MAX){
+ maxIteration = DEFAULT_ITERATION_MAX
+ }
+ }
+ })
+
+ org.codehaus.groovy.tools.shell.util.Preferences.addChangeListener(new PreferenceChangeListener() {
+ @Override
+ void preferenceChange(PreferenceChangeEvent evt) {
+ if (evt.key == PREF_GREMLIN_COLOR) {
+ if (null == evt.newValue) {
+ gremlinColor = STORE.get(PREF_GREMLIN_COLOR, PREF_GREMLIN_COLOR_DEFAULT)
+ } else {
+ gremlinColor = evt.newValue
+ }
+ } else if (evt.key == PREF_VERTEX_COLOR) {
+ if (null == evt.newValue) {
+ vertexColor = STORE.get(PREF_VERTEX_COLOR, PREF_VERTEX_COLOR_DEFAULT)
+ } else {
+ vertexColor = evt.newValue
+ }
+ } else if (evt.key == PREF_EDGE_COLOR) {
+ if (null == evt.newValue) {
+ edgeColor = STORE.get(PREF_EDGE_COLOR, PREF_EDGE_COLOR_DEFAULT)
+ } else {
+ edgeColor = evt.newValue
+ }
+ } else if (evt.key == PREF_ERROR_COLOR) {
+ if (null == evt.newValue) {
+ errorColor = STORE.get(PREF_ERROR_COLOR, PREF_ERROR_COLOR_DEFAULT)
+ } else {
+ errorColor = evt.newValue
+ }
+ } else if (evt.key == PREF_INFO_COLOR) {
+ if (null == evt.newValue) {
+ infoColor = STORE.get(PREF_INFO_COLOR, PREF_INFO_COLOR_DEFAULT)
+ } else {
+ infoColor = evt.newValue
+ }
+ } else if (evt.key == PREF_STRING_COLOR) {
+ if (null == evt.newValue) {
+ stringColor = STORE.get(PREF_STRING_COLOR, PREF_STRING_COLOR_DEFAULT)
+ } else {
+ stringColor = evt.newValue
+ }
+ } else if (evt.key == PREF_NUMBER_COLOR) {
+ if (null == evt.newValue) {
+ numberColor = STORE.get(PREF_NUMBER_COLOR, PREF_NUMBER_COLOR_DEFAULT)
+ } else {
+ numberColor = evt.newValue
+ }
+ } else if (evt.key == PREF_T_COLOR) {
+ if (null == evt.newValue) {
+ tColor = STORE.get(PREF_T_COLOR, PREF_T_COLOR_DEFAULT)
+ } else {
+ tColor = evt.newValue
+ }
+ } else if (evt.key == PREF_INPUT_PROMPT_COLOR) {
+ if (null == evt.newValue) {
+ inputPromptColor = STORE.get(PREF_INPUT_PROMPT_COLOR, PREF_INPUT_PROMPT_COLOR_DEFAULT)
+ } else {
+ inputPromptColor = evt.newValue
+ }
+ } else if (evt.key == PREF_RESULT_PROMPT_COLOR) {
+ if (null == evt.newValue) {
+ resultPromptColor = STORE.get(PREF_RESULT_PROMPT_COLOR, PREF_RESULT_PROMPT_COLOR_DEFAULT)
+ } else {
+ resultPromptColor = evt.newValue
+ }
+ } else if (evt.key == PREF_EMPTY_RESULT_IND) {
+ if (null == evt.newValue) {
+ emptyResult = STORE.get(PREF_EMPTY_RESULT_IND, PREF_EMPTY_RESULT_IND_DEFAULT)
+ } else {
+ emptyResult = evt.newValue
+ }
+ } else if (evt.key == PREF_INPUT_PROMPT) {
+ if (null == evt.newValue) {
+ inputPrompt = STORE.get(PREF_INPUT_PROMPT, PREF_INPUT_PROMPT_DEFAULT)
+ } else {
+ inputPrompt = evt.newValue
+ }
+ } else if (evt.key == PREF_RESULT_PROMPT) {
+ if (null == evt.newValue) {
+ resultPrompt = STORE.get(PREF_RESULT_PROMPT, PREF_RESULT_PROMPT_DEFAULT)
+ } else {
+ resultPrompt = evt.newValue
+ }
+ } else if (evt.key == PREF_COLORS) {
+ if (null == evt.newValue) {
+ colors = Boolean.valueOf(STORE.get(PREF_COLORS, PREF_COLORS_DEFAULT.toString()))
+ } else {
+ colors = Boolean.valueOf(evt.newValue)
+ }
+ }
+ }
+ })
+
+ }
+
+ private static loadDefaultValues() {
+ try {
+ maxIteration = STORE.get(PREFERENCE_ITERATION_MAX, DEFAULT_ITERATION_MAX.toString()).toInteger()
+ }catch (NumberFormatException e) {
+ String maxIterationString = STORE.get(PREFERENCE_ITERATION_MAX, DEFAULT_ITERATION_MAX.toString())
+ println(Colorizer.render(Preferences.errorColor,"Unable to convert '${maxIterationString}' to integer. Using default ${DEFAULT_ITERATION_MAX}"))
+ maxIteration = DEFAULT_ITERATION_MAX
+ }
+
+ gremlinColor = STORE.get(PREF_GREMLIN_COLOR, PREF_GREMLIN_COLOR_DEFAULT)
+
+ vertexColor = STORE.get(PREF_VERTEX_COLOR, PREF_VERTEX_COLOR_DEFAULT)
+
+ edgeColor = STORE.get(PREF_EDGE_COLOR, PREF_EDGE_COLOR_DEFAULT)
+
+ errorColor = STORE.get(PREF_ERROR_COLOR, PREF_ERROR_COLOR_DEFAULT)
+
+ infoColor = STORE.get(PREF_INFO_COLOR, PREF_INFO_COLOR_DEFAULT)
+
+ stringColor = STORE.get(PREF_STRING_COLOR, PREF_STRING_COLOR_DEFAULT)
+
+ numberColor = STORE.get(PREF_NUMBER_COLOR, PREF_NUMBER_COLOR_DEFAULT)
+
+ tColor = STORE.get(PREF_T_COLOR, PREF_T_COLOR_DEFAULT)
+
+ inputPromptColor = STORE.get(PREF_INPUT_PROMPT_COLOR, PREF_INPUT_PROMPT_COLOR_DEFAULT)
+
+ resultPromptColor = STORE.get(PREF_RESULT_PROMPT_COLOR, PREF_RESULT_PROMPT_COLOR_DEFAULT)
+
+ emptyResult = STORE.get(PREF_EMPTY_RESULT_IND, PREF_EMPTY_RESULT_IND_DEFAULT)
+
+ inputPrompt = STORE.get(PREF_INPUT_PROMPT, PREF_INPUT_PROMPT_DEFAULT)
+
+ resultPrompt = STORE.get(PREF_RESULT_PROMPT, PREF_RESULT_PROMPT_DEFAULT)
+
+ colors = Boolean.valueOf(STORE.get(PREF_COLORS, PREF_COLORS_DEFAULT.toString()))
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/34dc8e40/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy
index 297737c..4078374 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy
@@ -18,8 +18,8 @@
*/
package org.apache.tinkerpop.gremlin.console.commands
-import org.apache.tinkerpop.gremlin.console.Console
import jline.console.completer.Completer
+
import org.codehaus.groovy.tools.shell.Groovysh
import org.codehaus.groovy.tools.shell.commands.SetCommand
import org.codehaus.groovy.tools.shell.util.PackageHelper
@@ -60,24 +60,27 @@ class GremlinSetCommand extends SetCommand {
set << PackageHelper.IMPORT_COMPLETION_PREFERENCE_KEY
// add Gremlin Console specific preferences here
- set << Console.PREFERENCE_ITERATION_MAX
- set << Console.PREF_GREMLIN_COLOR
- set << Console.PREF_ERROR_COLOR
- set << Console.PREF_INFO_COLOR
- set << Console.PREF_INPUT_PROMPT_COLOR
- set << Console.PREF_RESULT_PROMPT_COLOR
- set << Console.PREF_EMPTY_RESULT_IND
- set << Console.PREF_INPUT_PROMPT
- set << Console.PREF_RESULT_PROMPT
- set << Console.PREF_EDGE_COLOR
- set << Console.PREF_VERTEX_COLOR
- set << Console.PREF_STRING_COLOR
- set << Console.PREF_NUMBER_COLOR
- set << Console.PREF_T_COLOR
-
+ set << org.apache.tinkerpop.gremlin.console.Preferences.PREFERENCE_ITERATION_MAX
+ set << org.apache.tinkerpop.gremlin.console.Preferences.PREF_GREMLIN_COLOR
+ set << org.apache.tinkerpop.gremlin.console.Preferences.PREF_ERROR_COLOR
+ set << org.apache.tinkerpop.gremlin.console.Preferences.PREF_INFO_COLOR
+ set << org.apache.tinkerpop.gremlin.console.Preferences.PREF_INPUT_PROMPT_COLOR
+ set << org.apache.tinkerpop.gremlin.console.Preferences.PREF_RESULT_PROMPT_COLOR
+ set << org.apache.tinkerpop.gremlin.console.Preferences.PREF_EMPTY_RESULT_IND
+ set << org.apache.tinkerpop.gremlin.console.Preferences.PREF_INPUT_PROMPT
+ set << org.apache.tinkerpop.gremlin.console.Preferences.PREF_RESULT_PROMPT
+ set << org.apache.tinkerpop.gremlin.console.Preferences.PREF_EDGE_COLOR
+ set << org.apache.tinkerpop.gremlin.console.Preferences.PREF_VERTEX_COLOR
+ set << org.apache.tinkerpop.gremlin.console.Preferences.PREF_STRING_COLOR
+ set << org.apache.tinkerpop.gremlin.console.Preferences.PREF_NUMBER_COLOR
+ set << org.apache.tinkerpop.gremlin.console.Preferences.PREF_T_COLOR
+
return set.toList()
}
- return [new SimpleCompletor(loader),null]
+ return [
+ new SimpleCompletor(loader),
+ null
+ ]
}
}
[15/18] tinkerpop git commit: updated doc with colors preference
Posted by sp...@apache.org.
updated doc with colors preference
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/6f1ed6f5
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/6f1ed6f5
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/6f1ed6f5
Branch: refs/heads/master
Commit: 6f1ed6f524aa8d7310f45efd41fc467cf2c69310
Parents: 34dc8e4
Author: Robert Dale <ro...@gmail.com>
Authored: Mon Aug 22 11:40:04 2016 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Mon Aug 22 11:40:04 2016 -0400
----------------------------------------------------------------------
docs/src/reference/gremlin-applications.asciidoc | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6f1ed6f5/docs/src/reference/gremlin-applications.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-applications.asciidoc b/docs/src/reference/gremlin-applications.asciidoc
index 7074fb9..32834a6 100644
--- a/docs/src/reference/gremlin-applications.asciidoc
+++ b/docs/src/reference/gremlin-applications.asciidoc
@@ -153,12 +153,13 @@ some other useful operations. The following table outlines the most commonly us
Console Preferences
~~~~~~~~~~~~~~~~~~~
-Preferences are set with `:set name value`. Values can contain spaces when quoted. Preferences are removed by `:purge preferences`
+Preferences are set with `:set name value`. Values can contain spaces when quoted. All preferences are reset by `:purge preferences`
[width="100%",cols="3,^2,10",options="header"]
|=========================================================
|Preference |Type |Description
|max-iteration | int | Controls the maximum number of results that the Console will display. Default: 100 results.
+|colors | bool | Enable ANSI color rendering. Default: true
|gremlin.color | colors | Color of the ASCII art gremlin on startup.
|info.color | colors | Color of "info" type messages.
|error.color | colors | Color of "error" type messages.
[16/18] tinkerpop git commit: bug fix
Posted by sp...@apache.org.
bug fix
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/7e70540e
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/7e70540e
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/7e70540e
Branch: refs/heads/master
Commit: 7e70540e2a15f0f017bd244066925dc96166a6df
Parents: 6f1ed6f
Author: Robert Dale <ro...@gmail.com>
Authored: Mon Aug 22 18:24:10 2016 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Mon Aug 22 18:24:10 2016 -0400
----------------------------------------------------------------------
.../groovy/org/apache/tinkerpop/gremlin/console/Colorizer.groovy | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7e70540e/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Colorizer.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Colorizer.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Colorizer.groovy
index 908d0ff..0fee402 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Colorizer.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Colorizer.groovy
@@ -35,7 +35,7 @@ public class Colorizer {
Ansi.enabled = true
}
- public static String render(String color, String text) {
+ public static String render(String color, Object text) {
if (Ansi.isEnabled() && Preferences.colors) {
Ansi.ansi().render(String.format("@|%s %s|@", color, text)).toString()
} else {
[06/18] tinkerpop git commit: added colorizing string, number, and T
Posted by sp...@apache.org.
added colorizing string, number, and T
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/a443d6ad
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/a443d6ad
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/a443d6ad
Branch: refs/heads/master
Commit: a443d6adb8f076a54e2c7be30d97e9f54b206f87
Parents: 8b58d9b
Author: Robert Dale <ro...@gmail.com>
Authored: Fri Aug 19 13:15:18 2016 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Fri Aug 19 14:46:20 2016 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 2 +
.../upgrade/release-3.2.x-incubating.asciidoc | 22 ++++++
.../tinkerpop/gremlin/console/Console.groovy | 79 +++++++++++++-------
.../console/commands/GremlinSetCommand.groovy | 5 +-
4 files changed, 78 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a443d6ad/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 1b93ecd..805cf65 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -37,6 +37,8 @@ TinkerPop 3.2.2 (NOT OFFICIALLY RELEASED YET)
* Fixed a severe bug in `SubgraphStrategy`.
* Deprecated `SubgraphStrategy.Builder.vertexCriterion()/edgeCriterion()` in favor of `vertices()/edges()`.
* Fixed a small bug in `StandardVerificationStrategy` that caused verification to fail when `withPath` was used in conjunction with `ProfileStep`.
+* Added color preferences
+* Added input, result prompt preferences
[[release-3-2-1]]
TinkerPop 3.2.1 (Release Date: July 18, 2016)
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a443d6ad/docs/src/upgrade/release-3.2.x-incubating.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/upgrade/release-3.2.x-incubating.asciidoc b/docs/src/upgrade/release-3.2.x-incubating.asciidoc
index bdcf69e..456f52d 100644
--- a/docs/src/upgrade/release-3.2.x-incubating.asciidoc
+++ b/docs/src/upgrade/release-3.2.x-incubating.asciidoc
@@ -54,6 +54,28 @@ and overridden as needed.
See: https://issues.apache.org/jira/browse/TINKERPOP-1373[TINKERPOP-1373]
+New Console Preferences
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Colors
+
+* gremlin.color
+* info.color
+* error.color
+* input.prompt.color
+* result.prompt.color
+* vertex.color
+* edge.color
+* string.color
+* number.color
+* T.color (e.g. id, label)
+
+Prompts
+
+* input.prompt
+* result.prompt
+* empty.result.indicator
+
Upgrading for Providers
~~~~~~~~~~~~~~~~~~~~~~~
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a443d6ad/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
index 841d670..e79800e 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
@@ -36,9 +36,9 @@ import org.apache.tinkerpop.gremlin.console.commands.UninstallCommand
import org.apache.tinkerpop.gremlin.console.plugin.PluggedIn
import org.apache.tinkerpop.gremlin.groovy.loaders.GremlinLoader
import org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin
-import org.apache.tinkerpop.gremlin.process.traversal.Path
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalExplanation
import org.apache.tinkerpop.gremlin.structure.Edge
+import org.apache.tinkerpop.gremlin.structure.T
import org.apache.tinkerpop.gremlin.structure.Vertex
import org.apache.tinkerpop.gremlin.util.Gremlin
import org.apache.tinkerpop.gremlin.util.iterator.ArrayIterator
@@ -66,7 +66,7 @@ class Console {
AnsiConsole.systemInstall()
// Register jline ansi detector
Ansi.setDetector(new AnsiDetector())
- Ansi.enabled = true
+ Ansi.enabled = false
}
public static final String PREFERENCE_ITERATION_MAX = "max-iteration"
@@ -74,25 +74,34 @@ class Console {
private static int maxIteration = DEFAULT_ITERATION_MAX
public static final String PREF_GREMLIN_COLOR = "gremlin.color"
- def gremlinColor = { Preferences.get(PREF_GREMLIN_COLOR, "green") }
+ def gremlinColor = { Preferences.get(PREF_GREMLIN_COLOR, "reset") }
public static final String PREF_VERTEX_COLOR = "vertex.color"
- def vertexColor = { Preferences.get(PREF_GREMLIN_COLOR, "green") }
+ def vertexColor = { Preferences.get(PREF_GREMLIN_COLOR, "reset") }
public static final String PREF_EDGE_COLOR = "edge.color"
- def edgeColor = { Preferences.get(PREF_GREMLIN_COLOR, "bg_blue,bold") }
+ def edgeColor = { Preferences.get(PREF_GREMLIN_COLOR, "reset") }
public static final String PREF_ERROR_COLOR = "error.color"
- def errorColor = { Preferences.get(PREF_ERROR_COLOR, "bold,red") }
+ def errorColor = { Preferences.get(PREF_ERROR_COLOR, "reset") }
public static final String PREF_INFO_COLOR = "info.color"
def infoColor = { Preferences.get(PREF_INFO_COLOR, "reset") }
+ public static final String PREF_STRING_COLOR = "string.color"
+ def stringColor = { Preferences.get(PREF_STRING_COLOR, "reset") }
+
+ public static final String PREF_NUMBER_COLOR = "number.color"
+ def numberColor = { Preferences.get(PREF_NUMBER_COLOR, "reset") }
+
+ public static final String PREF_T_COLOR = "T.color"
+ def tColor = { Preferences.get(PREF_T_COLOR, "reset") }
+
public static final String PREF_INPUT_PROMPT_COLOR = "input.prompt.color"
- def inputPromptColor = { Preferences.get(PREF_INPUT_PROMPT_COLOR, "white") }
+ def inputPromptColor = { Preferences.get(PREF_INPUT_PROMPT_COLOR, "reset") }
public static final String PREF_RESULT_PROMPT_COLOR = "result.prompt.color"
- def resultPromptColor = { Preferences.get(PREF_RESULT_PROMPT_COLOR, "white") }
+ def resultPromptColor = { Preferences.get(PREF_RESULT_PROMPT_COLOR, "reset") }
public static final String PREF_EMPTY_RESULT_COLOR = "empty.result.indicator"
def emptyResult = { Preferences.get(PREF_EMPTY_RESULT_COLOR, "null") }
@@ -242,26 +251,8 @@ class Console {
while (this.tempIterator.hasNext() && (maxIteration == -1 || counter < maxIteration)) {
final Object object = this.tempIterator.next()
String prompt = ansiRender(resultPromptColor, buildResultPrompt())
- if (object instanceof Vertex) {
- io.out.println(prompt + ansiRender(vertexColor, object.toString()))
- } else if (object instanceof Edge) {
- io.out.println(prompt + ansiRender(edgeColor, object.toString()))
- } else if (object instanceof Path) {
- List<String> buf = new ArrayList<>();
- Path path = (Path) object
- def pathIter = path.iterator()
- while (pathIter.hasNext()) {
- object = pathIter.next()
- if (object instanceof Vertex) {
- buf.add(ansiRender(vertexColor, object.toString()))
- } else if (object instanceof Edge) {
- buf.add(ansiRender(edgeColor, object.toString()))
- }
- }
- io.out.println(prompt + "[" + buf.join(",") + "]")
- } else {
- io.out.println(ansiRender(resultPromptColor, (buildResultPrompt() + ((null == object) ? emptyResult.doCall() : object.toString()))))
- }
+ String colorizedResult = colorizeResult(object)
+ io.out.println(prompt + ((null == object) ? emptyResult.call() : colorizedResult))
counter++;
}
if (this.tempIterator.hasNext())
@@ -319,6 +310,36 @@ class Console {
}
}
}
+
+ def colorizeResult = { object ->
+ if (object instanceof Vertex) {
+ return ansiRender(vertexColor, object.toString())
+ } else if (object instanceof Edge) {
+ return ansiRender(edgeColor, object.toString())
+ } else if (object instanceof Iterable) {
+ List<String> buf = new ArrayList<>();
+ def pathIter = object.iterator()
+ while (pathIter.hasNext()) {
+ Object n = pathIter.next()
+ buf.add(colorizeResult(n))
+ }
+ return ("[" + buf.join(",") + "]")
+ } else if (object instanceof Map) {
+ List<String> buf = new ArrayList<>();
+ object.each{k, v ->
+ buf.add(colorizeResult(k) + ":" + colorizeResult(v))
+ }
+ return ("[" + buf.join(",") + "]")
+ } else if (object instanceof String) {
+ return ansiRender(stringColor, object)
+ } else if (object instanceof Number) {
+ return ansiRender(numberColor, object)
+ } else if (object instanceof T) {
+ return ansiRender(tColor, object)
+ } else {
+ return object.toString()
+ }
+ }
private def handleError = { err ->
this.tempIterator = Collections.emptyIterator();
@@ -413,7 +434,7 @@ class Console {
}
}
- def ansiRender = { color, text -> Ansi.ansi().render(String.format("@|%s %s|@", color.call(), text)) }
+ def ansiRender = { color, text -> Ansi.ansi().render(String.format("@|%s %s|@", color.call(), text)).toString() }
public static void main(final String[] args) {
// need to do some up front processing to try to support "bin/gremlin.sh init.groovy" until this deprecated
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a443d6ad/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy
index 53de643..3e7dcef 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/GremlinSetCommand.groovy
@@ -71,7 +71,10 @@ class GremlinSetCommand extends SetCommand {
set << Console.PREF_RESULT_PROMPT
set << Console.PREF_EDGE_COLOR
set << Console.PREF_VERTEX_COLOR
-
+ set << Console.PREF_STRING_COLOR
+ set << Console.PREF_NUMBER_COLOR
+ set << Console.PREF_T_COLOR
+
return set.toList()
}