Skip to content

Commit b9731a2

Browse files
Use printAbove in terminal IO.
Improve display of delayed messages and fix issue where signal is not trapped. Fixes system exit service to not respond unless required which was showing in terminal on exit.
1 parent 902b776 commit b9731a2

5 files changed

Lines changed: 21 additions & 63 deletions

File tree

praxiscore-hub/src/main/java/org/praxislive/hub/BasicCoreRoot.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright 2023 Neil C Smith.
4+
* Copyright 2025 Neil C Smith.
55
*
66
* This code is free software; you can redistribute it and/or modify it
77
* under the terms of the GNU Lesser General Public License version 3 only, as
@@ -37,7 +37,6 @@
3737
import org.praxislive.core.Root;
3838
import org.praxislive.core.RootHub;
3939
import org.praxislive.core.Control;
40-
import org.praxislive.core.Lookup;
4140
import org.praxislive.core.PacketRouter;
4241
import org.praxislive.core.Value;
4342
import org.praxislive.core.services.RootFactoryService;
@@ -201,7 +200,9 @@ protected void buildControlMap(Map<String, Control> ctrls) {
201200
.toIntValue();
202201
}
203202
forceTermination();
204-
router.route(call.reply());
203+
if (call.isReplyRequired()) {
204+
router.route(call.reply());
205+
}
205206
}
206207
});
207208
}

praxiscore-launcher-jline/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
<dependency>
3030
<groupId>org.jline</groupId>
3131
<artifactId>jline-terminal</artifactId>
32-
<version>3.30.3</version>
32+
<version>3.30.6</version>
3333
</dependency>
3434
<dependency>
3535
<groupId>org.jline</groupId>
3636
<artifactId>jline-reader</artifactId>
37-
<version>3.30.3</version>
37+
<version>3.30.6</version>
3838
</dependency>
3939
</dependencies>
4040

praxiscore-launcher-jline/src/main/java/org/praxislive/launcher/jline/JLineTerminalIO.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright 2021 Neil C Smith.
4+
* Copyright 2025 Neil C Smith.
55
*
66
* This code is free software; you can redistribute it and/or modify it
77
* under the terms of the GNU Lesser General Public License version 3 only, as
@@ -99,7 +99,7 @@ private void handleExit() {
9999
.flatMap(s -> s.locate(SystemManagerService.class))
100100
.map(cmp -> ControlAddress.of(cmp, SystemManagerService.SYSTEM_EXIT))
101101
.ifPresentOrElse(exit -> {
102-
getRouter().route(Call.create(exit, fromAddress,
102+
getRouter().route(Call.createQuiet(exit, fromAddress,
103103
getExecutionContext().getTime()));
104104
}, () -> System.exit(0));
105105
}
Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright 2021 Neil C Smith.
4+
* Copyright 2025 Neil C Smith.
55
*
66
* This code is free software; you can redistribute it and/or modify it
77
* under the terms of the GNU Lesser General Public License version 3 only, as
@@ -22,22 +22,4 @@
2222

2323
package org.praxislive.launcher.jline;
2424

25-
class Response {
26-
27-
final String message;
28-
final boolean error;
29-
30-
Response(String message, boolean error) {
31-
this.message = message;
32-
this.error = error;
33-
}
34-
35-
String message() {
36-
return message;
37-
}
38-
39-
boolean error() {
40-
return error;
41-
}
42-
43-
}
25+
record Response(String message, boolean error) {}

praxiscore-launcher-jline/src/main/java/org/praxislive/launcher/jline/TerminalImpl.java

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
package org.praxislive.launcher.jline;
2323

2424
import java.util.Locale;
25-
import java.util.concurrent.BlockingQueue;
26-
import java.util.concurrent.LinkedBlockingQueue;
27-
import java.util.concurrent.TimeUnit;
2825
import java.util.concurrent.atomic.AtomicReference;
2926
import org.jline.reader.EOFError;
3027
import org.jline.reader.LineReader;
@@ -52,15 +49,13 @@ class TerminalImpl {
5249

5350
private static final TerminalImpl INSTANCE = new TerminalImpl();
5451

55-
private final BlockingQueue<Response> responses;
5652
private final AtomicReference<JLineTerminalIO> service;
5753

5854
private Thread inputThread;
5955
private Terminal terminal;
6056
private LineReader reader;
6157

6258
private TerminalImpl() {
63-
responses = new LinkedBlockingQueue<>(200);
6459
service = new AtomicReference<>();
6560
}
6661

@@ -94,49 +89,36 @@ synchronized void attach(JLineTerminalIO service) {
9489
}
9590

9691
synchronized void detach(JLineTerminalIO service) {
97-
if (this.service.compareAndSet(service, null)) {
98-
postResponse(new Response("", false));
99-
}
92+
this.service.compareAndSet(service, null);
10093
}
10194

10295
synchronized void postResponse(Response response) {
103-
if (terminal != null) {
104-
responses.add(response);
96+
if (reader != null) {
97+
writeResponse(response);
10598
}
10699
}
107100

108101
private void inputLoop() {
109102

110103
while (true) {
111104
try {
112-
var script = reader.readLine(PROMPT);
105+
String script = reader.readLine(PROMPT);
113106
if (script != null && !script.isBlank()) {
114-
var root = service.get();
107+
JLineTerminalIO root = service.get();
115108
if (root != null) {
116109
root.postScript(script);
117-
var response = responses.poll(10, TimeUnit.SECONDS);
118-
if (response == null) {
119-
writeResponse(new Response("Timed out", true));
120-
} else {
121-
writeResponse(response);
122-
}
123110
} else {
124111
writeResponse(new Response("Not running", true));
125112
}
126113
}
127-
// make sure response queue empty
128-
Response response;
129-
while ((response = responses.poll()) != null) {
130-
writeResponse(response);
131-
}
132114
} catch (UserInterruptException ex) {
133115
if (ex.getPartialLine().isBlank()) {
134116
try {
135-
var confirm = reader.readLine(EXIT_PROMPT);
117+
String confirm = reader.readLine(EXIT_PROMPT);
136118
if ("y".equals(confirm.trim().toLowerCase(Locale.ROOT))) {
137119
terminal.writer().println(EXIT_NOTICE);
138120
terminal.flush();
139-
var root = service.get();
121+
JLineTerminalIO root = service.get();
140122
if (root != null) {
141123
root.postExit();
142124
Thread.sleep(5000);
@@ -157,29 +139,22 @@ private void inputLoop() {
157139
}
158140

159141
private synchronized void writeResponse(Response response) {
160-
if (response.error) {
161-
terminal.writer()
162-
.println(new AttributedString("ERR : " + response.message,
142+
if (response.error()) {
143+
reader.printAbove(new AttributedString("ERR : " + response.message(),
163144
AttributedStyle.DEFAULT.foreground(AttributedStyle.RED))
164145
.toAnsi(terminal)
165146
);
166-
terminal.flush();
167147
} else {
168-
terminal.writer()
169-
.println(new AttributedString("--- : " + response.message,
148+
reader.printAbove(new AttributedString("--- : " + response.message(),
170149
AttributedStyle.DEFAULT.foreground(AttributedStyle.GREEN))
171150
.toAnsi(terminal)
172151
);
173-
terminal.flush();
174152
}
175153
}
176154

177155
private boolean isCompleteScript(String script) {
178156
try {
179-
var tok = new Tokenizer(script);
180-
for (var t : tok) {
181-
// consume to end
182-
}
157+
Tokenizer.parse(script);
183158
return true;
184159
} catch (Exception e) {
185160
return false;

0 commit comments

Comments
 (0)