private void OnLogEvent( DiagnosticLogEntryProduced logEvent, ZeroMQMessage request, IJupyterMessageSender jupyterMessageSender) { var transient = CreateTransient(); var span = _textSpanFormatter.ParseToSpan($"{Ansi.Color.Foreground.DarkGray}{logEvent.Message}{Ansi.Text.AttributesOff}"); var message = span.ToString(OutputMode.Ansi); var dataMessage = new DisplayData( transient: transient, data: new Dictionary <string, object> { [PlainTextFormatter.MimeType] = message }); var isSilent = ((ExecuteRequest)request.Content).Silent; if (!isSilent) { // send on io jupyterMessageSender.Send(dataMessage); } }
public DirectoryView(DirectoryInfo directory) { if (directory == null) { throw new ArgumentNullException(nameof(directory)); } var formatter = new TextSpanFormatter(); formatter.AddFormatter <DateTime>(d => $"{d:d} {ForegroundColorSpan.DarkGray()}{d:t}"); Add(new ContentView("")); Add(new ContentView("")); Add(new ContentView($"Directory: {directory.FullName}")); Add(new ContentView("")); Add(new ContentView("")); var directoryContents = directory.EnumerateFileSystemInfos() .OrderBy(f => f is DirectoryInfo ? 0 : 1).ToList(); var tableView = new TableView <FileSystemInfo>(); tableView.Items = directoryContents; tableView.AddColumn(f => f is DirectoryInfo ? Span($"{ForegroundColorSpan.LightGreen()}{f.Name} ") : Span($"{ForegroundColorSpan.White()}{f.Name} "), new ContentView(formatter.ParseToSpan($"{Ansi.Text.UnderlinedOn}Name{Ansi.Text.UnderlinedOff}"))); tableView.AddColumn(f => formatter.Format(f.CreationTime), new ContentView(formatter.ParseToSpan($"{Ansi.Text.UnderlinedOn}Created{Ansi.Text.UnderlinedOff}"))); tableView.AddColumn(f => formatter.Format(f.LastWriteTime), new ContentView(formatter.ParseToSpan($"{Ansi.Text.UnderlinedOn}Modified{Ansi.Text.UnderlinedOff}"))); Add(tableView); TextSpan Span(FormattableString formattableString) { return(formatter.ParseToSpan(formattableString)); } }
public void Ansi_control_codes_can_be_included_in_interpolated_strings() { var writer = new StringWriter(); var formatter = new TextSpanFormatter(); var span = formatter.ParseToSpan($"{Ansi.Color.Foreground.LightGray}hello{Ansi.Color.Off}"); writer.Write(span.ToString(OutputMode.Ansi)); writer.ToString() .Should() .Be($"{Ansi.Color.Foreground.LightGray.EscapeSequence}hello{Ansi.Color.Off.EscapeSequence}"); }
public void BackgroundColorSpans_are_replaced_with_ANSI_codes_during_ANSI_rendering() { var span = _textSpanFormatter.ParseToSpan( $"{BackgroundColorSpan.Red()}red {BackgroundColorSpan.Blue()}blue {BackgroundColorSpan.Green()}green {BackgroundColorSpan.Reset()}or a {BackgroundColorSpan.Rgb(12, 34, 56)}little of each."); var renderer = new ConsoleRenderer(_terminal, OutputMode.Ansi); renderer.RenderToRegion(span, new Region(0, 0, 200, 1, false)); _terminal.Out .ToString() .Should() .Contain( $"{Ansi.Color.Background.Red.EscapeSequence}red {Ansi.Color.Background.Blue.EscapeSequence}blue {Ansi.Color.Background.Green.EscapeSequence}green {Ansi.Color.Background.Default.EscapeSequence}or a {Ansi.Color.Background.Rgb(12, 34, 56).EscapeSequence}little of each."); }
public RenderingTestCase( string name, FormattableString rendering, Region inRegion, params TextRendered[] expectOutput) { if (rendering == null) { throw new ArgumentNullException(nameof(rendering)); } if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(name)); } Name = name; InputSpan = _formatter.ParseToSpan(rendering); Region = inRegion ?? throw new ArgumentNullException(nameof(inRegion)); ExpectedOutput = expectOutput ?? throw new ArgumentNullException(nameof(expectOutput)); }
public void FormattableString_parsing_handles_escapes( FormattableString fs, int expectedCount ) { var formatter = new TextSpanFormatter(); var span = formatter.ParseToSpan(fs); if (expectedCount > 1) { var containerSpan = span.Should().BeOfType <ContainerSpan>().Subject; output.WriteLine(containerSpan.ToString()); containerSpan.Count.Should().Be(expectedCount); } else { span.Should().BeOfType <ContentSpan>(); } }
public void Empty_strings_are_returned_as_empty_spans() { var formatter = new TextSpanFormatter(); var span = formatter.ParseToSpan( $"{Ansi.Color.Foreground.Red}normal{Ansi.Color.Foreground.Default:a}" ); var containerSpan = span.Should().BeOfType <ContainerSpan>().Subject; containerSpan .Should() .BeEquivalentTo( new ContainerSpan( TextSpan.Empty(), new ContentSpan("normal"), TextSpan.Empty() ), options => options.WithStrictOrdering().Excluding(s => s.Parent).Excluding(s => s.Root) ); }
public static void WriteAnsi(this TextWriter writer, FormattableString formattableString) { var span = _spanFormatter.ParseToSpan(formattableString); writer.Write(span.ToString(OutputMode.Ansi)); }
public void WriteRichLine(FormattableString message) { WriteLine(formatter.ParseToSpan(message)); }
public void OnNext(T value) { _contentView.Span = _textSpanFormatter.ParseToSpan(_formatProvider(value)); _contentView.OnUpdated(); }
internal static Task DisplayAnsi( this KernelInvocationContext context, FormattableString message) => DisplayAnsi(context, _textSpanFormatter.ParseToSpan(message));