Esempio n. 1
0
        public InteractiveConsole(string appName = "gizmo", int histSize = 100)
        {
            Error = StandardStreamWriter.Create(System.Console.Error);
            Out   = StandardStreamWriter.Create(System.Console.Out);

            _lineEditor = new LineEditor(appName, histSize);
        }
Esempio n. 2
0
 internal SystemConsole()
 {
     _initialForegroundColor = Console.ForegroundColor;
     _initialBackgroundColor = Console.BackgroundColor;
     Error = StandardStreamWriter.Create(Console.Error);
     Out   = StandardStreamWriter.Create(Console.Out);
 }
Esempio n. 3
0
        public CommandLineConsole(IConsole console)
        {
            _console = console;

            //Creates output and error stream from IConsole Out and Error
            Out   = StandardStreamWriter.Create(_console.Out);
            Error = StandardStreamWriter.Create(_console.Error);
        }
Esempio n. 4
0
        public ConsoleRenderer(TextWriter output, TextReader input, TextWriter error, Action <ConsoleColor> setColor, Action resetColor)
        {
            _error = error ?? throw new ArgumentNullException(nameof(error));
            Error  = StandardStreamWriter.Create(_error);

            _output = output ?? throw new ArgumentNullException(nameof(output));
            Out     = StandardStreamWriter.Create(_output);

            _input = input ?? throw new ArgumentNullException(nameof(input));

            _setColor   = setColor ?? throw new ArgumentNullException(nameof(setColor));
            _resetColor = resetColor ?? throw new ArgumentNullException(nameof(resetColor));
        }
        public CustomConsole(IStandardStreamWriter stdOut = null, IStandardStreamWriter stdError = null)
        {
            if (stdOut != null)
            {
                Out = stdOut;
            }
            else
            {
                Out = StandardStreamWriter.Create(Console.Out);
            }

            if (stdError != null)
            {
                Error = stdError;
            }
            else
            {
                Error = StandardStreamWriter.Create(Console.Error);
            }
        }
Esempio n. 6
0
        public void Apply(InvocationContext context)
        {
            context.Console.ResetTerminalForegroundColor();
            context.Console.SetTerminalForegroundRed();

            foreach (var error in context.ParseResult.Errors)
            {
                context.Console.Error.WriteLine(error.Message);
            }

            context.Console.Error.WriteLine();

            context.ExitCode = _errorExitCode ?? 1;

            context.Console.ResetTerminalForegroundColor();

            context.BindingContext
            .HelpBuilder
            .Write(context.ParseResult.CommandResult.Command, StandardStreamWriter.Create(context.Console.Out));
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            MemoryStream ms = new MemoryStream();
            TextWriter   tw = new StreamWriter(ms);

            IConsole console = new CustomConsole(StandardStreamWriter.Create(tw));

            var rootCommand = new RootCommand()
            {
                Description = "Console app to demonstrate System.CommandLine.IConsole"
            };

            Console.WriteLine("Hello World!");

            rootCommand.InvokeAsync(args, console).Wait();

            tw.Flush();
            ms.Position = 0;

            Console.Write(new StreamReader(ms).ReadToEnd());
        }
Esempio n. 8
0
        public void CreateDependencies()
        {
            _out          = new StringBuilder();
            _stringWriter = new StringWriter(_out);
            var outWriter = StandardStreamWriter.Create(_stringWriter);

            _renderer = new Mock <IConsoleRenderer>(MockBehavior.Strict);
            _renderer.Setup(x => x.WriteLine()).Callback(() => _out.Append($"\n"));
            _renderer.Setup(x => x.WriteLine(It.IsAny <string>())).Callback((string line) => _out.Append($"{line}\n"));
            _renderer.Setup(x => x.WriteLine(It.IsAny <string>(), It.IsAny <ConsoleColor>())).Callback((string line, ConsoleColor color) => _out.Append($"[color:{color}]{line}[/color]\n"));
            _renderer.Setup(x => x.Write(It.IsAny <string>())).Callback((string text) => _out.Append(text));
            _renderer.Setup(x => x.Write(It.IsAny <string>(), It.IsAny <ConsoleColor>())).Callback((string text, ConsoleColor color) => _out.Append($"[color:{color}]{text}[/color]"));
            _renderer.Setup(x => x.WithColor(It.IsAny <ConsoleColor>())).Returns((ConsoleColor color) => new ColorStub(_out, color));
            _renderer.Setup(x => x.Out).Returns(outWriter);
            _renderer.Setup(x => x.Error).Returns(outWriter);
            _controller = new Mock <IPartyController>(MockBehavior.Strict);
            _controller.SetupProperty(mock => mock.ChecksEnabled);
            var config = PartyConfigurationFactory.Create(@"C:\VaM");

            _program = new Program(_renderer.Object, config, _controller.Object);
        }
 public SystemConsole()
 {
     Error = StandardStreamWriter.Create(Console.Error);
     Out   = StandardStreamWriter.Create(Console.Out);
 }
Esempio n. 10
0
 public SystemConsoleWrapper(TextWriter consoleOut, TextWriter consoleErr)
 {
     Error = StandardStreamWriter.Create(consoleErr);
     Out   = StandardStreamWriter.Create(consoleOut);
 }
Esempio n. 11
0
 /// <inheritdoc />
 public void Apply(InvocationContext context)
 {
     context.BindingContext
     .HelpBuilder
     .Write(context.ParseResult.CommandResult.Command, StandardStreamWriter.Create(context.Console.Out), context.ParseResult);
 }
Esempio n. 12
0
 public SystemConsole()
 {
     Out   = StandardStreamWriter.Create(new ConsoleStdWriter());
     Error = StandardStreamWriter.Create(Console.Error);
 }