|
| 1 | +using Spectre.Console; |
| 2 | + |
| 3 | +namespace SpectreExercise |
| 4 | +{ |
| 5 | + internal class Program |
| 6 | + { |
| 7 | + static void Main(string[] args) |
| 8 | + { |
| 9 | + //原生控制台文字输出 |
| 10 | + Console.WriteLine("你好追逐时光者!!!"); |
| 11 | + |
| 12 | + //类库设置控制台文字输出 |
| 13 | + //类库文档颜色选择表:https://spectreconsole.net/appendix/colors |
| 14 | + AnsiConsole.Markup("[underline red]你好[/][Blue]追逐时光者[/][DarkMagenta]!!![/]"); |
| 15 | + |
| 16 | + #region 创建表 |
| 17 | + // 创建表 |
| 18 | + var table = new Table(); |
| 19 | + |
| 20 | + //添加一些列 |
| 21 | + table.AddColumn("[red]编号[/]"); |
| 22 | + table.AddColumn("[green]姓名[/]"); |
| 23 | + table.AddColumn("[blue]年龄[/]"); |
| 24 | + |
| 25 | + //添加一些行 |
| 26 | + table.AddRow("1", "追逐时光者", "20岁"); |
| 27 | + table.AddRow("2", "大姚", "22岁"); |
| 28 | + table.AddRow("3", "小袁", "18岁"); |
| 29 | + table.AddRow("4", "小明", "23岁"); |
| 30 | + |
| 31 | + // 将表格渲染到控制台 |
| 32 | + AnsiConsole.Write(table); |
| 33 | + #endregion |
| 34 | + |
| 35 | + #region 条形图 |
| 36 | + |
| 37 | + AnsiConsole.Write(new BarChart() |
| 38 | + .Width(60) |
| 39 | + .Label("[green bold underline]水果数量[/]") |
| 40 | + .CenterLabel() |
| 41 | + .AddItem("苹果", 12, Color.Yellow) |
| 42 | + .AddItem("西瓜", 54, Color.Green) |
| 43 | + .AddItem("香蕉", 33, Color.Red) |
| 44 | + .AddItem("芒果", 55, Color.Blue)); |
| 45 | + |
| 46 | + #endregion |
| 47 | + |
| 48 | + |
| 49 | + //日历 |
| 50 | + var calendar = new Calendar(2024, 5); |
| 51 | + AnsiConsole.Write(calendar); |
| 52 | + |
| 53 | + #region 布局 |
| 54 | + |
| 55 | + // Create the layout |
| 56 | + var layout = new Layout("Root") |
| 57 | + .SplitColumns( |
| 58 | + new Layout("Left"), |
| 59 | + new Layout("Right") |
| 60 | + .SplitRows( |
| 61 | + new Layout("Top"), |
| 62 | + new Layout("Bottom"))); |
| 63 | + |
| 64 | + // Update the left column |
| 65 | + layout["Left"].Update( |
| 66 | + new Panel( |
| 67 | + Align.Center( |
| 68 | + new Markup("[blue]你好![/]"), |
| 69 | + VerticalAlignment.Middle)) |
| 70 | + .Expand()); |
| 71 | + |
| 72 | + // Render the layout |
| 73 | + AnsiConsole.Write(layout); |
| 74 | + |
| 75 | + #endregion |
| 76 | + |
| 77 | + #region 规则水平线 |
| 78 | + |
| 79 | + var rule = new Rule("[red]Hello[/]"); |
| 80 | + AnsiConsole.Write(rule); |
| 81 | + |
| 82 | + var ruleLeft = new Rule("[blue]Hello[/]"); |
| 83 | + ruleLeft.Justification = Justify.Left; |
| 84 | + AnsiConsole.Write(ruleLeft); |
| 85 | + |
| 86 | + var ruleRight = new Rule("[yellow]Hello[/]"); |
| 87 | + ruleRight.Justification = Justify.Right; |
| 88 | + AnsiConsole.Write(ruleRight); |
| 89 | + |
| 90 | + #endregion |
| 91 | + |
| 92 | + } |
| 93 | + } |
| 94 | +} |
0 commit comments