docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a status message formatter for a CLI application that displays richly formatted status messages with nested colors and text styles.
Create a module that exports a formatStatus function that takes a status object and returns a formatted string suitable for terminal output. The function should handle multiple status types and display them with appropriate colors and formatting.
The status object has the following properties:
type: one of "success", "error", "warning", or "info"operation: a string describing what operation was performeddetails: an optional string with additional detailshighlight: an optional string within the details that should be emphasizedThe function should format messages as: [LABEL]: [operation] - [details]
Success messages should have:
Error messages should have:
Warning messages should have:
Info messages should have:
When highlight is provided, replace that text in the details with underlined formatting while maintaining the message color
For a success message with operation "File saved", details "Saved to output.txt", and highlight "output.txt":
SUCCESS: File saved - Saved to output.txtWhere:
When given a success status with operation "File saved" and details "Saved to output.txt", it returns a properly formatted green message with bold operation name @test
When given an error status with operation "Connection failed" and details "Could not reach server", it returns a properly formatted red message with bold operation name @test
When given a warning status with operation "Deprecated API" and details "This method will be removed in v2.0", it returns a properly formatted yellow message with bold operation name @test
When given an info status with operation "Build started" and details "Compiling 42 files", it returns a properly formatted cyan message with bold operation name @test
When given a status with a highlight field, the highlighted text within details is underlined while maintaining the message type's color @test
When given a status with nested formatting (bold operation within colored message, underlined highlight within that), all formatting is properly maintained without breaking @test
/**
* Formats a status message with colors and text styles for terminal output.
*
* @param {Object} status - The status object
* @param {string} status.type - The status type: "success", "error", "warning", or "info"
* @param {string} status.operation - Description of the operation
* @param {string} [status.details] - Optional additional details
* @param {string} [status.highlight] - Optional text within details to emphasize
* @returns {string} A formatted string with ANSI color codes
*/
function formatStatus(status) {
// IMPLEMENTATION HERE
}
module.exports = { formatStatus };Provides terminal color formatting with ANSI codes.