From a1c0df622b0205e38f63f7318cb0fe37dcfeee00 Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Sat, 12 Dec 2015 10:19:26 +0300 Subject: [PATCH] =?UTF-8?q?=D0=AD=D0=BA=D1=80=D0=B0=D0=BD=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20IOException=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B8?= =?UTF-8?q?=20Shell?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- src/main/java/ru/dmitriymx/shell/Shell.java | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) 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); }