public static ChangeConsoleColor To(ConsoleColor foreground, ConsoleColor background) { var restoreOriginal = new ChangeConsoleColor(); Console.BackgroundColor = background; Console.ForegroundColor = foreground; return(restoreOriginal); }
static int Main(string[] args) { var parser = new Parser(with => with.HelpWriter = Console.Out); var result = parser.ParseArguments < CrunchOptions, GenOptions> (args); try { result .WithParsed <CrunchOptions>(opts => Crunch(opts)) .WithParsed <GenOptions>(opts => Gen(opts)); return(0); } catch (Exception exception) { using (ChangeConsoleColor.To(ConsoleColor.Black, ConsoleColor.Yellow)) Console.Error.WriteLine(exception.Message); using (ChangeConsoleColor.To(ConsoleColor.Yellow, ConsoleColor.Black)) Console.Error.WriteLine(exception.StackTrace); return(-1); } }