Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify and complete method implementation #2075

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.IntConsumer;
import java.util.function.IntSupplier;
Expand All @@ -46,21 +44,22 @@

public class FastTerminal implements TerminalExt {

final Future<Terminal> terminal;
private final CompletableFuture<Terminal> terminal;

public FastTerminal(Callable<Terminal> builder, Consumer<Terminal> consumer) {
ExecutorService executor = Executors.newSingleThreadExecutor();
terminal = executor.submit(() -> {
try {
Terminal terminal = builder.call();
consumer.accept(terminal);
return terminal;
} catch (Exception e) {
throw new MavenException(e);
} finally {
executor.shutdown();
}
});
this.terminal = new CompletableFuture<>();
new Thread(
() -> {
try {
Terminal term = builder.call();
consumer.accept(term);
terminal.complete(term);
} catch (Exception e) {
terminal.completeExceptionally(new MavenException(e));
}
},
"fast-terminal-thread")
.start();
}

public TerminalExt getTerminal() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public JLineMessageBuilderFactory() {

@Override
public boolean isColorEnabled() {
return false;
return MessageUtils.isColorEnabled();
}

@Override
Expand Down