Экранирование IOException при создании Shell
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
group = 'ru.dmitriymx'
|
group = 'ru.dmitriymx'
|
||||||
version = '2.0-SNAPSHOT'
|
version = '2.1-SNAPSHOT'
|
||||||
|
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: 'idea'
|
apply plugin: 'idea'
|
||||||
|
|||||||
@@ -30,14 +30,20 @@ public class Shell extends Thread implements Completer {
|
|||||||
private Map<String, Command> commandMap = new HashMap<>();
|
private Map<String, Command> commandMap = new HashMap<>();
|
||||||
private StringsCompleter stringsCompleter = new StringsCompleter();
|
private StringsCompleter stringsCompleter = new StringsCompleter();
|
||||||
|
|
||||||
public Shell() throws IOException {
|
public Shell() {
|
||||||
console = new ConsoleReader(System.in, System.err);
|
try {
|
||||||
console.addCompleter(this);
|
console = new ConsoleReader(System.in, System.err);
|
||||||
out = new PrintWriter(console.getOutput());
|
console.addCompleter(this);
|
||||||
|
out = new PrintWriter(console.getOutput());
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace(System.err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void start() {
|
public synchronized void start() {
|
||||||
|
if (out == null) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.join();
|
this.join();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
@@ -54,6 +60,8 @@ public class Shell extends Thread implements Completer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void shutdown() {
|
public synchronized void shutdown() {
|
||||||
|
if (out == null) return;
|
||||||
|
|
||||||
out.print(ConsoleReader.RESET_LINE);
|
out.print(ConsoleReader.RESET_LINE);
|
||||||
out.flush();
|
out.flush();
|
||||||
|
|
||||||
@@ -110,6 +118,8 @@ public class Shell extends Thread implements Completer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void registerCommand(Command command) {
|
public void registerCommand(Command command) {
|
||||||
|
if (out == null) return;
|
||||||
|
|
||||||
if (command.getShell() == null) {
|
if (command.getShell() == null) {
|
||||||
command.setShell(this);
|
command.setShell(this);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user