public void When_formatting_null_values_then_empty_span_is_returned() { var formatter = new TextSpanFormatter(); var span = formatter.Format(null); span.Should().Be(TextSpan.Empty()); }
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)); } }
private static ContentView CreateView(object value, TextSpanFormatter formatter) => new ContentView(formatter.Format(value));