Skip to content

diverger/formatText-cmake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CMake Text Formatting Utilities

A CMake module providing ANSI text formatting capabilities for colored and styled terminal output.

Features

  • Text formatting: Bold, dim, italic, underline, blink, reverse, hidden, strike
  • Foreground colors: 16 standard colors (8 normal + 8 bright)
  • Background colors: 16 standard colors (8 normal + 8 bright)
  • Combined formatting: Mix multiple styles and colors
  • Chained output: Build formatted strings from multiple segments
  • Cross-platform: Works on both Unix and Windows (with ANSI support)

Installation

  1. Copy formatText.cmake to your project's CMake modules directory
  2. Include it in your CMakeLists.txt:
include(formatText.cmake)

Usage Examples

Basic Formatting

# Single formatted message
MessageWithFormat(FORM ${FORM_BOLD} FORE ${FORE_RED} "Error: Something went wrong!")

# Store formatted text in variable
formatText(FORM ${FORM_UNDERLINE} FORE ${FORE_BLUE} "Important notice")
message("${formatted_text}")

Combined Formatting

# Bold and italic red text
formatText(FORM ${FORM_BOLD} ${FORM_ITALIC} FORE ${FORE_RED} "Critical warning!")
message("${formatted_text}")

Chained Formatting

# Build a message with multiple formats
formatTextChain(FORM ${FORM_BOLD} FORE ${FORE_GREEN} "Status: ")
formatTextChain(FORM ${FORM_ITALIC} FORE ${FORE_YELLOW} "Running")
formatTextChain(FORM ${FORM_DEFAULT} FORE ${FORE_DEFAULT} " (")
formatTextChain(FORM ${FORM_BOLD} FORE ${FORE_CYAN} "OK")
formatTextChain(FORM ${FORM_DEFAULT} FORE ${FORE_DEFAULT} ")")
message("${formatted_text_chained}")

Background Colors

# Text with background color
formatText(FORE ${FORE_WHITE} BACK ${BACK_RED} " ALERT ")
message("${formatted_text}")

Break the format chain

Use 'formatTextChainBreak' to break the format chain and reset to default.

formatTextChainBreak()
formatTextchain(FORM ${FORM_REVERSE} ${FORM_BOLD} FORE ${FORE_YELLOW} "Warning: ")
message("${formatted_text_chained}")

The output will be like this:

alt text

License

MIT License - See LICENSE file for details.

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages