You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ch...@apache.org on 2007/12/07 03:59:47 UTC
svn commit: r601968 -
/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultShell.java
Author: chirino
Date: Thu Dec 6 18:59:45 2007
New Revision: 601968
URL: http://svn.apache.org/viewvc?rev=601968&view=rev
Log:
Allow the prompter to get injected or overriden.
Modified:
geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultShell.java
Modified: geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultShell.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultShell.java?rev=601968&r1=601967&r2=601968&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultShell.java (original)
+++ geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultShell.java Thu Dec 6 18:59:45 2007
@@ -33,6 +33,7 @@
import org.apache.geronimo.gshell.console.Console;
import org.apache.geronimo.gshell.console.JLineConsole;
import org.apache.geronimo.gshell.console.TerminalInfo;
+import org.apache.geronimo.gshell.console.Console.Prompter;
import org.apache.geronimo.gshell.shell.Environment;
import org.apache.geronimo.gshell.shell.InteractiveShell;
import org.apache.geronimo.gshell.shell.Shell;
@@ -77,6 +78,8 @@
@Requirement
private IO io;
+ private Prompter prompter;
+
public DefaultShell() {}
public DefaultShell(final ShellInfo shellInfo, final Branding branding, final CommandExecutor executor, final Terminal terminal, final Environment env, final IO io) {
@@ -167,21 +170,7 @@
JLineConsole console = new JLineConsole(executor, io, terminal);
// Setup the prompt
- console.setPrompter(new Console.Prompter() {
- Renderer renderer = new Renderer();
-
- public String prompt() {
- String userName = shellInfo.getUserName();
- String hostName = shellInfo.getLocalHost().getHostName();
-
- //
- // HACK: There is no path... yet ;-)
- //
- String path = "/";
-
- return renderer.render("@|bold " + userName + "|@" + hostName + ":@|bold " + path + "|> ");
- }
- });
+ console.setPrompter(getPrompter());
// Delegate errors for display and then continue
console.setErrorHandler(new Console.ErrorHandler() {
@@ -219,6 +208,39 @@
}
}
+ public Prompter getPrompter() {
+ if( prompter == null ) {
+ prompter = createPrompter();
+ }
+ return prompter;
+ }
+
+ public void setPrompter(Prompter prompter) {
+ this.prompter = prompter;
+ }
+
+ /**
+ * Allow subclasses to override the default Prompter implementation
+ * used.
+ * @return
+ */
+ protected Prompter createPrompter() {
+ return new Prompter() {
+ Renderer renderer = new Renderer();
+ public String prompt() {
+ String userName = shellInfo.getUserName();
+ String hostName = shellInfo.getLocalHost().getHostName();
+
+ //
+ // HACK: There is no path... yet ;-)
+ //
+ String path = "/";
+
+ return renderer.render("@|bold " + userName + "|@" + hostName + ":@|bold " + path + "|> ");
+ }
+ };
+ }
+
//
// Error Display
//
@@ -331,4 +353,5 @@
log.debug("Shared script is not present: {}", file);
}
}
+
}