Skip to content
This repository has been archived by the owner on May 8, 2021. It is now read-only.

Commit

Permalink
1.0.1 patch
Browse files Browse the repository at this point in the history
  • Loading branch information
antsif-a committed Jul 25, 2020
1 parent 537e50a commit a444281
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/window/components/console/console.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
margin-top: 30px;
width: 70%;
font-family: Consolas, sans-serif;
line-height: 1.6;
}

.command-line {
Expand Down
10 changes: 9 additions & 1 deletion src/window/styles/mindustry-colors.css
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@
color: #b03060ff;
}

.mindustry-I {
.mindustry-info {
color: #2fa7d3;
}

.mindustry-warning {
color: #ffe046;
}

.mindustry-error {
color: #fa8072ff;
}
45 changes: 33 additions & 12 deletions src/window/utils/color-parser.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @typedef {{string: string, color: string}|string} ColoredString - String with special color.
*/

/**
* Regular expression for checking colored strings.
* @type {RegExp}
Expand Down Expand Up @@ -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' };
}

/**
Expand All @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/window/utils/os-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a444281

Please sign in to comment.