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:21 UTC
[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
- 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
+ ]
}
}