Archived
0

Zond: несколько фиксов

This commit is contained in:
2017-06-14 17:39:48 +03:00
parent 52c5a73942
commit 349deaa837
5 changed files with 53 additions and 21 deletions

View File

@@ -1,5 +1,5 @@
group = 'asys' group = 'asys'
version = '0.6.10-SNAPSHOT' version = '0.6.11-SNAPSHOT'
apply plugin: 'application' apply plugin: 'application'

View File

@@ -57,8 +57,10 @@ public class Main {
Shell.getInstance().start(System.in, commandLine -> { Shell.getInstance().start(System.in, commandLine -> {
if (commandLine.equalsIgnoreCase(":exit")) { if (commandLine.equalsIgnoreCase(":exit")) {
Shell.getInstance().getOutput().println("force exit"); Shell.getInstance().getOutput().println("force exit");
watchdog.destroyProcess(); // watchdog.destroyProcess();
Shell.getInstance().shutdown(); Shell.getInstance().shutdown();
Main.shutdown();
return;
} }
pipeInputStream.write(commandLine+"\r\n"); pipeInputStream.write(commandLine+"\r\n");
}); });
@@ -66,17 +68,15 @@ public class Main {
Connector.getInstance().startReconnect(); Connector.getInstance().startReconnect();
int resultCode = executeProcess(args, Shell.getInstance().getOutput(), pipeInputStream); // int resultCode = executeProcess(args, Shell.getInstance().getOutput(), pipeInputStream);
Connector.getInstance().setNeedReconnect(false); // Shell.getInstance().shutdown();
Connector.getInstance().stopReconnect(); //
Connector.getInstance().disconnect(); //
// int resultCode = -2;
Shell.getInstance().shutdown(); // System.out.println(Ansi.ansi().reset().newline()
// .fg(Color.GREEN).a("Process Finished. Code: ")
System.out.println(Ansi.ansi().reset().newline() // .bold().fg(Color.WHITE).a(resultCode).reset());
.fg(Color.GREEN).a("Process Finished. Code: ")
.bold().fg(Color.WHITE).a(resultCode).reset());
} }
private static int executeProcess(String[] args, PrintStream printStream, InputStream stdin) throws IOException { private static int executeProcess(String[] args, PrintStream printStream, InputStream stdin) throws IOException {
@@ -120,4 +120,10 @@ public class Main {
Config.load(fis); Config.load(fis);
fis.close(); fis.close();
} }
private static void shutdown() {
Connector.getInstance().setNeedReconnect(false);
Connector.getInstance().stopReconnect();
Connector.getInstance().shutdown();
}
} }

View File

@@ -54,12 +54,10 @@ public class Connector {
} }
} }
public void disconnect() { public void shutdown() {
if (client.isConnected()) {
log("Disconnect..."); log("Disconnect...");
client.disconnect(); client.disconnect();
} }
}
public void setChannel(Channel channel) { public void setChannel(Channel channel) {
this.channel = channel; this.channel = channel;

View File

@@ -18,7 +18,16 @@ public class JlineProxySysOut extends PrintStream {
public void setConsoleReader(ConsoleReader consoleReader) { public void setConsoleReader(ConsoleReader consoleReader) {
this.consoleReader = consoleReader; this.consoleReader = consoleReader;
if (consoleReader != null) {
this.writer = new PrintWriter(consoleReader.getOutput()); this.writer = new PrintWriter(consoleReader.getOutput());
} else {
try {
super.out.write('\r');
super.out.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
} }
private void _print(String s) { private void _print(String s) {
@@ -47,12 +56,29 @@ public class JlineProxySysOut extends PrintStream {
@Override @Override
public void write(byte[] buf, int off, int len) { public void write(byte[] buf, int off, int len) {
if ((char)buf[len-1] == '\n') len--; //TODO проверить в windows if (consoleReader != null) {
if ((char) buf[len - 1] == '\n') len--; //TODO проверить в windows
_print(new String(buf, off, len)); _print(new String(buf, off, len));
} else {
super.write(buf, off, len);
}
}
@Override
public void print(String x) {
if (consoleReader != null) {
_print(x);
} else {
super.print(x);
}
} }
@Override @Override
public void println(String x) { public void println(String x) {
if (consoleReader != null) {
_print(x); _print(x);
} else {
super.println(x);
}
} }
} }

View File

@@ -5,6 +5,7 @@
package asys.zond.shell; package asys.zond.shell;
import jline.console.ConsoleReader; import jline.console.ConsoleReader;
import jline.internal.Ansi;
import java.io.*; import java.io.*;
@@ -48,6 +49,7 @@ public class Shell {
public void shutdown() { public void shutdown() {
threadCommandHandler.interrupt(); threadCommandHandler.interrupt();
active = false; active = false;
proxySysOut.setConsoleReader(null);
} }
public JlineProxySysOut getOutput() { public JlineProxySysOut getOutput() {