public void WriteLine(TerminalMessage message)
        {
            switch (message.Style)
            {
            case TerminalStyle.Command:
                _writer.WriteLine(" > " + message.Message);
                break;

            case TerminalStyle.Error:
                _writer.ChangeColor(ConsoleColor.Red);
                _writer.WriteLine(message.Message);
                _writer.ChangeColor(ConsoleColor.White);
                break;

            default:
                _writer.WriteLine(message.Message);
                break;
            }
        }
Exemplo n.º 2
0
        public void Should_change_color_around_batch_if_colors_enabled()
        {
            batcher.BatchEvents(Arg.Any <LogEventInfo[]>(), Arg.Any <int>())
            .Returns(callInfo => MakeBatch(callInfo).Concat(MakeBatch(callInfo)));

            writer.WriteEvents(new[] { CreateLogEventInfo(), CreateLogEventInfo() }, 2);

            Received.InOrder(
                () =>
            {
                consoleWriter.ChangeColor(ConsoleColor.White);
                consoleWriter.WriteLogEvent(Arg.Any <LogEventInfo>());
                consoleWriter.WriteLogEvent(Arg.Any <LogEventInfo>());
                colorReleaser.Dispose();
                consoleWriter.ChangeColor(ConsoleColor.White);
                consoleWriter.WriteLogEvent(Arg.Any <LogEventInfo>());
                consoleWriter.WriteLogEvent(Arg.Any <LogEventInfo>());
                colorReleaser.Dispose();
            });
        }
Exemplo n.º 3
0
        public void TestSetup()
        {
            batcher = Substitute.For <IEventsBatcher>();
            batcher.BatchEvents(Arg.Any <LogEventInfo[]>(), Arg.Any <int>()).Returns(MakeBatch);

            consoleWriter = Substitute.For <IConsoleWriter>();

            colorReleaser = Substitute.For <IDisposable>();
            consoleWriter.ChangeColor(Arg.Any <ConsoleColor>()).Returns(_ => colorReleaser);

            var featuresDetector = Substitute.For <IConsoleFeaturesDetector>();

            featuresDetector.AreColorsSupported.Returns(true);

            writer = new EventsWriter(batcher, consoleWriter, featuresDetector);
        }
Exemplo n.º 4
0
        private void WriteBatch(IList <LogEventInfo> batch, IConsoleWriter writer)
        {
            var settings = batch[0].Settings;

            if (settings.ColorsEnabled && consoleFeaturesDetector.AreColorsSupported)
            {
                if (!settings.ColorMapping.TryGetValue(batch[0].Event.Level, out var color))
                {
                    color = ConsoleColor.Gray;
                }

                using (writer.ChangeColor(color))
                {
                    WriteBatchInternal(batch, writer);
                }
            }
            else
            {
                WriteBatchInternal(batch, writer);
            }
        }