https://github.com/vbfox/coloredprintf
F# printf functions but with colors !
https://github.com/vbfox/coloredprintf
color fsharp printf
Last synced: about 2 months ago
JSON representation
F# printf functions but with colors !
- Host: GitHub
- URL: https://github.com/vbfox/coloredprintf
- Owner: vbfox
- License: mit
- Created: 2016-10-08T13:54:58.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-09-05T22:01:28.000Z (8 months ago)
- Last Synced: 2025-02-26T13:07:59.517Z (2 months ago)
- Topics: color, fsharp, printf
- Language: F#
- Homepage:
- Size: 319 KB
- Stars: 48
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
- License: License.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Colored Printf

[](https://github.com/vbfox/ColoredPrintf/actions/workflows/main.yml?query=branch%3Amaster)
[](https://www.nuget.org/packages/BlackFox.ColoredPrintf)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](https://docs.microsoft.com/en-us/dotnet/api/system.consolecolor) enum.
## Examples
```fsharp
// 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 :

## Thanks
* [Newaita icon pack](https://github.com/cbrnix/Newaita) for the base of the icon (License: [CC BY-NC-SA 3.0]