Skip to content

Instantly share code, notes, and snippets.

@devhawk
Created August 4, 2016 17:19
Show Gist options
  • Save devhawk/4719d1b369170b206cd88b9da16e1b8a to your computer and use it in GitHub Desktop.
Save devhawk/4719d1b369170b206cd88b9da16e1b8a to your computer and use it in GitHub Desktop.
F# Color Console Functions
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