Beispiel #1
0
 public static string ReadLine(this ColorConsole console, string prompt, ConsoleColor foregroundColor, ConsoleColor backgroundColor = ConsoleColor.Black, bool intercept = false, char echo = '*')
 {
     lock (readGate) {
         console.Write(prompt, foregroundColor, backgroundColor);
         if (!intercept)
         {
             return(System.Console.ReadLine());
         }
         else
         {
             int            left = System.Console.CursorLeft;
             StringBuilder  sb   = new StringBuilder();
             ConsoleKeyInfo keyInfo;
             while ((keyInfo = System.Console.ReadKey(intercept)).Key != ConsoleKey.Enter)
             {
                 if (ConsoleKey.LeftArrow == keyInfo.Key || ConsoleKey.RightArrow == keyInfo.Key)
                 {
                     continue;
                 }
                 if (ConsoleKey.Backspace == keyInfo.Key)
                 {
                     if (System.Console.CursorLeft > left)
                     {
                         console.Write("\b \b"); if (sb.Length > 0)
                         {
                             sb.Remove(sb.Length - 1, 1);
                         }
                     }
                     continue;
                 }
                 System.Console.Write(echo); sb.Append(keyInfo.KeyChar);
             }
             ;
             console.WriteLineBlank();
             return(sb.ToString());
         }
     }
 }