or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-8/

Terminal Status Message Formatter

Build a status message formatter for a CLI application that displays richly formatted status messages with nested colors and text styles.

Requirements

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.

Status Object Structure

The status object has the following properties:

  • type: one of "success", "error", "warning", or "info"
  • operation: a string describing what operation was performed
  • details: an optional string with additional details
  • highlight: an optional string within the details that should be emphasized

Formatting Requirements

The function should format messages as: [LABEL]: [operation] - [details]

  1. Success messages should have:

    • The entire message in green text
    • "SUCCESS" label in bright green
    • The operation name in bold (while maintaining green color)
  2. Error messages should have:

    • The entire message in red text
    • "ERROR" label in bright red
    • The operation name in bold (while maintaining red color)
  3. Warning messages should have:

    • The entire message in yellow text
    • "WARNING" label in bright yellow
    • The operation name in bold (while maintaining yellow color)
  4. Info messages should have:

    • The entire message in cyan text
    • "INFO" label in bright cyan
    • The operation name in bold (while maintaining cyan color)
  5. When highlight is provided, replace that text in the details with underlined formatting while maintaining the message color

Example Output Format

For a success message with operation "File saved", details "Saved to output.txt", and highlight "output.txt":

SUCCESS: File saved - Saved to output.txt

Where:

  • The entire message is green text
  • "SUCCESS" is bright green
  • "File saved" is bold (and green)
  • "output.txt" is underlined (and green)

Test Cases

  • 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

Implementation

@generates

API

/**
 * 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 };

Dependencies { .dependencies }

picocolors { .dependency }

Provides terminal color formatting with ANSI codes.