We have some methods that output a lot of colored text to the Console.
This is actually a menu that is created by cyclic data collection.
Since we write an element by element (and one line contains many elements in different colors), this process is rather slow on low-performance and medium-sized machines. On these machines, you can see each line written one by one, and this is rather unpleasant for the end user.
This menu should be displayed many times, so I wonder if I can somehow "cache" this output. If there wasn’t color text, I would just save the output in a line and write it at a time, but I don’t want to lose color information.
Any suggestions?
Update: Just to give an idea of how intense the output is: Update 2: The sloppy code has been updated, but you still need to somehow drown out the output. MoveBufferArea is a partial solution (creates unwanted scrollbars)
DefaultBanner(); WriteLine("Available tests:\n", ConsoleColor.White); var methodNames = methods.Select(m => ((TestAttribute)m.GetCustomAttributes(false)[0]).Name).ToArray(); int vertical = 0; for (int i = 1; i <= methods.Length; i++) { if (i > methods.Length / 2) { Console.SetCursorPosition(40, 4 + vertical++); } Write("("); Write(i, ConsoleColor.Yellow); WriteLine(") {0:00}", methodNames[i - 1]); } Write("\n("); Write(items.Count + 1, ConsoleColor.Yellow); Write(") Set address | ("); Write(items.Count + 2, ConsoleColor.Yellow); Write(") View Log | ("); Write(items.Count + 3, ConsoleColor.Yellow); Write(") Open Log directory \n("); Write(items.Count + 4, ConsoleColor.Yellow); Write(") Open configuration | ("); Write(items.Count + 5, ConsoleColor.Yellow); Write(") View current configuration | ("); Write(items.Count + 6, ConsoleColor.Yellow); WriteLine(") Quit"); Write("\nYour selection: "); int command = 0; while (!ConsoleReader<int>.TryReadValueInRange(1, items.Count + 6,out command)); return command;
Writing methods are just helper methods that encapsulate any behavior of the System.Console class, so we won’t need to set the color.
source share