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

Commit

Permalink
Color parser fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
antsif-a committed Jul 24, 2020
1 parent 30c8bd7 commit e400de0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/window/components/console/console.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { getCurrentWindow } = require('electron').remote;
const { ipcRenderer } = require('electron');

const Titlebar = require('../titlebar/titlebar');
const Menu = require('../menu/menu');
const Players = require('../players/players');
Expand Down
15 changes: 15 additions & 0 deletions src/window/utils/color-parser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
/**
* Regular expression for checking colored strings.
* @type {RegExp}
*/
const colorRegex = /\[(\w)+]/g;

/**
* Regular expression for checking HEX colors.
* @type {RegExp}
*/
const hexRegex = /[0-9A-Fa-f]{6}/;

/**
Expand Down Expand Up @@ -67,8 +76,11 @@ function parseName(rawName) {
}

const coloredStrings = [];
let coloring = false;

for (let i = 0; i < name.length; i++) {
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++) {
Expand All @@ -82,6 +94,9 @@ function parseName(rawName) {
? getHexColoredString(result.str, result.color)
: getColoredString(result.str, result.color);
coloredStrings.push(coloredString);
} else if (!coloring) {
const whiteString = getColoredString(name.charAt(i), 'white');
coloredStrings.push(whiteString);
}
}
return `<div class="colored">${coloredStrings.join('')}</div>`;
Expand Down
11 changes: 9 additions & 2 deletions src/window/window.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,15 @@

<div class="command-line">
<label for="console-input">></label>
<input autofocus class="command-line-input" id="console-input" type="text">
<gear-icon size="20px" class="console-settings"></gear-icon>
<input
autofocus
class="command-line-input"
id="console-input"
type="text"
placeholder="..."
>
<!-- TODO: Settings page
<gear-icon size="20px" class="console-settings-button" id="console-settings-button"></gear-icon> -->
</div>
</div>
</body>
Expand Down

0 comments on commit e400de0

Please sign in to comment.