Экранирование IOException при создании Shell
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
group = 'ru.dmitriymx'
|
||||
version = '2.0-SNAPSHOT'
|
||||
version = '2.1-SNAPSHOT'
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'idea'
|
||||
|
||||
@@ -30,14 +30,20 @@ public class Shell extends Thread implements Completer {
|
||||
private Map<String, Command> commandMap = new HashMap<>();
|
||||
private StringsCompleter stringsCompleter = new StringsCompleter();
|
||||
|
||||
public Shell() throws IOException {
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user