git://git.nikiroo.be
/
gofetch.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Bug fixes + rework of BasicSupport
[gofetch.git]
/
src
/
be
/
nikiroo
/
gofetch
/
output
/
Gopher.java
diff --git
a/src/be/nikiroo/gofetch/output/Gopher.java
b/src/be/nikiroo/gofetch/output/Gopher.java
index 877dfa27fb445b3b2cb622a50244d3f70ece71ea..12a420cd84482b988cde4775c6b29f3962fe574b 100644
(file)
--- a/
src/be/nikiroo/gofetch/output/Gopher.java
+++ b/
src/be/nikiroo/gofetch/output/Gopher.java
@@
-1,9
+1,10
@@
package be.nikiroo.gofetch.output;
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.data.Comment;
import be.nikiroo.gofetch.data.Story;
-import be.nikiroo.gofetch.support.BasicSupport.Type;
+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;
public class Gopher extends Output {
static private final int LINE_SIZE = 67;
@@
-16,7
+17,7
@@
public class Gopher extends Output {
public String getIndexHeader() {
StringBuilder builder = new StringBuilder();
public String getIndexHeader() {
StringBuilder builder = new StringBuilder();
- appendCenter(builder, true, "NEWS", true);
+ appendCenter(builder, true, "NEWS",
"",
true);
appendLeft(builder, true, "", "");
appendLeft(builder, true,
"You will find here a few pages full of news.", "");
appendLeft(builder, true, "", "");
appendLeft(builder, true,
"You will find here a few pages full of news.", "");
@@
-50,7
+51,7
@@
public class Gopher extends Output {
if (story.getComments() != null) {
for (Comment comment : story.getComments()) {
if (story.getComments() != null) {
for (Comment comment : story.getComments()) {
- append(builder, false, comment, "");
+ append(builder, false, comment, "
");
}
}
}
}
@@
-67,10
+68,13
@@
public class Gopher extends Output {
}
appendLeft(builder, menu, comment.getTitle(), "** ", " ", space);
}
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;
for (String line : comment.getContentLines()) {
int depth = 0;
@@
-91,10
+95,10
@@
public class Gopher extends Output {
appendLeft(builder, menu, line, prep, prep, space);
}
appendLeft(builder, menu, line, prep, prep, space);
}
- builder.append(
"i
\r\n");
+ builder.append(
(menu ? "i" : "") + "
\r\n");
for (Comment subComment : comment) {
append(builder, menu, subComment, space + " ");
for (Comment subComment : comment) {
append(builder, menu, subComment, space + " ");
- builder.append(
"i
\r\n");
+ builder.append(
(menu ? "i" : "") + "
\r\n");
}
return builder;
}
return builder;
@@
-103,7
+107,7
@@
public class Gopher extends Output {
private StringBuilder append(StringBuilder builder, Story story,
boolean resume) {
if (!resume) {
private StringBuilder append(StringBuilder builder, Story story,
boolean resume) {
if (!resume) {
- appendCenter(builder, false, story.getTitle(), true);
+ appendCenter(builder, false, story.getTitle(),
" ",
true);
builder.append("\r\n");
appendJustified(builder, false, story.getDetails(), " ");
builder.append("\r\n");
builder.append("\r\n");
appendJustified(builder, false, story.getDetails(), " ");
builder.append("\r\n");
@@
-117,6
+121,7
@@
public class Gopher extends Output {
builder.append("\r\n");
appendJustified(builder, false, story.getFullContent(), " ");
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()) //
} else {
builder.append('0').append(story.getTitle()) //
.append('\t').append(story.getSelector()) //
@@
-126,32
+131,43
@@
public class Gopher extends Output {
appendJustified(builder, true, story.getDetails(), " ");
builder.append("i\r\n");
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" : "") + "\r\n");
-
return builder;
}
// note: adds "i"
private static void appendCenter(StringBuilder builder, boolean menu,
return builder;
}
// note: adds "i"
private static void appendCenter(StringBuilder builder, boolean menu,
- String text, boolean allCaps) {
+ String text,
String space,
boolean allCaps) {
if (allCaps) {
text = text.toUpperCase();
}
if (allCaps) {
text = text.toUpperCase();
}
- for (String line : StringJustifier.center(text, LINE_SIZE)) {
- builder.append(menu ? "i" : "").append(line).append("\r\n");
+ int size = LINE_SIZE - space.length();
+ for (String line : StringUtils
+ .justifyText(text, size, Alignment.CENTER)) {
+ builder.append(menu ? "i" : "") //
+ .append(space) //
+ .append(line) //
+ .append("\r\n");
}
}
private static void appendJustified(StringBuilder builder, boolean menu,
String text, String space) {
for (String line : text.split("\n")) {
}
}
private static void appendJustified(StringBuilder builder, boolean menu,
String text, String space) {
for (String line : text.split("\n")) {
- for (String subline : StringJustifier.full(line,
- LINE_SIZE - space.length())) {
- builder.append(menu ? "i" : "").append(subline).append("\r\n");
+ int size = LINE_SIZE - space.length();
+ for (String subline : StringUtils.justifyText(line, size,
+ Alignment.JUSTIFY)) {
+ builder.append(menu ? "i" : "") //
+ .append(space) //
+ .append(subline) //
+ .append("\r\n");
}
}
}
}
}
}
@@
-165,10
+181,13
@@
public class Gopher extends Output {
String text, String prependFirst, String prependOthers, String space) {
String prepend = prependFirst;
for (String line : text.split("\n")) {
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;
}
}
prepend = prependOthers;
}
}