From 92f7d12c0e958a9d17f7ce8a23d1ea5622ac7064 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Fri, 29 Mar 2019 12:26:25 -0400 Subject: [PATCH] free output is now aligned and shows percent used --- src/Terminal.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Terminal.js b/src/Terminal.js index e41bb5125..87f15c181 100644 --- a/src/Terminal.js +++ b/src/Terminal.js @@ -1640,9 +1640,15 @@ let Terminal = { postError("Incorrect usage of free command. Usage: free"); return; } - post("Total: " + numeralWrapper.format(Player.getCurrentServer().maxRam, '0.00') + " GB"); - post("Used: " + numeralWrapper.format(Player.getCurrentServer().ramUsed, '0.00') + " GB"); - post("Available: " + numeralWrapper.format(Player.getCurrentServer().maxRam - Player.getCurrentServer().ramUsed, '0.00') + " GB"); + const ram = numeralWrapper.format(Player.getCurrentServer().maxRam, '0.00'); + const used = numeralWrapper.format(Player.getCurrentServer().ramUsed, '0.00'); + const avail = numeralWrapper.format(Player.getCurrentServer().maxRam - Player.getCurrentServer().ramUsed, '0.00'); + const maxLength = Math.max(ram.length, Math.max(used.length, avail.length)); + const usedPercent = numeralWrapper.format(Player.getCurrentServer().ramUsed/Player.getCurrentServer().maxRam*100, '0.00'); + + post(`Total: ${" ".repeat(maxLength-ram.length)}${ram} GB`); + post(`Used: ${" ".repeat(maxLength-used.length)}${used} GB (${usedPercent}%)`); + post(`Available: ${" ".repeat(maxLength-avail.length)}${avail} GB`); }, executeKillCommand: function(commandArray) {