static int RunListAndReturnExitCode(ListOptions options) { AnsiConsole.WriteLine("Fetching versions from builder.blender.org..."); AnsiConsole.WriteLine(); var client = new BlenderOrgClient(); var result = client.GetAvailableVersions().GetAwaiter().GetResult().ToList(); if (!string.IsNullOrEmpty(options.Branch)) { result = result.Where(x => x.Tag == options.Branch).ToList(); } if (!string.IsNullOrEmpty(options.OperatingSystem)) { result = result.Where(x => x.OperatingSystem == options.OperatingSystem).ToList(); } var table = new Table(); table.AddColumns("OS", "Variation", "Version", "Arch", "Size", "Built On"); foreach (var res in result) { AddVersionLine(table, res); } AnsiConsole.Render(table); return(0); }
public void PrintTable <T>(IEnumerable <T> values) { Table table = new Table(); var columns = GetColumns <T>(); var columnsWithIdx = columns.ToList(); columnsWithIdx.Insert(0, "№"); table.AddColumns(Alignment.Left, Alignment.Left, columnsWithIdx.ToArray()); int index = 0; foreach ( var propertyValues in values.Select(value => columns.Select(column => GetColumnValue <T>(value, column))) ) { index++; var row = propertyValues.ToList(); row.Insert(0, index); table.AddRow(row.ToArray()); } if (table.Rows.Count > 0) { System.Console.Write(table.ToString()); System.Console.WriteLine(); } else { PrintInfoMessage("Table is empty!"); System.Console.WriteLine(); } }
public void Should_Render_Table_With_Footers_Correctly() { // Given var console = new PlainConsole(width: 80); var table = new Table(); table.AddColumn(new TableColumn("Foo").Footer("Oof").RightAligned()); table.AddColumn("Bar"); table.AddColumns(new TableColumn("Baz").Footer("Zab")); table.AddRow("Qux", "Corgi", "Waldo"); table.AddRow("Grault", "Garply", "Fred"); // When console.Render(table); // Then console.Lines.Count.ShouldBe(8); console.Lines[0].ShouldBe("┌────────┬────────┬───────┐"); console.Lines[1].ShouldBe("│ Foo │ Bar │ Baz │"); console.Lines[2].ShouldBe("├────────┼────────┼───────┤"); console.Lines[3].ShouldBe("│ Qux │ Corgi │ Waldo │"); console.Lines[4].ShouldBe("│ Grault │ Garply │ Fred │"); console.Lines[5].ShouldBe("├────────┼────────┼───────┤"); console.Lines[6].ShouldBe("│ Oof │ │ Zab │"); console.Lines[7].ShouldBe("└────────┴────────┴───────┘"); }
public void Should_Render_Table_With_Cell_Padding_Correctly() { // Given var console = new PlainConsole(width: 80); var table = new Table(); table.AddColumns("Foo", "Bar"); table.AddColumn(new TableColumn("Baz") { Padding = new Padding(3, 0, 2, 0) }); table.AddRow("Qux\nQuuux", "Corgi", "Waldo"); table.AddRow("Grault", "Garply", "Fred"); // When console.Render(table); // Then console.Lines.Count.ShouldBe(7); console.Lines[0].ShouldBe("┌────────┬────────┬──────────┐"); console.Lines[1].ShouldBe("│ Foo │ Bar │ Baz │"); console.Lines[2].ShouldBe("├────────┼────────┼──────────┤"); console.Lines[3].ShouldBe("│ Qux │ Corgi │ Waldo │"); console.Lines[4].ShouldBe("│ Quuux │ │ │"); console.Lines[5].ShouldBe("│ Grault │ Garply │ Fred │"); console.Lines[6].ShouldBe("└────────┴────────┴──────────┘"); }
public void ColumnsExpression() { Table table = new Table(); table.AddColumns(new Column[] { new Column("A"), new Column("B"), new Column("C", new SheetExpression <int>((A, B) => DoSometing(A, B))) }); table["A", 1] = 1; Assert.AreEqual(1, table["A", 1]); table["B", 1] = 2; Assert.AreEqual(2, table["B", 1]); var c = table["C", 1]; Assert.AreEqual(3, c); Assert.AreEqual(1, counter); // check the value is not resolved again. c = table["C", 1]; Assert.AreEqual(3, c); Assert.AreEqual(1, counter); table["A", 1] = 10; c = table["C", 1]; Assert.AreEqual(12, c); Assert.AreEqual(2, counter); }
public void Should_Right_Align_Table_With_Title_And_Caption_Correctly() { // Given var console = new PlainConsole(width: 80); var table = new Table { Border = TableBorder.Rounded }; table.RightAligned(); table.Title = new TableTitle("Hello World"); table.Caption = new TableTitle("Goodbye World"); table.AddColumns("Foo", "Bar", "Baz"); table.AddRow("Qux", "Corgi", "Waldo"); table.AddRow("Grault", "Garply", "Fred"); // When console.Render(table); // Then console.Lines.Count.ShouldBe(8); console.Lines[0].ShouldBe(" Hello World "); console.Lines[1].ShouldBe(" ╭────────┬────────┬───────╮"); console.Lines[2].ShouldBe(" │ Foo │ Bar │ Baz │"); console.Lines[3].ShouldBe(" ├────────┼────────┼───────┤"); console.Lines[4].ShouldBe(" │ Qux │ Corgi │ Waldo │"); console.Lines[5].ShouldBe(" │ Grault │ Garply │ Fred │"); console.Lines[6].ShouldBe(" ╰────────┴────────┴───────╯"); console.Lines[7].ShouldBe(" Goodbye World "); }
private static void DisplayCountryData(CovidData data) { var table = new Table(); table.Border = TableBorder.Minimal; table.AddColumns("", "Total Reported", "Per 100k", data.RegionData.LatestDate.ToString("yyyy-MM-dd"), "Weekly Trend"); table.Columns[0].LeftAligned(); table.Columns[1].RightAligned(); table.Columns[2].RightAligned(); table.Columns[3].RightAligned(); table.Columns[4].RightAligned(); string casesColor = data.RegionData.CasesWeeklyTrend > 0 ? "[red]" : "[green]"; table.AddRow( "[white]Cases[/]", data.RegionData.LatestCases.ToString("n0"), data.RegionData.CasesPerHundredThousand.ToString("n0"), data.RegionData.LastReportedCases.ToString("n0"), casesColor + data.RegionData.CasesWeeklyTrend + "%[/]" ); string deathsColor = data.RegionData.DeathsWeeklyTrend > 0 ? "[red]" : "[green]"; table.AddRow( "[white]Deaths[/]", data.RegionData.LatestDeaths.ToString("n0"), data.RegionData.DeathsPerHundredThousand.ToString("n0"), data.RegionData.LastReportedDeaths.ToString("n0"), deathsColor + data.RegionData.DeathsWeeklyTrend + "%[/]" ); AnsiConsole.Render(table); }
private static void DisplayRegionalDeaths(CovidData data) { var table = new Table(); table.Border = TableBorder.Minimal; table.AddColumns("", "Deaths", "Per 100k", "7d Avg", "Per 100k"); table.Columns[0].LeftAligned(); table.Columns[1].RightAligned(); table.Columns[2].RightAligned(); table.Columns[3].RightAligned(); table.Columns[4].RightAligned(); var subregions = data.SubRegionData .Where(d => d.Name != "Unknown") .OrderByDescending(d => d.DailyAverageCasesLastSevenDaysPerHundredThousand); foreach (var region in subregions) { table.AddRow( region.Name, region.LatestDeaths.ToString("n0"), region.DeathsPerHundredThousand.ToString("n0"), region.DailyAverageDeathsLastSevenDays.ToString("n0"), region.DailyAverageDeathsLastSevenDaysPerHundredThousand.ToString("n1")); } AnsiConsole.Render(table); }
static void Main(string[] args) { Table table = new Table(); table.AddColumns(new Column[] { new Column("A"), new Column("B"), new Column("C", new SheetExpression <int>((A, B) => DoSometing(A, B))) }); table.GetCell("B", 1).SetExpression <int>((A) => DoSometing(A, A)); int i = 0; while (true) { if (i > 1000000) { i = 0; } i++; table["A", 1] = i; Console.WriteLine(table["C", 1]); } }
public void RenderTaskList() { var list = app.GetAll().OrderBy(t => t.CreatedAt).ToList(); if (!list.Any()) { Console.WriteLine("empty."); return; } var table = new Table(); table.Border = TableBorder.Square; table.AddColumns( new TableColumn("[green]No.[/]"), new TableColumn("[yellow]Todo[/]"), new TableColumn("[blue]Created At[/]").Centered()); table.Expand(); table.Columns[0].Width(1).NoWrap(); table.Columns[1].Width(10); table.Columns[2].Width(3); for (int i = 1; i <= list.Count; i++) { var todo = list[i - 1]; table.AddRow($"{i}", todo.Text, todo.CreatedAt.ToString("dd MMM yyyy, HH:mm")); } AnsiConsole.Render(table); }
public void Should_Expand_Table_To_Available_Space_If_Specified() { // Given var console = new PlainConsole(width: 80); var table = new Table() { Expand = true }; table.AddColumns("Foo", "Bar", "Baz"); table.AddRow("Qux", "Corgi", "Waldo"); table.AddRow("Grault", "Garply", "Fred"); // When console.Render(table); // Then console.Lines.Count.ShouldBe(6); console.Lines[0].Length.ShouldBe(80); console.Lines[0].ShouldBe("┌───────────────────────────┬───────────────────────────┬──────────────────────┐"); console.Lines[1].ShouldBe("│ Foo │ Bar │ Baz │"); console.Lines[2].ShouldBe("├───────────────────────────┼───────────────────────────┼──────────────────────┤"); console.Lines[3].ShouldBe("│ Qux │ Corgi │ Waldo │"); console.Lines[4].ShouldBe("│ Grault │ Garply │ Fred │"); console.Lines[5].ShouldBe("└───────────────────────────┴───────────────────────────┴──────────────────────┘"); }
private static void ListAssignmentsForStudent(int observerId, string studentName) { var user = GetObserveeByName(observerId, studentName); System.Console.WriteLine($"{user.Name} - {user.Id}"); var courses = GetCoursesForUser(user.Id); foreach (var course in courses) { AnsiConsole.Render(new Rule(course.Name ?? "No course name")); var assignments = GetAssignmentsForUserAndCourse(user.Id, course.Id); assignments = FilterToRelevantAssignments(assignments); var table = new Table(); table.AddColumns("Name", "Submitted", "Due At", "Lock At", "Score", "State", "Graded by"); foreach (var assignment in assignments.OrderBy(x => x.LockAt)) { var submitted = assignment.HasSubmittedSubmissions ? new Markup("yes") : new Markup("[red]no[/]"); var scoreText = $"{assignment.Score}/{assignment.PointsPossible}"; var score = assignment.Score < assignment.PointsPossible ? new Markup($"[red]{scoreText}[/]") : new Markup(scoreText); table.AddRow( new Markup(assignment.Name), submitted, new Markup(assignment.DueAt.ToString()), new Markup(assignment.LockAt.ToString()), score, new Markup(assignment.WorkflowState), new Markup(assignment.GradedBy)); } AnsiConsole.Render(table); } }
public void ViewProductDetails(Product product) { var table = new Table(); table.Border = TableBorder.Square; table.Title(product.Name).SquareBorder(); table.AddColumns( new TableColumn("characteristic").LeftAligned().Width(15), new TableColumn("description").LeftAligned().Width(62)); table.AddRow("Product ID", product.ProductId.ToString()); table.AddRow("Quantity", product.Quantity.ToString()); float discount; float finalPrice; if (product.DiscountId != 0) { discount = UnitOfWOrk.Discounts.Get(product.DiscountId).Value; finalPrice = (float)product.Price * (100 - discount) / 100; } else { finalPrice = (float)product.Price; } table.AddRow("Price", finalPrice.ToString()); table.AddRow("Available", product.IsAvailable.ToString()); table.AddRow("Category", UnitOfWOrk.Categories.GetAll() .Where(category => category.CategoryId == product.CategoryId) .Select(category => category.Name) .FirstOrDefault()); AnsiConsole.Render(table); }
public CommandResult <IDataObject> Inf( CommandEvaluationContext context, [Parameter(0, "variable namespace of a value")] string varPath ) { context.Variables.GetObject(varPath, out var obj); var options = new TableFormattingOptions(context.ShellEnv.TableFormattingOptions) { UnfoldCategories = false, UnfoldItems = false, IsRawModeEnabled = true }; var props = new Dictionary <string, object>(); if (obj is DataObject o) { props.Add("name", o.Name); props.Add("is read only", o.IsReadOnly); props.Add("namespace", o.ObjectPath); props.Add("has attributes", o.HasAttributes); } else if (obj is DataValue v) { props.Add("name", v.Name); props.Add("type", v.ValueType?.UnmangledName(false)); props.Add("is read only", v.IsReadOnly); props.Add("has attributes", v.HasAttributes); props.Add("has value", v.HasValue); props.Add("namespace", v.ObjectPath); props.Add("value", v.Value); } else { throw new Exception($"can't get information for a variable member"); } Table dt = new Table(); dt.AddColumns("property", "value") .SetFormat("property", $"{context.ShellEnv.Colors.Label}{{0}}{Rdc}"); dt.Columns[0].DataType = typeof(string); dt.Columns[1].DataType = typeof(object); foreach (var kv in props) { var row = dt.NewRow(); row["property"] = kv.Key; row["value"] = kv.Value; dt.Rows.Add(row); } dt.Echo(new EchoEvaluationContext(context.Out, context, options)); return(new CommandResult <IDataObject>(obj as IDataObject)); }
public static Table GetTable() { var table = new Table(); table.AddColumns("Header 1", "Header 2"); table.AddRow("Cell", "Cell"); table.AddRow("Cell", "Cell"); return(table); }
private void button1_Click(object sender, EventArgs e) { dataGridView1.ColumnHeadersVisible = true; dataGridView1.RowHeadersVisible = true; int count = dataGridView1.ColumnCount; dataGridView1.ColumnCount += 1; table.AddColumns(1); dataGridView1.Columns[count].Name = TwentySixNumeralSystem.ToTwentySixBasedNumeralSystem(count); }
private static void WritePlain(string windowsPath, string unixPath) { var table = new Table().BorderColor(Color.Grey).Title("Plain").RoundedBorder(); table.AddColumns("[grey]OS[/]", "[grey]Path[/]"); table.AddRow(new Text("Windows"), new TextPath(windowsPath)); table.AddRow(new Text("Unix"), new TextPath(unixPath)); AnsiConsole.Write(table); }
private static void WriteAligned(string path) { var table = new Table().BorderColor(Color.Grey).Title("Aligned").RoundedBorder(); table.AddColumns("[grey]Alignment[/]", "[grey]Path[/]"); table.AddRow(new Text("Left"), new TextPath(path).LeftAligned()); table.AddRow(new Text("Center"), new TextPath(path).Centered()); table.AddRow(new Text("Right"), new TextPath(path).RightAligned()); AnsiConsole.Write(table); }
private static void RenderExtendedCapabilitiesTable(TermInfoDesc desc) { var table = new Table(); table.Expand(); table.Title("[green]Extended capabilities[/]"); table.AddColumns("Name", "Type", "Value"); foreach (var key in desc.Extended.GetNames(TermInfoCapsKind.Num)) { var value = desc.Extended.GetNum(key); if (value != null) { table.AddRow( "[yellow]" + key + "[/]", "[grey]num[/]", value.ToString().EscapeMarkup()); } } foreach (var key in desc.Extended.GetNames(TermInfoCapsKind.String)) { var value = desc.Extended.GetString(key); if (value != null) { value = value.Replace("\u001b", "ESC") .Replace("\u000e", "") .Replace("\u000f", "") .Replace("\t", "\\t") .Replace("\r", "\\r") .Replace("\a", "\\a") .Replace("\n", "\\n"); table.AddRow( "[yellow]" + key.EscapeMarkup() + "[/]", "[grey]string[/]", value.EscapeMarkup()); } } foreach (var key in desc.Extended.GetNames(TermInfoCapsKind.Boolean)) { var value = desc.Extended.GetBoolean(key); if (value != null) { table.AddRow( "[yellow]" + key.EscapeMarkup() + "[/]", "[grey]boolean[/]", value.ToString().EscapeMarkup()); } } AnsiConsole.Render(table); }
public void Should_Throw_If_Columns_Are_Null() { // Given var table = new Table(); // When var result = Record.Exception(() => table.AddColumns((string[])null)); // Then result.ShouldBeOfType <ArgumentNullException>() .ParamName.ShouldBe("columns"); }
private static IRenderable Create(string name, Border border) { var table = new Table().SetBorder(border); table.AddColumns("[yellow]Header 1[/]", "[yellow]Header 2[/]"); table.AddRow("Cell", "Cell"); table.AddRow("Cell", "Cell"); return(new Panel(table) .SetHeader($" {name} ", Style.Parse("blue"), Justify.Center) .SetBorderStyle(Style.Parse("grey")) .NoBorder()); }
private static Table BuildTableForSingleDatabase(Table table, DatabaseStatus database) { table.AddColumns("Shard", "Sequence", "Status"); table.Columns[1].Alignment = Justify.Right; table.AddRow(new Markup("[blue]High Water Mark[/]"), new Markup($"[blue]{database.HighWaterMark}[/]"), new Markup("[gray]Active[/]")); foreach (var shard in database.Shards.OrderBy(x => x.ShardName)) { table.AddRow(shard.ShardName, shard.Sequence.ToString(), shard.State.ToString()); } return(table); }
private void CreateTable() { var lineValuesTop = CardLines[0].GetLineValues().ToArray(); var lineValuesButtom = CardLines[2].GetLineValues().ToArray(); var table = new Table(); for (int i = 0; i < lineValuesTop.Length; i++) { table.AddColumns(new TableColumn(lineValuesTop[i]).Footer(lineValuesButtom[i])); } table.AddRow(CardLines[1].GetLineValues().ToArray()); Table = new Panel(table).Header(Path.GetFileNameWithoutExtension(FileName)); }
public void DateTests() { Table table = new Table(); DateTime ahora = DateTime.UtcNow; table.AddColumns(new Column[] { new Column("A", new SheetExpression <DateTime>((A_1N) => A_1N.AddDays(1))), }); table["A", 1] = ahora; Assert.AreEqual(ahora.AddDays(1), table["A", 2]); }
public static Panel CreateTableNumbersBase(int numberBase, HashSet <int> numbers) { int[] ceilings = Enumerable.Range(1, 90 / numberBase).Select(number => number * numberBase).ToArray(); List <List <string> > numberLines = GetNumbersValuesPivot(numbers, ceilings); Table table = new Table().HideHeaders(); table.AddColumns(ceilings.Select(ceiling => ceiling.ToString()).ToArray()); foreach (var numberLine in numberLines) { table.AddRow(numberLine.ToArray()); } return(new Panel(table).Header("Numbers Drawn")); }
public Task Should_Render_Table_With_Multiple_Rows_In_Cell_Correctly() { // Given var console = new FakeConsole(width: 80); var table = new Table(); table.AddColumns("Foo", "Bar", "Baz"); table.AddRow("Qux\nQuuux", "Corgi", "Waldo"); table.AddRow("Grault", "Garply", "Fred"); // When console.Write(table); // Then return(Verifier.Verify(console.Output)); }
public Task Should_Render_Table_With_EA_Character_Correctly() { // Given var console = new TestConsole().Width(48); var table = new Table(); table.AddColumns("Foo", "Bar", "Baz"); table.AddRow("中文", "日本語", "한국어"); table.AddRow("这是中文测试字符串", "これは日本語のテスト文字列です", "이것은한국어테스트문자열입니다"); // When console.Write(table); // Then return(Verifier.Verify(console.Output)); }
public Task Should_Render_Table_Correctly() { // Given var console = new TestConsole(); var table = new Table(); table.AddColumns("Foo", "Bar", "Baz"); table.AddRow("Qux", "Corgi", "Waldo"); table.AddRow("Grault", "Garply", "Fred"); // When console.Write(table); // Then return(Verifier.Verify(console.Output)); }
public Task Should_Right_Align_Table_Correctly() { // Given var console = new FakeConsole(width: 80); var table = new Table(); table.Alignment = Justify.Right; table.AddColumns("Foo", "Bar", "Baz"); table.AddRow("Qux", "Corgi", "Waldo"); table.AddRow("Grault", "Garply", "Fred"); // When console.Write(table); // Then return(Verifier.Verify(console.Output)); }
Table GetVarsDataTable(List <DataValue> values) { var table = new Table(); table.AddColumns("name", "type", "value"); table.SetFormat("name", Yellow + "{0}" + Rsf); table.SetFormat("type", Cyan + "{0}" + Tab + Rsf); table.SetHeaderFormat("type", "{0}" + Tab); foreach (var value in values) { table.Rows.Add( value.Name + (value.IsReadOnly ? "(r)" : ""), value.ValueType.Name, DumpAsText(value.Value, false)); } return(table); }