-
Notifications
You must be signed in to change notification settings - Fork 212
/
Example.java
648 lines (619 loc) · 31.6 KB
/
Example.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
/*
* Copyright (c) 2002-2019, the original author or authors.
*
* This software is distributable under the BSD license. See the terms of the
* BSD license in the documentation provided with this software.
*
* https://opensource.org/licenses/BSD-3-Clause
*/
package org.jline.example;
import static java.time.temporal.ChronoField.HOUR_OF_DAY;
import static java.time.temporal.ChronoField.MINUTE_OF_HOUR;
import static org.jline.builtins.Completers.TreeCompleter.node;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import org.jline.builtins.Builtins;
import org.jline.builtins.Builtins.Command;
import org.jline.builtins.CommandRegistry;
import org.jline.builtins.Completers;
import org.jline.builtins.Completers.SystemCompleter;
import org.jline.builtins.Completers.TreeCompleter;
import org.jline.builtins.Options.HelpException;
import org.jline.builtins.Widgets.ArgDesc;
import org.jline.builtins.Widgets.AutopairWidgets;
import org.jline.builtins.Widgets.AutosuggestionWidgets;
import org.jline.builtins.Widgets.CmdDesc;
import org.jline.builtins.Widgets.CmdLine;
import org.jline.builtins.Widgets.TailTipWidgets;
import org.jline.builtins.Widgets.TailTipWidgets.TipType;
import org.jline.keymap.KeyMap;
import org.jline.reader.*;
import org.jline.reader.LineReader.Option;
import org.jline.reader.LineReader.SuggestionType;
import org.jline.reader.impl.DefaultParser;
import org.jline.reader.impl.DefaultParser.Bracket;
import org.jline.reader.impl.LineReaderImpl;
import org.jline.reader.impl.completer.AggregateCompleter;
import org.jline.reader.impl.completer.ArgumentCompleter;
import org.jline.reader.impl.completer.StringsCompleter;
import org.jline.terminal.Cursor;
import org.jline.terminal.MouseEvent;
import org.jline.terminal.Terminal;
import org.jline.terminal.TerminalBuilder;
import org.jline.utils.AttributedString;
import org.jline.utils.AttributedStringBuilder;
import org.jline.utils.AttributedStyle;
import org.jline.utils.InfoCmp.Capability;
import org.jline.utils.Status;
public class Example
{
public static void usage() {
String[] usage = {
"Usage: java " + Example.class.getName() + " [cases... [trigger mask]]"
, " Terminal:"
, " -system terminalBuilder.system(false)"
, " +system terminalBuilder.system(true)"
, " Completors:"
, " aggregate an aggregate completor with strings Supplier"
, " argument an argument completor & autosuggestion"
, " files a completor that completes file names"
, " none no completors"
, " param a paramenter completer using Java functional interface"
, " regexp a regex completer"
, " simple a string completor that completes \"foo\", \"bar\" and \"baz\""
, " tree a tree completer"
, " Multiline:"
, " brackets eof on unclosed bracket"
, " quotes eof on unclosed quotes"
, " Mouse:"
, " mouse enable mouse"
, " mousetrack enable tracking mouse"
, " Miscellaneous:"
, " color colored left and right prompts"
, " status multi-thread test of jline status line"
, " timer widget 'Hello world'"
, " <trigger> <mask> password mask"
, " Example:"
, " java " + Example.class.getName() + " simple su '*'"};
for (String u: usage) {
System.out.println(u);
}
}
public static void help(CommandRegistry builtins) {
TreeSet<String> commands = new TreeSet<>(builtins.commandNames());
List<String> help = new ArrayList<String>(Arrays.asList(
"List of available commands:"
, " Builtin:"));
for (String c: commands) {
AttributedStringBuilder asb = new AttributedStringBuilder().tabs(Arrays.asList(4,20));
asb.append("\t");
asb.append(c);
asb.append("\t");
asb.append(builtins.commandInfo(c).get(0));
help.add(asb.toString());
}
help.addAll(Arrays.asList(
" Example:"
, " autopair toggle brackets/quotes autopair key bindings"
, " autosuggestion history, completer, tailtip [tailtip|completer|combined] or none"
, " cls clear screen"
, " help list available commands"
, " exit exit from example app"
, " sleep sleep 3 seconds"
, " testkey display key events"
, " tput set terminal capability"
, " Additional help:"
, " <command> --help"));
for (String u: help) {
System.out.println(u);
}
}
private static Map<String,CmdDesc> compileTailTips() {
Map<String, CmdDesc> tailTips = new HashMap<>();
Map<String, List<AttributedString>> optDesc = new HashMap<>();
optDesc.put("--optionA", Arrays.asList(new AttributedString("optionA description...")));
optDesc.put("--noitpoB", Arrays.asList(new AttributedString("noitpoB description...")));
optDesc.put("--optionC", Arrays.asList(new AttributedString("optionC description...")
, new AttributedString("line2")));
Map<String, List<AttributedString>> widgetOpts = new HashMap<>();
List<AttributedString> mainDesc = Arrays.asList(new AttributedString("widget -N new-widget [function-name]")
, new AttributedString("widget -D widget ...")
, new AttributedString("widget -A old-widget new-widget")
, new AttributedString("widget -U string ...")
, new AttributedString("widget -l [options]")
);
widgetOpts.put("-N", Arrays.asList(new AttributedString("Create new widget")));
widgetOpts.put("-D", Arrays.asList(new AttributedString("Delete widgets")));
widgetOpts.put("-A", Arrays.asList(new AttributedString("Create alias to widget")));
widgetOpts.put("-U", Arrays.asList(new AttributedString("Push characters to the stack")));
widgetOpts.put("-l", Arrays.asList(new AttributedString("List user-defined widgets")));
tailTips.put("widget", new CmdDesc(mainDesc, ArgDesc.doArgNames(Arrays.asList("[pN...]")), widgetOpts));
tailTips.put("foo12", new CmdDesc(ArgDesc.doArgNames(Arrays.asList("param1", "param2", "[paramN...]"))));
tailTips.put("foo11", new CmdDesc(Arrays.asList(
new ArgDesc("param1",Arrays.asList(new AttributedString("Param1 description...")
, new AttributedString("line 2: This is a very long line that does exceed the terminal width."
+" The line will be truncated automatically (by Status class) be before printing out.")
, new AttributedString("line 3")
, new AttributedString("line 4")
, new AttributedString("line 5")
, new AttributedString("line 6")
))
, new ArgDesc("param2",Arrays.asList(new AttributedString("Param2 description...")
, new AttributedString("line 2")
))
, new ArgDesc("param3", new ArrayList<>())
), optDesc));
return tailTips;
}
private static class DescriptionGenerator {
Builtins builtins;
public DescriptionGenerator(Builtins builtins) {
this.builtins = builtins;
}
CmdDesc commandDescription(CmdLine line) {
CmdDesc out = null;
switch (line.getDescriptionType()) {
case COMMAND:
String cmd = Parser.getCommand(line.getArgs().get(0));
if (builtins.hasCommand(cmd)) {
out = builtins.commandDescription(cmd);
} else {
// other commands...
}
break;
case METHOD:
out = methodDescription(line);
break;
case SYNTAX:
out = new CmdDesc(false);
break;
}
return out;
}
private CmdDesc methodDescription(CmdLine line) {
List<String> keywords = Arrays.asList("if", "while", "for");
for (String s: keywords) {
if (Pattern.compile("\\b" + s + "\\s*$").matcher(line.getHead()).find()){
return null;
}
}
List<AttributedString> mainDesc = new ArrayList<>();
try {
// For example if using groovy you can create involved object
// dynamically from line string and then inspect method's
// parameters using reflection
if (line.getLine().length() > 20) {
throw new IllegalArgumentException("Failed to create object from source: " + line.getLine());
}
mainDesc = Arrays.asList(new AttributedString("method1(int arg1, List<String> arg2)")
, new AttributedString("method1(int arg1, Map<String,Object> arg2)")
);
} catch (Exception e) {
for (String s: e.getMessage().split("\n")) {
mainDesc.add(new AttributedString(s, AttributedStyle.DEFAULT.foreground(AttributedStyle.RED)));
}
}
return new CmdDesc(mainDesc, new ArrayList<>(), new HashMap<>());
}
}
private static class ReaderOptions {
LineReader reader;
public ReaderOptions() {
}
public void setReader(LineReader reader) {
this.reader = reader;
}
List<String> unsetted(boolean set) {
List<String> out = new ArrayList<>();
for (Option option : Option.values()) {
if (set == (reader.isSet(option) == option.isDef())) {
out.add((option.isDef() ? "no-" : "") + option.toString().toLowerCase().replace('_', '-'));
}
}
return out;
}
}
public static void main(String[] args) throws IOException {
try {
String prompt = "prompt> ";
String rightPrompt = null;
Character mask = null;
String trigger = null;
boolean color = false;
boolean timer = false;
boolean argument = false;
TerminalBuilder builder = TerminalBuilder.builder();
if ((args == null) || (args.length == 0)) {
usage();
return;
}
int mouse = 0;
Completer completer = null;
Parser parser = null;
List<Consumer<LineReader>> callbacks = new ArrayList<>();
ReaderOptions readerOptions = new ReaderOptions();
for (int index=0; index < args.length; index++) {
switch (args[index]) {
/* SANDBOX JANSI
case "-posix":
builder.posix(false);
break;
case "+posix":
builder.posix(true);
break;
case "-native-pty":
builder.nativePty(false);
break;
case "+native-pty":
builder.nativePty(true);
break;
*/
case "timer":
timer = true;
break;
case "-system":
builder.system(false).streams(System.in, System.out);
break;
case "+system":
builder.system(true);
break;
case "none":
break;
case "files":
completer = new Completers.FileNameCompleter();
break;
case "simple":
completer = new StringsCompleter("foo", "bar", "baz");
break;
case "quotes":
DefaultParser p = new DefaultParser();
p.setEofOnUnclosedQuote(true);
parser = p;
break;
case "brackets":
prompt = "long-prompt> ";
DefaultParser p2 = new DefaultParser();
p2.setEofOnUnclosedBracket(Bracket.CURLY, Bracket.ROUND, Bracket.SQUARE);
parser = p2;
break;
case "status":
completer = new StringsCompleter("foo", "bar", "baz");
callbacks.add(reader -> {
new Thread(() -> {
int counter = 0;
while (true) {
try {
Status status = Status.getStatus(reader.getTerminal());
counter++;
status.update(Arrays.asList(new AttributedStringBuilder().append("counter: " + counter).toAttributedString()));
((LineReaderImpl) reader).redisplay();
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
});
break;
case "aggregate":
List<Completer> ccc = new ArrayList<>();
ccc.add(new ArgumentCompleter(
new StringsCompleter("setopt"),
new StringsCompleter(() -> readerOptions.unsetted(true))));
ccc.add(new ArgumentCompleter(
new StringsCompleter("unsetopt"),
new StringsCompleter(() -> readerOptions.unsetted(false))));
completer = new AggregateCompleter(ccc);
break;
case "argument":
argument = true;
completer = new ArgumentCompleter(
new Completer() {
@Override
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
candidates.add(new Candidate("foo11", "foo11", null, "complete cmdDesc", null, null, true));
candidates.add(new Candidate("foo12", "foo12", null, "cmdDesc -names only", null, null, true));
candidates.add(new Candidate("foo13", "foo13", null, "-", null, null, true));
candidates.add(new Candidate("widget", "widget", null, "cmdDesc with short options", null, null, true));
}
},
new StringsCompleter("foo21", "foo22", "foo23"),
new Completer() {
@Override
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
candidates.add(new Candidate("", "", null, "frequency in MHz", null, null, false));
}
});
break;
case "param":
completer = (reader, line, candidates) -> {
if (line.wordIndex() == 0) {
candidates.add(new Candidate("Command1"));
} else if (line.words().get(0).equals("Command1")) {
if (line.words().get(line.wordIndex() - 1).equals("Option1")) {
candidates.add(new Candidate("Param1"));
candidates.add(new Candidate("Param2"));
} else {
if (line.wordIndex() == 1) {
candidates.add(new Candidate("Option1"));
}
if (!line.words().contains("Option2")) {
candidates.add(new Candidate("Option2"));
}
if (!line.words().contains("Option3")) {
candidates.add(new Candidate("Option3"));
}
}
}
};
break;
case "tree":
completer = new TreeCompleter(
node("Command1",
node("Option1",
node("Param1", "Param2")),
node("Option2"),
node("Option3")));
break;
case "regexp":
Map<String, Completer> comp = new HashMap<>();
comp.put("C1", new StringsCompleter("cmd1"));
comp.put("C11", new StringsCompleter("--opt11", "--opt12"));
comp.put("C12", new StringsCompleter("arg11", "arg12", "arg13"));
comp.put("C2", new StringsCompleter("cmd2"));
comp.put("C21", new StringsCompleter("--opt21", "--opt22"));
comp.put("C22", new StringsCompleter("arg21", "arg22", "arg23"));
completer = new Completers.RegexCompleter("C1 C11* C12+ | C2 C21* C22+", comp::get);
break;
case "color":
color = true;
prompt = new AttributedStringBuilder()
.style(AttributedStyle.DEFAULT.background(AttributedStyle.GREEN))
.append("foo")
.style(AttributedStyle.DEFAULT)
.append("@bar")
.style(AttributedStyle.DEFAULT.foreground(AttributedStyle.GREEN))
.append("\nbaz")
.style(AttributedStyle.DEFAULT)
.append("> ").toAnsi();
rightPrompt = new AttributedStringBuilder()
.style(AttributedStyle.DEFAULT.background(AttributedStyle.RED))
.append(LocalDate.now().format(DateTimeFormatter.ISO_DATE))
.append("\n")
.style(AttributedStyle.DEFAULT.foreground(AttributedStyle.RED | AttributedStyle.BRIGHT))
.append(LocalTime.now().format(new DateTimeFormatterBuilder()
.appendValue(HOUR_OF_DAY, 2)
.appendLiteral(':')
.appendValue(MINUTE_OF_HOUR, 2)
.toFormatter()))
.toAnsi();
completer = new StringsCompleter("\u001B[1mfoo\u001B[0m", "bar", "\u001B[32mbaz\u001B[0m", "foobar");
break;
case "mouse":
mouse = 1;
break;
case "mousetrack":
mouse = 2;
break;
default:
if (index==0) {
usage();
return;
} else if (args.length == index + 2) {
mask = args[index+1].charAt(0);
trigger = args[index];
index = args.length;
} else {
System.out.println("Bad test case: " + args[index]);
}
}
}
Builtins builtins = new Builtins(Paths.get(""), null, null);
builtins.rename(Command.TTOP, "top");
builtins.alias("zle", "widget");
builtins.alias("bindkey", "keymap");
SystemCompleter systemCompleter = builtins.compileCompleters();
systemCompleter.compile();
List<Completer> completers = new ArrayList<>();
completers.add(systemCompleter);
if (completer != null) {
completers.add(completer);
}
AggregateCompleter finalCompleter = new AggregateCompleter(completers);
Terminal terminal = builder.build();
System.out.println(terminal.getName()+": "+terminal.getType());
System.out.println("\nhelp: list available commands");
LineReader reader = LineReaderBuilder.builder()
.terminal(terminal)
.completer(finalCompleter)
.parser(parser)
.variable(LineReader.SECONDARY_PROMPT_PATTERN, "%M%P > ")
.variable(LineReader.INDENTATION, 2)
.option(Option.INSERT_BRACKET, true)
.build();
builtins.setLineReader(reader);
DescriptionGenerator descriptionGenerator = new DescriptionGenerator(builtins);
readerOptions.setReader(reader);
AutopairWidgets autopairWidgets = new AutopairWidgets(reader);
AutosuggestionWidgets autosuggestionWidgets = new AutosuggestionWidgets(reader);
TailTipWidgets tailtipWidgets = null;
if (argument) {
tailtipWidgets = new TailTipWidgets(reader, compileTailTips(), 5, TipType.COMPLETER);
} else {
tailtipWidgets = new TailTipWidgets(reader, descriptionGenerator::commandDescription, 5, TipType.COMPLETER);
}
if (timer) {
Executors.newScheduledThreadPool(1)
.scheduleAtFixedRate(() -> {
reader.callWidget(LineReader.CLEAR);
reader.getTerminal().writer().println("Hello world!");
reader.callWidget(LineReader.REDRAW_LINE);
reader.callWidget(LineReader.REDISPLAY);
reader.getTerminal().writer().flush();
}, 1, 1, TimeUnit.SECONDS);
}
if (mouse != 0) {
reader.setOpt(LineReader.Option.MOUSE);
if (mouse == 2) {
reader.getWidgets().put(LineReader.CALLBACK_INIT, () -> {
terminal.trackMouse(Terminal.MouseTracking.Any);
return true;
});
reader.getWidgets().put(LineReader.MOUSE, () -> {
MouseEvent event = reader.readMouseEvent();
StringBuilder tsb = new StringBuilder();
Cursor cursor = terminal.getCursorPosition(c -> tsb.append((char) c));
reader.runMacro(tsb.toString());
String msg = " " + event.toString();
int w = terminal.getWidth();
terminal.puts(Capability.cursor_address, 0, Math.max(0, w - msg.length()));
terminal.writer().append(msg);
terminal.puts(Capability.cursor_address, cursor.getY(), cursor.getX());
terminal.flush();
return true;
});
}
}
callbacks.forEach(c -> c.accept(reader));
if (!callbacks.isEmpty()) {
Thread.sleep(2000);
}
while (true) {
try {
String line = reader.readLine(prompt, rightPrompt, (MaskingCallback) null, null);
line = line.trim();
if (color) {
terminal.writer().println(
AttributedString.fromAnsi("\u001B[33m======>\u001B[0m\"" + line + "\"")
.toAnsi(terminal));
} else {
terminal.writer().println("======>\"" + line + "\"");
}
terminal.flush();
// If we input the special word then we will mask
// the next line.
if ((trigger != null) && (line.compareTo(trigger) == 0)) {
line = reader.readLine("password> ", mask);
}
if (line.equalsIgnoreCase("quit") || line.equalsIgnoreCase("exit")) {
break;
}
ParsedLine pl = reader.getParser().parse(line, 0);
String[] argv = pl.words().subList(1, pl.words().size()).toArray(new String[0]);
String cmd = Parser.getCommand(pl.word());
if ("help".equals(cmd) || "?".equals(cmd)) {
help(builtins);
}
else if (builtins.hasCommand(cmd)) {
builtins.execute(cmd, argv, System.in, System.out, System.err);
}
else if ("tput".equals(cmd)) {
if (argv.length == 1) {
Capability vcap = Capability.byName(argv[0]);
if (vcap != null) {
terminal.puts(vcap);
} else {
terminal.writer().println("Unknown capability");
}
} else {
terminal.writer().println("Usage: tput <capability>");
}
}
else if ("testkey".equals(cmd)) {
terminal.writer().write("Input the key event(Enter to complete): ");
terminal.writer().flush();
StringBuilder sb = new StringBuilder();
while (true) {
int c = ((LineReaderImpl) reader).readCharacter();
if (c == 10 || c == 13) break;
sb.append(new String(Character.toChars(c)));
}
terminal.writer().println(KeyMap.display(sb.toString()));
terminal.writer().flush();
}
else if ("cls".equals(cmd)) {
terminal.puts(Capability.clear_screen);
terminal.flush();
}
else if ("sleep".equals(cmd)) {
Thread.sleep(3000);
}
else if ("autopair".equals(cmd)) {
terminal.writer().print("Autopair widgets are ");
if (autopairWidgets.toggle()) {
terminal.writer().println("enabled.");
} else {
terminal.writer().println("disabled.");
}
}
else if ("autosuggestion".equals(cmd)) {
if (argv.length > 0) {
String type = argv[0].toLowerCase();
if (type.startsWith("his")) {
tailtipWidgets.disable();
autosuggestionWidgets.enable();
} else if (type.startsWith("tai")) {
autosuggestionWidgets.disable();
tailtipWidgets.enable();
if (argv.length > 1) {
String mode = argv[1].toLowerCase();
if (mode.startsWith("tai")) {
tailtipWidgets.setTipType(TipType.TAIL_TIP);
} else if (mode.startsWith("comp")) {
tailtipWidgets.setTipType(TipType.COMPLETER);
} else if (mode.startsWith("comb")) {
tailtipWidgets.setTipType(TipType.COMBINED);
}
}
} else if (type.startsWith("com")) {
autosuggestionWidgets.disable();
tailtipWidgets.disable();
reader.setAutosuggestion(SuggestionType.COMPLETER);
} else if (type.startsWith("non")) {
autosuggestionWidgets.disable();
tailtipWidgets.disable();
reader.setAutosuggestion(SuggestionType.NONE);
} else {
terminal.writer().println("Usage: autosuggestion history|completer|tailtip|none");
}
} else {
if (tailtipWidgets.isEnabled()) {
terminal.writer().println("Autosuggestion: tailtip/" + tailtipWidgets.getTipType());
} else {
terminal.writer().println("Autosuggestion: " + reader.getAutosuggestion());
}
}
}
}
catch (HelpException e) {
HelpException.highlight(e.getMessage(), HelpException.defaultStyle()).print(terminal);
}
catch (IllegalArgumentException|FileNotFoundException e) {
System.out.println(e.getMessage());
}
catch (UserInterruptException e) {
// Ignore
}
catch (EndOfFileException e) {
return;
}
catch (Exception e) {
e.printStackTrace();
}
}
}
catch (Throwable t) {
t.printStackTrace();
}
}
}