Created
August 4, 2016 17:19
-
-
Save devhawk/4719d1b369170b206cd88b9da16e1b8a to your computer and use it in GitHub Desktop.
F# Color Console Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
// helper function to set the console collor and automatically set it back when disposed | |
let consoleColor (fc : ConsoleColor) = | |
let current = Console.ForegroundColor | |
Console.ForegroundColor <- fc | |
{ new IDisposable with | |
member x.Dispose() = Console.ForegroundColor <- current } | |
// printf statements that allow user to specify output color | |
let cprintf color str = Printf.kprintf (fun s -> use c = consoleColor color in printf "%s" s) str | |
let cprintfn color str = Printf.kprintf (fun s -> use c = consoleColor color in printfn "%s" s) str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment