diff --git a/build.gradle b/build.gradle index f6581d9..e6c7579 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group = 'ru.dmitriymx' -version = '2.0-SNAPSHOT' +version = '2.1-SNAPSHOT' apply plugin: 'java' apply plugin: 'idea' diff --git a/src/main/java/ru/dmitriymx/shell/Shell.java b/src/main/java/ru/dmitriymx/shell/Shell.java index c764d9c..81f8f2d 100644 --- a/src/main/java/ru/dmitriymx/shell/Shell.java +++ b/src/main/java/ru/dmitriymx/shell/Shell.java @@ -30,14 +30,20 @@ public class Shell extends Thread implements Completer { private Map commandMap = new HashMap<>(); private StringsCompleter stringsCompleter = new StringsCompleter(); - public Shell() throws IOException { - console = new ConsoleReader(System.in, System.err); - console.addCompleter(this); - out = new PrintWriter(console.getOutput()); + public Shell() { + try { + console = new ConsoleReader(System.in, System.err); + console.addCompleter(this); + out = new PrintWriter(console.getOutput()); + } catch (IOException e) { + e.printStackTrace(System.err); + } } @Override public synchronized void start() { + if (out == null) return; + try { this.join(); } catch (InterruptedException e) { @@ -54,6 +60,8 @@ public class Shell extends Thread implements Completer { } public synchronized void shutdown() { + if (out == null) return; + out.print(ConsoleReader.RESET_LINE); out.flush(); @@ -110,6 +118,8 @@ public class Shell extends Thread implements Completer { } public void registerCommand(Command command) { + if (out == null) return; + if (command.getShell() == null) { command.setShell(this); }