mirror of
https://gitee.com/dcren/initializr.git
synced 2025-12-17 17:41:31 +08:00
Add empty line when content is wrapped
See gh-984
This commit is contained in:
committed by
Stephane Nicoll
parent
ff6e26463b
commit
76e6271e8e
@@ -21,6 +21,7 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -141,7 +142,7 @@ public class CommandLineHelpGenerator {
|
|||||||
data[2] = (String) defaults.get(id);
|
data[2] = (String) defaults.get(id);
|
||||||
parameterTable[i++] = data;
|
parameterTable[i++] = data;
|
||||||
}
|
}
|
||||||
model.put("parameters", TableGenerator.generate(parameterTable, false, this.maxColumnWidth));
|
model.put("parameters", TableGenerator.generate(parameterTable, this.maxColumnWidth));
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
@@ -165,7 +166,7 @@ public class CommandLineHelpGenerator {
|
|||||||
data[2] = (String) defaults.get(id);
|
data[2] = (String) defaults.get(id);
|
||||||
parameterTable[i++] = data;
|
parameterTable[i++] = data;
|
||||||
}
|
}
|
||||||
model.put("parameters", TableGenerator.generate(parameterTable, false, this.maxColumnWidth));
|
model.put("parameters", TableGenerator.generate(parameterTable, this.maxColumnWidth));
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +182,7 @@ public class CommandLineHelpGenerator {
|
|||||||
data[2] = dep.getVersionRequirement();
|
data[2] = dep.getVersionRequirement();
|
||||||
dependencyTable[i++] = data;
|
dependencyTable[i++] = data;
|
||||||
}
|
}
|
||||||
return TableGenerator.generate(dependencyTable, true, this.maxColumnWidth);
|
return TableGenerator.generate(dependencyTable, this.maxColumnWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String generateTypeTable(InitializrMetadata metadata, String linkHeader, boolean addTags) {
|
protected String generateTypeTable(InitializrMetadata metadata, String linkHeader, boolean addTags) {
|
||||||
@@ -203,7 +204,7 @@ public class CommandLineHelpGenerator {
|
|||||||
}
|
}
|
||||||
typeTable[i++] = data;
|
typeTable[i++] = data;
|
||||||
}
|
}
|
||||||
return TableGenerator.generate(typeTable, false, this.maxColumnWidth);
|
return TableGenerator.generate(typeTable, this.maxColumnWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map<String, Object> buildParametersDescription(InitializrMetadata metadata) {
|
protected Map<String, Object> buildParametersDescription(InitializrMetadata metadata) {
|
||||||
@@ -240,18 +241,26 @@ public class CommandLineHelpGenerator {
|
|||||||
* The {@code content} is a two-dimensional array holding the rows of the table.
|
* The {@code content} is a two-dimensional array holding the rows of the table.
|
||||||
* The first entry holds the header of the table.
|
* The first entry holds the header of the table.
|
||||||
* @param content the table content
|
* @param content the table content
|
||||||
* @param emptyRow add an empty row separator
|
|
||||||
* @param maxWidth the width bound for each column
|
* @param maxWidth the width bound for each column
|
||||||
* @return the generated table
|
* @return the generated table
|
||||||
*/
|
*/
|
||||||
static String generate(String[][] content, boolean emptyRow, int maxWidth) {
|
static String generate(String[][] content, int maxWidth) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
boolean emptyRow = false;
|
||||||
int[] columnsLength = computeColumnsLength(content, maxWidth);
|
int[] columnsLength = computeColumnsLength(content, maxWidth);
|
||||||
|
List<List<String[]>> formattedContent = new LinkedList<>();
|
||||||
|
for (int i = 0; i < content.length; i++) {
|
||||||
|
List<String[]> rows = computeRow(content, i, maxWidth);
|
||||||
|
formattedContent.add(rows);
|
||||||
|
if (rows.size() > 1) {
|
||||||
|
emptyRow = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
appendTableSeparation(sb, columnsLength);
|
appendTableSeparation(sb, columnsLength);
|
||||||
appendRow(sb, content, columnsLength, 0, maxWidth); // Headers
|
appendRow(sb, formattedContent, columnsLength, 0); // Headers
|
||||||
appendTableSeparation(sb, columnsLength);
|
appendTableSeparation(sb, columnsLength);
|
||||||
for (int i = 1; i < content.length; i++) {
|
for (int i = 1; i < formattedContent.size(); i++) {
|
||||||
appendRow(sb, content, columnsLength, i, maxWidth);
|
appendRow(sb, formattedContent, columnsLength, i);
|
||||||
if (emptyRow && i < content.length - 1) {
|
if (emptyRow && i < content.length - 1) {
|
||||||
appendEmptyRow(sb, columnsLength);
|
appendEmptyRow(sb, columnsLength);
|
||||||
}
|
}
|
||||||
@@ -260,10 +269,9 @@ public class CommandLineHelpGenerator {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void appendRow(StringBuilder sb, String[][] content, int[] columnsLength, int rowIndex,
|
private static void appendRow(StringBuilder sb, List<List<String[]>> formattedContent, int[] columnsLength,
|
||||||
int maxWidth) {
|
int rowIndex) {
|
||||||
String[] line = content[rowIndex];
|
List<String[]> rows = formattedContent.get(rowIndex);
|
||||||
List<String[]> rows = HelpFormatter.format(line, maxWidth);
|
|
||||||
for (String[] row : rows) {
|
for (String[] row : rows) {
|
||||||
for (int i = 0; i < row.length; i++) {
|
for (int i = 0; i < row.length; i++) {
|
||||||
sb.append("| ").append(fill(row[i], columnsLength[i])).append(" ");
|
sb.append("| ").append(fill(row[i], columnsLength[i])).append(" ");
|
||||||
@@ -273,6 +281,12 @@ public class CommandLineHelpGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<String[]> computeRow(String[][] content, int rowIndex, int maxWidth) {
|
||||||
|
String[] line = content[rowIndex];
|
||||||
|
List<String[]> row = HelpFormatter.format(line, maxWidth);
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
private static void appendEmptyRow(StringBuilder sb, int[] columnsLength) {
|
private static void appendEmptyRow(StringBuilder sb, int[] columnsLength) {
|
||||||
for (int columnLength : columnsLength) {
|
for (int columnLength : columnsLength) {
|
||||||
sb.append("| ").append(fill(null, columnLength)).append(" ");
|
sb.append("| ").append(fill(null, columnLength)).append(" ");
|
||||||
|
|||||||
Reference in New Issue
Block a user