Skip to content

Commit

Permalink
chore: Replaces StringWriter by ByteArrayOutputStream
Browse files Browse the repository at this point in the history
  • Loading branch information
bric3 committed Sep 18, 2023
1 parent 5ff663a commit 9968be7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 29 deletions.
4 changes: 0 additions & 4 deletions jufmt-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ graalvmNative {
}
}

testlogger {
showStandardStreams = true
}

tasks {
distZip { enabled = false }
distTar { enabled = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,23 +259,15 @@ void figlet(
*/
var out = spec.commandLine().getOut();
if (random) {
String rendered = Figlet.render(stringToProcess);
if (rendered.isBlank()) {
throw new IllegalStateException("No font found");
}
out.println(rendered);
out.println(Figlet.render(stringToProcess));
return;
}
if (renderAll) {
Arrays.stream(EmbeddedFigletFonts.values())
.forEach(f -> {
out.printf("%s:%n", f);
out.println();
String rendered = Figlet.render(stringToProcess, f);
if (rendered.isBlank()) {
throw new IllegalStateException("No font found");
}
out.println(rendered);
out.println(Figlet.render(stringToProcess, f));
out.println();
});
return;
Expand Down Expand Up @@ -309,11 +301,7 @@ void figlet(
font = figletFont.font;
}

var rendered = Figlet.render(stringToProcess, font);
if (rendered.isBlank()) {
throw new IllegalStateException("No font found");
}
out.println(rendered);
out.println(Figlet.render(stringToProcess, font));
}

@Command(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,27 @@

import picocli.CommandLine;

import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;

import static java.nio.charset.StandardCharsets.UTF_8;

class JufmtTestUtil {
record Result(int status, String out, String err) {}

public static Result jufmt(String... args) {
var outWriter = new StringWriter();
var errWriter = new StringWriter();
var outWriter = new ByteArrayOutputStream();
var errWriter = new ByteArrayOutputStream();
int status = new CommandLine(new JufmtCommand())
.setOut(new PrintWriter(outWriter, true))
.setErr(new PrintWriter(errWriter, true))
.setOut(new PrintWriter(outWriter, true, UTF_8))
.setErr(new PrintWriter(errWriter, true, UTF_8))
.execute(args);

return new Result(status, outWriter.toString(), errWriter.toString());
return new Result(
status,
outWriter.toString(UTF_8),
errWriter.toString(UTF_8)
);
}
}
5 changes: 1 addition & 4 deletions jufmt-lib/src/main/java/io/github/bric3/jufmt/Figlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ public class Figlet {
*/
@NotNull
public static String render(@NotNull String text, @NotNull FontSpec font) {
String render = renderer.render(text, font);
System.out.println("Render for " + text + " with " + font.getName() +
"\n" + render + "\n");
return render;
return renderer.render(text, font);
}

/**
Expand Down

0 comments on commit 9968be7

Please sign in to comment.