Skip to content

Commit 2571851

Browse files
Format the description of a studio to remove line breaks to increase readability (#488)
* Format the description of a studio to remove line breaks to increase readability * Update src/main/java/io/seqera/tower/cli/utils/FormatHelper.java Co-authored-by: Endre Sükösd <148096496+endre-seqera@users.noreply.github.com> --------- Co-authored-by: Endre Sükösd <148096496+endre-seqera@users.noreply.github.com>
1 parent 2058dd5 commit 2571851

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/main/java/io/seqera/tower/cli/responses/studios/StudiosList.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import io.seqera.tower.model.DataStudioStatusInfo;
3131
import io.seqera.tower.model.StudioUser;
3232

33+
import static io.seqera.tower.cli.utils.FormatHelper.formatDescription;
3334
import static io.seqera.tower.cli.utils.FormatHelper.formatStudioStatus;
3435

3536
public class StudiosList extends Response {
@@ -67,10 +68,10 @@ public void toString(PrintWriter out) {
6768
DataStudioStatusInfo statusInfo = studio.getStatusInfo();
6869
StudioUser user = studio.getUser();
6970
List<String> rows = new ArrayList<>(List.of(
70-
studio.getSessionId() == null ? "" : studio.getSessionId(),
71-
studio.getName() == null ? "" : studio.getName(),
72-
studio.getDescription() == null ? "" : studio.getDescription(),
73-
user == null ? "" : user.getUserName(),
71+
studio.getSessionId() == null ? "NA" : studio.getSessionId(),
72+
studio.getName() == null ? "NA" : studio.getName(),
73+
formatDescription(studio.getDescription(), 100),
74+
user == null ? "NA" : user.getUserName(),
7475
formatStudioStatus(statusInfo == null ? null : statusInfo.getStatus())
7576
));
7677

src/main/java/io/seqera/tower/cli/responses/studios/StudiosView.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import java.io.PrintWriter;
2929

30+
import static io.seqera.tower.cli.utils.FormatHelper.formatDescription;
3031
import static io.seqera.tower.cli.utils.FormatHelper.formatStudioStatus;
3132
import static io.seqera.tower.cli.utils.FormatHelper.formatTime;
3233

@@ -54,7 +55,7 @@ public void toString(PrintWriter out){
5455
table.addRow("Status", formatStudioStatus(statusInfo == null ? null : statusInfo.getStatus()));
5556
table.addRow("Status last update", statusInfo == null ? "NA" : formatTime(statusInfo.getLastUpdate()));
5657
table.addRow("Studio URL", studio.getStudioUrl());
57-
table.addRow("Description", studio.getDescription());
58+
table.addRow("Description", formatDescription(studio.getDescription(), 100));
5859
table.addRow("Created on", formatTime(studio.getDateCreated()));
5960
table.addRow("Created by", studioUser == null ? "NA" : String.format("%s | %s",studioUser.getUserName(), studioUser.getEmail()));
6061
table.addRow("Template", studio.getTemplate() == null ? "NA" : studio.getTemplate().getRepository());

src/main/java/io/seqera/tower/cli/utils/FormatHelper.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,19 @@ public static String formatLabels(java.util.List<io.seqera.tower.model.LabelDbDt
334334
.collect(Collectors.joining(","));
335335
}
336336

337+
public static String formatDescription(String description) {
338+
return formatDescription(description, 2048);
339+
}
340+
341+
public static String formatDescription(String description, int maxLength) {
342+
if (description == null) {
343+
return "NA";
344+
}
345+
346+
// remove line breaks
347+
var text = description.trim().replace("\n", " ").replace("\r", " ");
348+
// cap the description length if too long
349+
return text.length() > maxLength ? text.substring(0, maxLength) + "..." : text;
350+
}
351+
337352
}

0 commit comments

Comments
 (0)