Skip to content

To offer built-in color output as option #692

@oscard0m

Description

@oscard0m

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions