From 1998000cf78db29a0a1a224b9699ab23cfed7c24 Mon Sep 17 00:00:00 2001 From: J-onasJones Date: Mon, 11 Mar 2024 19:27:57 +0100 Subject: [PATCH] Improved readability of token list --- .../web/api/v2/tokenmgr/TokenManager.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/jonasjones/mcwebserver/web/api/v2/tokenmgr/TokenManager.java b/src/main/java/me/jonasjones/mcwebserver/web/api/v2/tokenmgr/TokenManager.java index 91bdf3d..96a02c8 100644 --- a/src/main/java/me/jonasjones/mcwebserver/web/api/v2/tokenmgr/TokenManager.java +++ b/src/main/java/me/jonasjones/mcwebserver/web/api/v2/tokenmgr/TokenManager.java @@ -140,10 +140,34 @@ public static String listTokens() { if (tokens.size() == 0) { return "No active tokens."; } + int longestName = 0; + int longestExpires = 0; + for (Token token : tokens) { + if (token.getName().length() > longestName) { + longestName = token.getName().length(); + } + if (convertToHumanReadable(token.getExpires()).length() > longestExpires) { + longestExpires = convertToHumanReadable(token.getExpires()).length(); + } + } sb.append("Active Tokens:\n"); - sb.append("Name | Expiration Date | Beginning of Token value\n"); + sb.append("Name") + .append(" ".repeat(Math.max(longestName - 4, 0))) + .append(" | ").append("Expires") + .append(" ".repeat(Math.max(longestExpires - 6, 0))) + .append(" | TokenStart\n"); + sb.append("-".repeat(Math.max(longestName, 4))) + .append(" | ") + .append("-".repeat(Math.max(longestExpires, 7))) + .append(" | ") + .append("-".repeat(10)) + .append("\n"); for (Token token : tokens) { - sb.append(token.getName()).append(" | ").append(convertToHumanReadable(token.getExpires())).append(" | ").append(token.getTokenStart()).append("...").append("\n"); + String humanExpires = convertToHumanReadable(token.getExpires()); + sb.append(token.getName()) + .append(" ".repeat(Math.max(longestName - token.getName().length(), 4 - token.getName().length()))) + .append(" | ").append(humanExpires).append(" ".repeat(Math.max(longestExpires - humanExpires.length(), 7 - humanExpires.length()))) + .append(" | ").append(token.getTokenStart()).append("...").append("\n"); } return sb.toString(); }