-
Notifications
You must be signed in to change notification settings - Fork 3
Colors #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wolfy1339
wants to merge
16
commits into
master
Choose a base branch
from
colors
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Colors #25
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
644a377
Add color utils
wolfy1339 dc3a9ab
Add implentation to the IRC wrappers
wolfy1339 f9d0551
Fix typo in JSDoc comments
wolfy1339 b07f640
Move logic for styling a message to it's own function
wolfy1339 bbe7598
Fix some problems related to undefined variables
wolfy1339 cdde1a5
Colours should be included in the total message length
wolfy1339 fe3dd5e
Stylistic improvements to color utils
wolfy1339 d26c4cb
Fix irc.reply()
wolfy1339 e07e51f
Fix: Use the right function name for upper case
wolfy1339 d1351a9
Fix setting backgrounds
wolfy1339 dfd1b20
Fix rainbow
wolfy1339 ecdf00c
Add a proof of concept for a new color class
wolfy1339 45421e5
Remove methods not needed anymore
wolfy1339 e508704
Actually make class work
wolfy1339 25aed04
Fix a double return
wolfy1339 ab19d71
Merge branch 'master' into colors
wolfy1339 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,230 @@ | ||
| const colors = { | ||
| WHITE: '\x0300', | ||
| BLACK: '\x0301', | ||
| NAVY: '\x0302', | ||
| GREEN: '\x0303', | ||
| RED: '\x0304', | ||
| BROWN: '\x0305', | ||
| MAROON: '\x0305', | ||
| PURPLE: '\x0306', | ||
| VIOLET: '\x0306', | ||
| ORANGE: '\x0307', | ||
| YELLOW: '\x0308', | ||
| LIGHTGREEN: '\x0309', | ||
| LIME: '\x0309', | ||
| TEAL: '\x0310', | ||
| BLUECYAN: '\x0310', | ||
| CYAN: '\x0311', | ||
| AQUA: '\x0311', | ||
| BLUE: '\x0312', | ||
| ROYAL: '\x0312', | ||
| LIGHTPURPLE: '\x0313', | ||
| PINK: '\x0313', | ||
| FUCHSIA: '\x0313', | ||
| GREY: '\x0314', | ||
| GRAY: '\x0314', | ||
| LIGHTGRAY: '\x0315', | ||
| LIGHTGREY: '\x0315', | ||
| SILVER: '\x0315', | ||
|
|
||
| NORMAL: '\x0F', | ||
| UNDERLINE: '\x1F', | ||
| BOLD: '\x02', | ||
| ITALIC: '\x1D', | ||
| REVERSE: '\u202E' | ||
| }; | ||
|
|
||
| const _rainbow = ['red', 'orange', 'yellow', 'green', 'blue', 'navy', 'violet']; | ||
|
|
||
| /** | ||
| * Colors a message | ||
| */ | ||
| class Color extends String { | ||
| /** | ||
| * @param {string} message - The message you want to add rainbow colors too | ||
| */ | ||
| constructor(message) { | ||
| super(message); | ||
| } | ||
|
|
||
| white() { | ||
| return new Color(`${colors.WHITE}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| black() { | ||
| return new Color(`${colors.BLACK}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| navy() { | ||
| return new Color(`${colors.NAVY}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| green() { | ||
| return new Color(`${colors.GREEN}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| red() { | ||
| return new Color(`${colors.RED}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| brown() { | ||
| return new Color(`${colors.BROWN}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| maroon() { | ||
| return new Color(`${colors.MAROON}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| purple() { | ||
| return new Color(`${colors.PURPLE}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| violet() { | ||
| return new Color(`${colors.VIOLET}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| orange() { | ||
| return new Color(`${colors.ORANGE}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| yellow() { | ||
| return new Color(`${colors.YELLOW}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| lightgreen() { | ||
| return new Color(`${colors.LIGHTGREEN}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| lime() { | ||
| return new Color(`${colors.LIME}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| teal() { | ||
| return new Color(`${colors.TEAL}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| bluecyan() { | ||
| return new Color(`${colors.BLUECYAN}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| cyan() { | ||
| return new Color(`${colors.CYAN}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| aqua() { | ||
| return new Color(`${colors.AQUA}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| blue() { | ||
| return new Color(`${colors.BLUE}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| royal() { | ||
| return new Color(`${colors.ROYAL}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| lightpurple() { | ||
| return new Color(`${colors.LIGHTPURPLE}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| pink() { | ||
| return new Color(`${colors.PINK}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| fuchsia() { | ||
| return new Color(`${colors.FUCHSIA}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| grey() { | ||
| return new Color(`${colors.GREY}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| gray() { | ||
| return new Color(`${colors.GRAY}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| lightgray() { | ||
| return new Color(`${colors.LIGHTGRAY}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| lightgrey() { | ||
| return new Color(`${colors.LIGHTGREY}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| silver() { | ||
| return new Color(`${colors.SILVER}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
|
|
||
| bold() { | ||
| return new Color(`${colors.BOLD}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| italic() { | ||
| return new Color(`${colors.ITALIC}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| underline() { | ||
| return new Color(`${colors.UNDERLINE}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| reverse() { | ||
| return new Color(`${colors.ITALIC}${this}${colors.NORMAL}`); | ||
| } | ||
|
|
||
| /** | ||
| * Colors a message with rainbow colors | ||
| * @return {string} - Returns your message returned with rainbow coloring | ||
| */ | ||
| rainbow() { | ||
| let i = 0; | ||
| let colored = ''; | ||
|
|
||
| for (let character of this) { | ||
| if (i > (_rainbow.length - 1)) // We substract one because i starts at 0 and rainbow.length at 1 | ||
| i = 0; | ||
|
|
||
| colored += `${colors[_rainbow[i].toUpperCase()]}${character}`; | ||
| i += 1; | ||
| } | ||
|
|
||
| return new Color(colored.concat('\x0F')); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Colors a message with rainbow colors | ||
| * @param {string} msg - The message you want to add rainbow colors too | ||
| * @param {string} bg - The message you want to add rainbow colors too | ||
| * @return {string} - Returns your message returned with rainbow coloring | ||
| */ | ||
| function add_background(msg, bg) { | ||
| let c = msg.indexOf('\x03') !== -1; | ||
|
|
||
| if (c && bg !== null) { | ||
| return `${msg.slice(0, 3)},${colors[bg.toUpperCase()].slice(1)}${msg.slice(3)}`; | ||
| } else if (!c && bg !== null) { | ||
| return `${colors.BLACK},${colors[bg.toUpperCase()].slice(1)}${msg}\x0F`; | ||
| } else if (bg === null) { | ||
| return msg; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| function addStyling(msg, background, rainbow, style) { | ||
| let myRe = /\${(\w+)}/g; | ||
| let myArray; | ||
|
|
||
| while ((myArray = myRe.exec(msg)) !== null) { | ||
| msg.replace(myArray[0], colors[myArray[1]]); | ||
| } | ||
|
|
||
| return ((...args)=>{})(add_background(msg, background), style); | ||
| } | ||
|
|
||
| module.exports = { | ||
| Color, | ||
| colors, | ||
| add_background, | ||
| addStyling | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be better for plugins/root to add colours to the message before calling message functions with it hence the extra three arguments wouldn't be necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it would be nice if colours were provided as a util. Maybe something like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't know how to do that kind of function, with the chained functions