diff --git a/package.json b/package.json index 7814fd4..8027faf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "server-console", - "version": "1.0.0", + "version": "1.0.1", "description": "An advanced control panel for Mindustry server.", "main": "./src/main-process/main.js", "license": "GPL-3.0-or-later", diff --git a/src/window/components/console/console.css b/src/window/components/console/console.css index f07732c..c63b9e8 100644 --- a/src/window/components/console/console.css +++ b/src/window/components/console/console.css @@ -5,6 +5,7 @@ margin-top: 30px; width: 70%; font-family: Consolas, sans-serif; + line-height: 1.6; } .command-line { diff --git a/src/window/styles/mindustry-colors.css b/src/window/styles/mindustry-colors.css index 1b75da8..3a27ba1 100644 --- a/src/window/styles/mindustry-colors.css +++ b/src/window/styles/mindustry-colors.css @@ -118,6 +118,14 @@ color: #b03060ff; } -.mindustry-I { +.mindustry-info { color: #2fa7d3; } + +.mindustry-warning { + color: #ffe046; +} + +.mindustry-error { + color: #fa8072ff; +} diff --git a/src/window/utils/color-parser.js b/src/window/utils/color-parser.js index dab2b21..cb28010 100644 --- a/src/window/utils/color-parser.js +++ b/src/window/utils/color-parser.js @@ -1,3 +1,7 @@ +/** + * @typedef {{string: string, color: string}|string} ColoredString - String with special color. + */ + /** * Regular expression for checking colored strings. * @type {RegExp} @@ -51,16 +55,32 @@ function getHexColoredString(str, hexColor) { /** * Check color in the string. * @param {string} str - String to be checked. - * @returns {{str: string, color: string}|string} - Object with string and color. + * @returns {ColoredString} - Object with string and color. */ function checkColor(str) { for (let i = 1; i < str.length; i++) { if (str.charAt(i) === ']') { - const color = str.substring(1, i); - return { str: str.substring(i + 1), color }; + const string = str.substring(i + 1); + let color = str.substring(1, i); + + // Parse log colors. + switch (color) { + case 'I': + color = 'info'; + break; + case 'E': + color = 'error'; + break; + case 'W': + color = 'warning'; + break; + default: + break; + } + return { string, color }; } } - return str; + return { string: str, color: 'white' }; } /** @@ -82,17 +102,18 @@ function parseName(rawName) { if (name.charAt(i) === '[' && i !== name.length - 1 && name.charAt(i + 1) !== '[' && (i === 0 || name.charAt(i - 1) !== '[')) { coloring = true; const next = name.substring(i); - const result = checkColor(next); - for (let j = 0; j < result.str.length; j++) { - if (result.str.split('')[j] === '[') { - result.str = result.str.split('').slice(0, j).join(''); + // eslint-disable-next-line prefer-const + let { string, color } = checkColor(next); + for (let j = 0; j < string.length; j++) { + if (string.split('')[j] === '[') { + string = string.split('').slice(0, j).join(''); break; } } - result.str.replace(colorRegex, ''); - const coloredString = isHex(result.color) - ? getHexColoredString(result.str, result.color) - : getColoredString(result.str, result.color); + string.replace(colorRegex, ''); + const coloredString = isHex(color) + ? getHexColoredString(string, color) + : getColoredString(string, color); coloredStrings.push(coloredString); } else if (!coloring) { const whiteString = getColoredString(name.charAt(i), 'white'); diff --git a/src/window/utils/os-utils.js b/src/window/utils/os-utils.js index cb2632b..fc40e54 100644 --- a/src/window/utils/os-utils.js +++ b/src/window/utils/os-utils.js @@ -33,7 +33,7 @@ function cpuUsagePercent() { const totalDiff = endTotal - startTotal; const idleDiff = endIdle - startIdle; - const percent = Math.round((100 - 100 * (idleDiff / totalDiff)) * 10) / 10; + const percent = Math.round(1000 - 1000 * (idleDiff / totalDiff)) / 10; resolve(percent); }, 1000);