Revision: 59074
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at August 16, 2012 08:30 by lookitstony
Initial Code
using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; namespace CodeGenerator.Utilities { public class Write { public const ConsoleColor Statement = ConsoleColor.White; public const ConsoleColor Note = ConsoleColor.Gray; public const ConsoleColor Title = ConsoleColor.Yellow; public const ConsoleColor Question = ConsoleColor.White; public const ConsoleColor Answer = ConsoleColor.Green; public const ConsoleColor Error = ConsoleColor.Red; public const ConsoleColor Background = ConsoleColor.Black; public static void Line(string text, ConsoleColor forecolor = Statement, ConsoleColor backcolor = Background) { SetColors(forecolor, backcolor); Console.WriteLine(text); Console.ResetColor(); } public static string Input(string text, ConsoleColor questionForecolor = Question, ConsoleColor questionBackcolor = Background, ConsoleColor inputForecolor = Answer, ConsoleColor inputBackcolor = Background) { SetColors(questionForecolor,questionBackcolor); Console.Write(text + " "); SetColors(inputForecolor, inputBackcolor); var answer = Console.ReadLine(); Console.ResetColor(); return answer; } public static bool BoolInput(string text, ConsoleColor questionForecolor = Question, ConsoleColor questionBackcolor = Background, ConsoleColor inputForecolor = Answer, ConsoleColor inputBackcolor = Background) { SetColors(questionForecolor,questionBackcolor); Console.Write(text + " "); SetColors(Note); Console.Write("(y/n) "); SetColors(inputForecolor, inputBackcolor); var answer = Console.ReadLine() ?? "N"; Console.ResetColor(); return answer.ToLower() == "y"; } public static void Value(string key, string value, string seperator = " - ", ConsoleColor keyForecolor = Statement, ConsoleColor keyBackcolor = Background, ConsoleColor valueForecolor = Answer, ConsoleColor valueBackcolor = Background) { SetColors(keyForecolor, keyBackcolor); Console.Write(key); Console.Write(seperator); Line(value, valueForecolor,valueBackcolor); } public static string Options(string[] options, string question = null) { for (var i = 0; i < options.Count(); i++) { Value(" " + (i+1).ToString(CultureInfo.InvariantCulture), options[i],". "); } Blank(); var answer = Input( question != null ? question + "[1-" + options.Count() + "]" : "Please choose an option:[1-" + options.Count() + "]"); return answer; } public static void Blank() { Console.WriteLine(); } public static void SetColors(ConsoleColor foreground = Statement, ConsoleColor background = Background) { Console.ForegroundColor = foreground; Console.BackgroundColor = background; } } }
Initial URL
Initial Description
Helps write data to the console screen.
Initial Title
Console Write Utility
Initial Tags
c#
Initial Language
C#