Skip to content
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

To offer built-in color output as option #692

Open
oscard0m opened this issue Jan 16, 2021 · 0 comments
Open

To offer built-in color output as option #692

oscard0m opened this issue Jan 16, 2021 · 0 comments
Labels
core enhancement New feature or request

Comments

@oscard0m
Copy link

Describe the enhancement
After color output improvements (link and #583) I think it could be interesting to integrate to this toolkit, as an option disabled by default, color output for the following methods

export function debug(message: string): void {
issueCommand('debug', {}, message)
}
/**
* Adds an error issue
* @param message error issue message. Errors will be converted to string via toString()
*/
export function error(message: string | Error): void {
issue('error', message instanceof Error ? message.toString() : message)
}
/**
* Adds an warning issue
* @param message warning issue message. Errors will be converted to string via toString()
*/
export function warning(message: string | Error): void {
issue('warning', message instanceof Error ? message.toString() : message)
}
/**
* Writes info to log with console.log.
* @param message info message
*/
export function info(message: string): void {
process.stdout.write(message + os.EOL)
}

Code Snippet

Current

export function issue(name: string, message: string = ''): void {
issueCommand(name, {}, message)
}

Change Proposal

import { red, yellow } from 'whatever-lib-to-color-output'

const logColors = {
	error: red,
    warning: yellow
}

...

function issue(name: string, message: string = '', useColoredMessage: boolean = false): void {
	if(!useColoredMessage) issueCommand(name, {}, message)
	else {
		const paintMessage = logColors[name]
		const paintedMessage = paintMessage? paintMessage(message) : message

		issueCommand(name, {}, paintMessage(paintedMessage))
	}
}

Additional information
Here are some comparisons for some packages for coloring the output:

In case this feature has sense, I guess it will need to be discussed how and which external package or internal utility to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants