Skip to content

F# printf functions but with colors !

License

Notifications You must be signed in to change notification settings

vbfox/ColoredPrintf

Repository files navigation

Colored Printf

color drops Logo

Github Actions Status Nuget Package

This library provide a replacement to F# printf function with color support.

The syntax to set the color inside the string is $foreground;background[text] where both foreground and background are optional.

The supported colors are the one from the System.ConsoleColor enum.

Examples

// Change the color of part of a string
colorprintfn "$red[Hello] $white;red[world]."

// Use sprintf syntax
colorprintfn "Hello $green[%s]: %s" "user" "Welcome to color!"
colorprintfn "$white[Progress]: $yellow[%.2f%%] (Eta $yellow[%i] minutes)" 42.33 5

// Use interpolated strings
let life = "La vie"
let is_ = "est"
colorprintfn $"""$white;blue[%s{life} ]$black;white[{is_} ]$white;red[{"belle"}]"""

// Specify the colors from variables
let logColor = ConsoleColor.Yellow
colorprintfn "result: $%A[Hello world]" logColor
colorprintfn $"result: ${logColor}[Hello world]"

Displays :

Demo

Thanks