You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2007/09/18 04:30:32 UTC
svn commit: r576667 -
/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java
Author: jdillon
Date: Mon Sep 17 19:30:32 2007
New Revision: 576667
URL: http://svn.apache.org/viewvc?rev=576667&view=rev
Log:
Hook up some preliminary console support on the client-side
Modified:
geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java
Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java?rev=576667&r1=576666&r2=576667&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java Mon Sep 17 19:30:32 2007
@@ -30,7 +30,12 @@
import org.apache.geronimo.gshell.command.CommandSupport;
import org.apache.geronimo.gshell.command.annotation.CommandComponent;
import org.apache.geronimo.gshell.clp.Argument;
+import org.apache.geronimo.gshell.console.Console;
+import org.apache.geronimo.gshell.console.JLineConsole;
+import org.apache.geronimo.gshell.ExitNotification;
+import org.apache.geronimo.gshell.ansi.Renderer;
import org.codehaus.plexus.component.annotations.Requirement;
+import jline.Terminal;
/**
* Command to connect to a remote shell server.
@@ -45,6 +50,9 @@
private URI location;
@Requirement
+ private Terminal terminal;
+
+ @Requirement
private RshClientFactory factory;
private RshClient client;
@@ -55,73 +63,45 @@
client = factory.connect(location);
io.out.println("Connected");
-
- client.echo("TESTING");
client.handshake();
- /*
- client.echo("READ_STREAMS");
+ Console.Executor executor = new Console.Executor() {
+ public Result execute(final String line) throws Exception {
+ assert line != null;
- OutputStream out = client.getOutputStream();
- final PrintWriter writer = new PrintWriter(out);
+ client.echo(line);
- InputStream in = client.getInputStream();
- final BufferedReader reader = new BufferedReader(new InputStreamReader(in));
-
- Thread t = new Thread("Stream Consumer") {
- public void run() {
- try {
- log.debug("Consumer running...");
-
- String line;
- while ((line = reader.readLine()) != null) {
- System.err.println(line);
- }
-
- log.debug("Consumer stopped");
- }
- catch (Exception e) {
- log.error(e.getMessage(), e);
- }
+ return Result.CONTINUE;
}
};
- t.start();
+ JLineConsole console = new JLineConsole(executor, io, terminal);
+
+ console.setPrompter(new Console.Prompter() {
+ Renderer renderer = new Renderer();
- Thread t2 = new Thread("Noise Maker") {
- public void run() {
- try {
- log.debug("Noise Maker...");
-
- while (true) {
- writer.println("FROM CLIENT: " + new Date());
- writer.flush();
-
- Thread.sleep(1000 * 5);
- }
-
- // log.debug("Noise Maker stopped");
- }
- catch (Exception e) {
- log.error(e.getMessage(), e);
- }
+ public String prompt() {
+ String userName = "user";
+ String hostName = "remote";
+ String path = "/";
+
+ return renderer.render("@|bold " + userName + "|@" + hostName + ":@|bold " + path + "|> ");
}
- };
+ });
- t2.start();
+ console.setErrorHandler(new Console.ErrorHandler() {
+ public Result handleError(final Throwable error) {
+ assert error != null;
- t.join();
- t2.join();
- */
+ log.error("Communication error: " + error, error);
- boolean running = true;
-
- while (running) {
- client.echo(new Date().toString());
- Thread.sleep(1000 * 5);
- }
+ return Result.CONTINUE;
+ }
+ });
+ console.run();
+
client.close();
return SUCCESS;