From: Niki Roo Date: Tue, 8 Aug 2017 18:18:29 +0000 (+0200) Subject: Justify text on gopher X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=301dfeb23bda89e70b3c51ac2e26b378e7448cab;p=gofetch.git Justify text on gopher --- diff --git a/src/be/nikiroo/gofetch/output/Gopher.java b/src/be/nikiroo/gofetch/output/Gopher.java index 478522b..dd5e348 100644 --- a/src/be/nikiroo/gofetch/output/Gopher.java +++ b/src/be/nikiroo/gofetch/output/Gopher.java @@ -87,7 +87,7 @@ public class Gopher extends Output { if (!resume) { appendCenter(builder, story.getTitle(), true); builder.append("i\r\n"); - appendLeft(builder, story.getDetails(), " "); + appendJustified(builder, story.getDetails(), " "); builder.append("i\r\n"); builder.append("i o News link: ").append(story.getUrlInternal()) @@ -98,17 +98,17 @@ public class Gopher extends Output { builder.append("i\r\n"); - appendLeft(builder, story.getFullContent(), " "); + appendJustified(builder, story.getFullContent(), " "); } else { builder.append('1').append(story.getTitle()) // .append('\t').append("0").append(story.getSelector()) // .append('\t').append(hostname) // .append('\t').append(port) // .append("\r\n"); - appendLeft(builder, story.getDetails(), " "); + appendJustified(builder, story.getDetails(), " "); builder.append("i\r\n"); - appendLeft(builder, story.getContent(), " "); + appendJustified(builder, story.getContent(), " "); } builder.append("i\r\n"); @@ -128,6 +128,15 @@ public class Gopher extends Output { } } + // note: adds "i" + private static void appendJustified(StringBuilder builder, String text, + String space) { + for (String line : StringJustifier.full(text, + LINE_SIZE - space.length())) { + builder.append("i").append(line).append("\r\n"); + } + } + // note: adds "i" private static void appendLeft(StringBuilder builder, String text, String space) {