From 301dfeb23bda89e70b3c51ac2e26b378e7448cab Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Tue, 8 Aug 2017 20:18:29 +0200 Subject: [PATCH] Justify text on gopher --- src/be/nikiroo/gofetch/output/Gopher.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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) { -- 2.27.0