fix standard output and console detection

This commit is contained in:
2025-11-13 20:53:19 +03:00
parent eab4f44e51
commit 8880de04d0
4 changed files with 9 additions and 8 deletions

View File

@@ -46,6 +46,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
@@ -154,7 +155,7 @@ public class NoBuild {
@Override
public void publish(LogRecord record) {
if (record.getMessage() != null && !record.getMessage().isEmpty()) {
if (System.console().isTerminal()) {
if (Optional.ofNullable(System.console()).map(it -> it.isTerminal()).orElse(false)) {
int color = colors.get(record.getLevel());
System.err.printf(
"\u001b[38;5;%dm[%s]\u001b[0m %s%n",
@@ -386,10 +387,9 @@ public class NoBuild {
PathMatcher pathMatcher =
FileSystems.getDefault()
.getPathMatcher(String.join("", "glob:", cwd.toString(), File.separator, globPattern));
try (@SuppressWarnings("unused")
Stream<Path> paths =
Files.find(
cwd, Integer.MAX_VALUE, (path, basicFileAttributes) -> pathMatcher.matches(path))) {
try (Stream<Path> paths =
Files.find(
cwd, Integer.MAX_VALUE, (path, basicFileAttributes) -> pathMatcher.matches(path))) {
return paths.map(Path::toString).toArray(String[]::new);
} catch (IOException e) {
return new String[0];

View File

@@ -106,6 +106,7 @@ public class Jtags {
System.exit(1);
yield null;
}
case "-" -> Path.of("-");
case String output -> Path.of(output).toAbsolutePath();
};
logger.config("Writing tags to " + options.output.toString());

View File

@@ -2,6 +2,7 @@ package xyz.naofal.jtags;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
@@ -47,7 +48,7 @@ public class JtagsLogger {
@Override
public void publish(LogRecord record) {
if (record.getMessage() != null && !record.getMessage().isEmpty()) {
if (System.console().isTerminal()) {
if (Optional.ofNullable(System.console()).map(it->it.isTerminal()).orElse(false)) {
int color = colors.get(record.getLevel());
System.err.printf(
"\u001b[38;5;%dm[%s]\u001b[0m %s%n",

View File

@@ -76,8 +76,7 @@ public @interface Test {
case "-u", "-update-snapshots":
options.updateSnapshots = true;
break;
case null:
default:
case null, default:
break;
}