X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fgofetch%2Foutput%2FGopher.java;h=aab03f67d19127145735189abd41adc79fbc41a4;hb=c715ea028a2b9865b1b5a619b7cf7553a89aa90d;hp=97b7b9b5b1f4f45476c71883655cfbf15025e51d;hpb=136d034bf1f8ea08c8675866d3ab59900b82d3fe;p=gofetch.git diff --git a/src/be/nikiroo/gofetch/output/Gopher.java b/src/be/nikiroo/gofetch/output/Gopher.java index 97b7b9b..aab03f6 100644 --- a/src/be/nikiroo/gofetch/output/Gopher.java +++ b/src/be/nikiroo/gofetch/output/Gopher.java @@ -1,9 +1,11 @@ package be.nikiroo.gofetch.output; -import be.nikiroo.gofetch.StringJustifier; import be.nikiroo.gofetch.data.Comment; import be.nikiroo.gofetch.data.Story; -import be.nikiroo.gofetch.support.BasicSupport.Type; +import be.nikiroo.gofetch.support.BasicSupport; +import be.nikiroo.gofetch.support.Type; +import be.nikiroo.utils.StringUtils; +import be.nikiroo.utils.StringUtils.Alignment; public class Gopher extends Output { static private final int LINE_SIZE = 67; @@ -13,7 +15,7 @@ public class Gopher extends Output { } @Override - public String getIndexHeader() { + public String getMainIndexHeader() { StringBuilder builder = new StringBuilder(); appendCenter(builder, true, "NEWS", "", true); @@ -32,7 +34,22 @@ public class Gopher extends Output { } @Override - public String getIndexFooter() { + public String getMainIndexFooter() { + return ""; + } + + @Override + public String getIndexHeader(BasicSupport support) { + StringBuilder builder = new StringBuilder(); + appendCenter(builder, true, support.getDescription(), "", true); + builder.append("\r\n"); + builder.append("\r\n"); + builder.append("\r\n"); + return builder.toString(); + } + + @Override + public String getIndexFooter(BasicSupport support) { return ""; } @@ -67,10 +84,13 @@ public class Gopher extends Output { } appendLeft(builder, menu, comment.getTitle(), "** ", " ", space); - appendLeft(builder, menu, "(" + comment.getAuthor() + ")", " ", - " ", space); - builder.append((menu ? "i" : "") + "\r\n"); + if (comment.getAuthor() != null + && !comment.getAuthor().trim().isEmpty()) { + appendLeft(builder, menu, "(" + comment.getAuthor() + ")", " ", + " ", space); + builder.append((menu ? "i" : "") + "\r\n"); + } for (String line : comment.getContentLines()) { int depth = 0; @@ -108,6 +128,8 @@ public class Gopher extends Output { appendJustified(builder, false, story.getDetails(), " "); builder.append("\r\n"); + builder.append(" o Reference: ").append(story.getId()) + .append("\r\n"); builder.append(" o News link: ").append(story.getUrlInternal()) .append("\r\n"); builder.append(" o Source link: ").append(story.getUrlExternal()) @@ -117,6 +139,7 @@ public class Gopher extends Output { builder.append("\r\n"); appendJustified(builder, false, story.getFullContent(), " "); + builder.append("\r\n"); } else { builder.append('0').append(story.getTitle()) // .append('\t').append(story.getSelector()) // @@ -126,11 +149,13 @@ public class Gopher extends Output { appendJustified(builder, true, story.getDetails(), " "); builder.append("i\r\n"); - appendJustified(builder, true, story.getContent(), " "); + String content = story.getContent(); + if (!content.isEmpty()) { + appendJustified(builder, true, content, " "); + builder.append("i\r\n"); + } } - builder.append(resume ? "i" : "").append("\r\n"); - return builder; } @@ -140,12 +165,14 @@ public class Gopher extends Output { if (allCaps) { text = text.toUpperCase(); } - + int size = LINE_SIZE - space.length(); - for (String line : StringJustifier.center(text, size)) { - builder.append(menu ? "i" : "") - .append(space) - .append(line).append("\r\n"); + for (String line : StringUtils + .justifyText(text, size, Alignment.CENTER)) { + builder.append(menu ? "i" : "") // + .append(space) // + .append(line) // + .append("\r\n"); } } @@ -153,11 +180,12 @@ public class Gopher extends Output { String text, String space) { for (String line : text.split("\n")) { int size = LINE_SIZE - space.length(); - for (String subline : StringJustifier.full(line, size)) { - builder.append(menu ? "i" : "") - .append(space) - .append(subline) - .append("\r\n"); + for (String subline : StringUtils.justifyText(line, size, + Alignment.JUSTIFY)) { + builder.append(menu ? "i" : "") // + .append(space) // + .append(subline) // + .append("\r\n"); } } } @@ -171,10 +199,13 @@ public class Gopher extends Output { String text, String prependFirst, String prependOthers, String space) { String prepend = prependFirst; for (String line : text.split("\n")) { - for (String subline : StringJustifier.left(line, - LINE_SIZE - space.length())) { - builder.append(menu ? "i" : "").append(space).append(prepend) - .append(subline).append("\r\n"); + for (String subline : StringUtils.justifyText(line, LINE_SIZE + - space.length(), Alignment.LEFT)) { + builder.append(menu ? "i" : "") // + .append(space) // + .append(prepend) // + .append(subline) // + .append("\r\n"); prepend = prependOthers; } }