We have some methods that output a lot of coloured text to the Console.
It s actually a menu that is built by looping through a collection of data.
Because we are writing item by item (and one line contains many items in different colours), this process is rather slow on low-end and mid-end machines. On those machines you can see each line being written one by one and it s rather frustrating for the end user.
This menu has to be displayed many times so I m wondering if I can t just "cache" this output somehow. If there was no coloured text I d simply store the output in a string and write it in one go, but I don t want to lose colour information.
Any suggestions?
Update: Just to give an idea of how intensive the output is: Update 2: Updated the sloppy code, but still want to buffer the output somehow. MoveBufferArea proves to be a partial solution (it creates unwanted scrollbars)
DefaultBanner();
WriteLine("Available tests:
", 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("
(");
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
(");
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("
Your selection: ");
int command = 0;
while (!ConsoleReader<int>.TryReadValueInRange(1, items.Count + 6,out command));
return command;
The Write methods are simply helper methods that encapsulate some behaviour of the System.Console class so we wouldn t have to keep setting the colour.