public void CanShowDefaultColumns() { TabularOutputSettings outputSettings = new( new MockEnvironment() { ConsoleBufferWidth = 100 }); IEnumerable <Tuple <string, string, string> > data = new List <Tuple <string, string, string> >() { new Tuple <string, string, string>("My test data", "My test data", "Column 3 data"), new Tuple <string, string, string>("My test data", "My test data", "Column 3 data") }; string expectedOutput = $"Column 1 Column 2 {Environment.NewLine}------------ ------------{Environment.NewLine}My test data My test data{Environment.NewLine}My test data My test data{Environment.NewLine}"; TabularOutput <Tuple <string, string, string> > formatter = TabularOutput.TabularOutput .For(outputSettings, data) .DefineColumn(t => t.Item1, "Column 1", showAlways: true) .DefineColumn(t => t.Item2, "Column 2", columnName: "column2") //defaultColumn: true by default .DefineColumn(t => t.Item3, "Column 3", columnName: "column3", defaultColumn: false); string result = formatter.Layout(); Assert.Equal(expectedOutput, result); }
public void CannotShrinkOverMinimumWidth() { TabularOutputSettings outputSettings = new( new MockEnvironment() { ConsoleBufferWidth = 10, //less than need for data below }); IEnumerable <Tuple <string, string> > data = new List <Tuple <string, string> >() { new Tuple <string, string>("My test data", "My test data"), new Tuple <string, string>("My test data", "My test data") }; string expectedOutput = $"Column 1 Column 2 {Environment.NewLine}------------ -----------{Environment.NewLine}My test data My test ...{Environment.NewLine}My test data My test ...{Environment.NewLine}"; TabularOutput <Tuple <string, string> > formatter = TabularOutput.TabularOutput .For(outputSettings, data) .DefineColumn(t => t.Item1, "Column 1", shrinkIfNeeded: true, minWidth: 15) .DefineColumn(t => t.Item2, "Column 2", shrinkIfNeeded: true, minWidth: 8); string result = formatter.Layout(); Assert.Equal(expectedOutput, result); }
public void CanShrinkMultipleColumnsAndBalanceShrinking() { TabularOutputSettings outputSettings = new( new MockEnvironment() { ConsoleBufferWidth = 6 + 2 + 6 + 1, }); IEnumerable <Tuple <string, string> > data = new List <Tuple <string, string> >() { new Tuple <string, string>("My test data", "My test data"), new Tuple <string, string>("My test data", "My test data") }; string expectedOutput = $"Col... Col...{Environment.NewLine}------ ------{Environment.NewLine}My ... My ...{Environment.NewLine}My ... My ...{Environment.NewLine}"; TabularOutput <Tuple <string, string> > formatter = TabularOutput.TabularOutput .For(outputSettings, data) .DefineColumn(t => t.Item1, "Column 1", shrinkIfNeeded: true, minWidth: 2) .DefineColumn(t => t.Item2, "Column 2", shrinkIfNeeded: true, minWidth: 2); string result = formatter.Layout(); Assert.Equal(expectedOutput, result); }
public void CanRightAlign() { TabularOutputSettings outputSettings = new( new MockEnvironment() { ConsoleBufferWidth = 10 }); IEnumerable <Tuple <string, string> > data = new List <Tuple <string, string> >() { new Tuple <string, string>("Monday", "Wednesday"), new Tuple <string, string>("Tuesday", "Sunday") }; string expectedOutput = $"Column 1 Column 2{Environment.NewLine}-------- ---------{Environment.NewLine}Monday Wednesday{Environment.NewLine}Tuesday Sunday{Environment.NewLine}"; TabularOutput <Tuple <string, string> > formatter = TabularOutput.TabularOutput .For(outputSettings, data) .DefineColumn(t => t.Item1, "Column 1") .DefineColumn(t => t.Item2, "Column 2", rightAlign: true); string result = formatter.Layout(); Assert.Equal(expectedOutput, result); }
internal static NewCommandStatus HandleAmbiguousTemplateGroup( IEngineEnvironmentSettings environmentSettings, TemplatePackageManager templatePackageManager, IEnumerable <TemplateGroup> templateGroups, Reporter reporter, CancellationToken cancellationToken = default) { IEnvironment environment = environmentSettings.Environment; reporter.WriteLine(LocalizableStrings.AmbiguousTemplatesHeader.Bold().Red()); TabularOutput <TemplateGroup> formatter = TabularOutput.TabularOutput .For( new TabularOutputSettings(environment), templateGroups) .DefineColumn(t => t.GroupIdentity ?? t.Templates[0].Identity, out object?identityColumn, LocalizableStrings.ColumnNameIdentity, showAlways: true) .DefineColumn(t => t.Name, LocalizableStrings.ColumnNameTemplateName, shrinkIfNeeded: true, minWidth: 15, showAlways: true) .DefineColumn(t => string.Join(",", t.ShortNames), LocalizableStrings.ColumnNameShortName, showAlways: true) .DefineColumn(t => string.Join(",", t.Languages), LocalizableStrings.ColumnNameLanguage, showAlways: true) .DefineColumn(t => string.Join(",", t.Authors), LocalizableStrings.ColumnNameAuthor, showAlways: true, shrinkIfNeeded: true, minWidth: 10) .DefineColumn(t => Task.Run(() => GetTemplatePackagesList(t)).GetAwaiter().GetResult(), LocalizableStrings.ColumnNamePackage, showAlways: true) .OrderBy(identityColumn, StringComparer.CurrentCultureIgnoreCase); reporter.WriteLine(formatter.Layout().Bold().Red()); reporter.WriteLine(LocalizableStrings.AmbiguousTemplatesMultiplePackagesHint.Bold().Red()); return(NewCommandStatus.NotFound); async Task <string> GetTemplatePackagesList(TemplateGroup templateGroup) { try { IReadOnlyList <IManagedTemplatePackage> templatePackages = await templateGroup.GetManagedTemplatePackagesAsync(templatePackageManager, cancellationToken).ConfigureAwait(false); return(string.Join(environment.NewLine, templatePackages.Select(templatePackage => templatePackage.Identifier))); } catch (Exception ex) { environmentSettings.Host.Logger.LogWarning($"Failed to get information about template packages for template group {templateGroup.GroupIdentity}."); environmentSettings.Host.Logger.LogDebug($"Details: {ex}."); return(string.Empty); } } }
public void CanShrinkWideCharsCorrectly() { TabularOutputSettings outputSettings = new( new MockEnvironment() { ConsoleBufferWidth = 30 }); IEnumerable <Tuple <string, string> > data = new List <Tuple <string, string> >() { new Tuple <string, string>("dotnet gitignore 文件", "gitignore"), new Tuple <string, string>("Dotnet 本地工具清单文件", "tool-manifest"), new Tuple <string, string>("控制台应用程序", "console"), new Tuple <string, string>("类库", "classlib"), }; string expectedOutput = @"模板名 短名称 -------------- ------------- dotnet giti... gitignore Dotnet 本地... tool-manifest 控制台应用程序 console 类库 classlib "; TabularOutput <Tuple <string, string> > formatter = TabularOutput.TabularOutput .For( outputSettings, data) .DefineColumn(t => t.Item1, "模板名", shrinkIfNeeded: true) .DefineColumn(t => t.Item2, "短名称"); string result = formatter.Layout(); Assert.Equal(expectedOutput, result); }