Justify text on gopher
authorNiki Roo <niki@nikiroo.be>
Tue, 8 Aug 2017 18:18:29 +0000 (20:18 +0200)
committerNiki Roo <niki@nikiroo.be>
Tue, 8 Aug 2017 18:18:29 +0000 (20:18 +0200)
src/be/nikiroo/gofetch/output/Gopher.java

index 478522b53a5ac24d8fbec9ff0ebfdca0d4f3ecef..dd5e3482f3c18b487097b595709cc211b3f8082b 100644 (file)
@@ -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) {