Beispiel #1
0
        /// <summary>
        /// Utility for constructing loop clients.
        /// </summary>
        /// <param name="parameters">I/O parameters for loop.</param>
        /// <returns>A constructed loop client.</returns>
        public static ILoopClient CreateClient(LoopInputOutputParameters parameters)
        {
            var consoleInput  = parameters.ConsoleInput ?? BasicConsole.Default;
            var consoleOutput = parameters.ConsoleOutput ?? BasicConsole.Default;
            var keyBindingSet = parameters.KeyBindingSet ?? ConsoleKeyBindingSet.Default;

            var lineInput = parameters.LineInput ?? new ConsoleLineInput(
                consoleOutput,
                new ConsoleInputBuffer(),
                new ConsoleHistory());

            lineInput.Prompt = parameters.Prompt ?? Strings.DefaultPrompt;

            var consoleReader = new ConsoleReader(lineInput, consoleInput, consoleOutput, keyBindingSet);

            var consoleClient = new ConsoleLoopClient(consoleReader);

            consoleClient.Reader.CommentCharacter = parameters.EndOfLineCommentCharacter;

            return(consoleClient);
        }
Beispiel #2
0
        /// <summary>
        /// Constructor that creates a loop with a default client.
        /// </summary>
        /// <param name="parameters">Optionally provides parameters controlling
        /// the loop's input and output behaviors; if not provided, default
        /// parameters are used.</param>
        /// <param name="options">Options for loop.</param>
        public Loop(LoopInputOutputParameters parameters, LoopOptions options = null) : this(options)
        {
            var consoleInput  = parameters?.ConsoleInput ?? BasicConsoleInputAndOutput.Default;
            var consoleOutput = parameters?.ConsoleOutput ?? BasicConsoleInputAndOutput.Default;
            var keyBindingSet = parameters?.KeyBindingSet ?? ConsoleKeyBindingSet.Default;

            var lineInput = parameters?.LineInput ?? new ConsoleLineInput(
                consoleOutput,
                new ConsoleInputBuffer(),
                new ConsoleHistory(),
                GenerateCompletions);

            lineInput.Prompt = parameters?.Prompt ?? Strings.DefaultPrompt;

            ConsoleReader = new ConsoleReader(lineInput, consoleInput, consoleOutput, keyBindingSet);

            var consoleClient = new ConsoleLoopClient(
                ConsoleReader,
                parameters?.ErrorWriter ?? Console.Error);

            consoleClient.Reader.CommentCharacter = options?.EndOfLineCommentCharacter;

            Client = consoleClient;
        }
Beispiel #3
0
 /// <summary>
 /// Constructor that creates a loop with a default client.
 /// </summary>
 /// <param name="commandType">Type that defines syntax for commands.</param>
 /// <param name="parameters">Optionally provides parameters controlling
 /// the loop's input and output behaviors; if not provided, default
 /// parameters are used.</param>
 /// <param name="argSetAttribute">Optionally provides attribute info
 /// for the argument set that will be dynamically created for this loop.</param>
 /// <param name="options">Optionally provides additional options for
 /// this loop's execution.</param>
 public Loop(Type commandType, LoopInputOutputParameters parameters = null, ArgumentSetAttribute argSetAttribute = null, LoopOptions options = null)
     : this(commandType, CreateClient(parameters ?? new LoopInputOutputParameters()), argSetAttribute, options)
 {
 }