Пример #1
0
 public void xg(int indnt, StreamWriter writer, ILoopCondition node, string msg)
 {
     indent(indnt, writer);
     if (msg != "")
     {
         writer.WriteLine(msg);
     }
     writer.Write("<ILoopCondition NodeId=\"" + node.UniqueId + "\" ParentId=\"" + node.ParentNode.UniqueId + "\">\n");
     PrintTerminals(indnt + 1, writer, node.Terminals);
     indent(indnt, writer);
     writer.Write("</ILoopCondition>\n");
 }
Пример #2
0
 /// <summary>
 /// Starts a loop that reads input from <see cref="Console"/>, parses (using <see cref="Parse(string)"/>), and invokes it asynchronously (using <see cref="HandleAsync(IParseResult, bool)"/>).
 /// Writes <paramref name="prompt"/> to the console as a prompt when it is ready for input, and will stop looping once <see cref="ILoopCondition.ShouldGo(string)"/> returns false.
 /// Any null strings received from inputs are not parsed, but still checked using <paramref name="condition"/>.
 /// </summary>
 /// <param name="prompt">The prompt to write, e.g. MyShell>.</param>
 /// <param name="condition">Loops based on this condition.</param>
 /// <param name="alwaysWriteHelpOnError">Always writes help when there is an error. If false, only writes help if an Error was <see cref="ErrorCode.HelpRequested"/>.</param>
 /// <param name="promptColor">The foreground color of <paramref name="prompt"/>.</param>
 /// <param name="commandColor">The foreground color of the text that the user enters after <paramref name="prompt"/> is written.</param>
 public async Task InputLoopAsync(string prompt, ILoopCondition condition, bool alwaysWriteHelpOnError = true, ConsoleColor promptColor = ConsoleColor.White, ConsoleColor commandColor = ConsoleColor.Gray)
 {
     while (true)
     {
         Console.ForegroundColor = promptColor;
         Console.Write(prompt);
         Console.ForegroundColor = commandColor;
         string?line = Console.ReadLine();
         if (!condition.ShouldGo(line))
         {
             break;
         }
         if (line != null)
         {
             await HandleAsync(Parse(line), alwaysWriteHelpOnError);
         }
     }
 }