Version 1.0.0: add Le Monde support
[gofetch.git] / src / be / nikiroo / gofetch / output / Gopher.java
index 478522b53a5ac24d8fbec9ff0ebfdca0d4f3ecef..2fa0c913b31d9951a1007b0269acd50324b2416a 100644 (file)
@@ -65,13 +65,30 @@ public class Gopher extends Output {
                        space = space.substring(0, LINE_SIZE - 20);
                }
 
-               appendLeft(builder, comment.getTitle(), ">> ", "   ", space);
+               appendLeft(builder, comment.getTitle(), "** ", "   ", space);
                appendLeft(builder, "(" + comment.getAuthor() + ")", "   ", "   ",
                                space);
 
                builder.append("i\r\n");
 
-               appendLeft(builder, comment.getContent(), "   ", "   ", space);
+               for (String line : comment.getContentLines()) {
+                       int depth = 0;
+                       while (line.length() > depth && line.charAt(depth) == '>') {
+                               depth++;
+                       }
+                       line = line.substring(depth).trim();
+
+                       String prep = "   ";
+                       for (int i = 0; i < depth; i++) {
+                               prep += ">";
+                       }
+
+                       if (depth > 0) {
+                               prep += " ";
+                       }
+
+                       appendLeft(builder, line, prep, prep, space);
+               }
 
                builder.append("i\r\n");
                for (Comment subComment : comment) {
@@ -87,7 +104,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 +115,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(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 +145,17 @@ public class Gopher extends Output {
                }
        }
 
+       // note: adds "i"
+       private static void appendJustified(StringBuilder builder, String text,
+                       String space) {
+               for (String line : text.split("\n")) {
+                       for (String subline : StringJustifier.full(line,
+                                       LINE_SIZE - space.length())) {
+                               builder.append("i").append(subline).append("\r\n");
+                       }
+               }
+       }
+
        // note: adds "i"
        private static void appendLeft(StringBuilder builder, String text,
                        String space) {
@@ -138,11 +166,13 @@ public class Gopher extends Output {
        private static void appendLeft(StringBuilder builder, String text,
                        String prependFirst, String prependOthers, String space) {
                String prepend = prependFirst;
-               for (String line : StringJustifier.left(text,
-                               LINE_SIZE - space.length())) {
-                       builder.append("i").append(space).append(prepend).append(line)
-                                       .append("\r\n");
-                       prepend = prependOthers;
+               for (String line : text.split("\n")) {
+                       for (String subline : StringJustifier.left(line,
+                                       LINE_SIZE - space.length())) {
+                               builder.append("i").append(space).append(prepend)
+                                               .append(subline).append("\r\n");
+                               prepend = prependOthers;
+                       }
                }
        }
 }