Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit d429a44

Browse files
committed
Mark truncated values with a '…'
1 parent a28784b commit d429a44

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

cypher-shell/src/main/java/org/neo4j/shell/prettyprint/OutputFormatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static boolean isNotBlank(String string) {
163163
}
164164

165165
@Nonnull static String rightPad(@Nonnull String str, int width) {
166-
return rightPad(str,width,' ');
166+
return rightPad(str, width, ' ');
167167
}
168168
@Nonnull static String rightPad(@Nonnull String str, int width, char c) {
169169
int actualSize = str.length();

cypher-shell/src/main/java/org/neo4j/shell/prettyprint/TableOutputFormatter.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,18 @@ private String formatRow(StringBuilder sb, int[] columnSizes, String[] row) {
110110
String txt = row[i];
111111
if (txt != null) {
112112
if (txt.length() > length) {
113-
row[i] = txt.substring(length);
114-
remainder = true;
115-
} else row[i] = null;
116-
sb.append(OutputFormatter.rightPad(txt, length));
113+
if (wrap) {
114+
sb.append(txt, 0, length);
115+
row[i] = txt.substring(length);
116+
remainder = true;
117+
} else {
118+
sb.append(txt, 0, length - 1);
119+
sb.append("…");
120+
}
121+
} else {
122+
row[i] = null;
123+
sb.append(OutputFormatter.rightPad(txt, length));
124+
}
117125
} else {
118126
sb.append(OutputFormatter.repeat(' ', length));
119127
}

cypher-shell/src/test/java/org/neo4j/shell/prettyprint/TableOutputFormatterTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public void wrapContent()
306306
}
307307

308308
@Test
309-
public void cutContent()
309+
public void truncateContent()
310310
{
311311
// GIVEN
312312
StatementResult result = mockResult( asList( "c1"), "a", "bb","ccc","dddd","eeeee" );
@@ -321,9 +321,9 @@ public void cutContent()
321321
"+------+\n" +
322322
"| \"a\" |\n" +
323323
"| \"bb\" |\n" +
324-
"| \"ccc |\n" +
325-
"| \"ddd |\n" +
326-
"| \"eee |\n" +
324+
"| \"cc… |\n" +
325+
"| \"dd… |\n" +
326+
"| \"ee… |\n" +
327327
"+------+\n"));
328328
}
329329

0 commit comments

Comments
 (0)