Skip to content

Commit 0c44a5a

Browse files
committed
Add SpectreExercise
1 parent c74aeb2 commit 0c44a5a

File tree

3 files changed

+116
-2
lines changed

3 files changed

+116
-2
lines changed

DotNetExercises.sln

+8-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChartjsExercise", "ChartjsE
1717
EndProject
1818
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GenericRepositoryExercise", "GenericRepositoryExercise\GenericRepositoryExercise.csproj", "{23932422-6C88-4E87-A41E-28263CA5F74E}"
1919
EndProject
20-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdGeneratorExercise", "IdGeneratorExercise\IdGeneratorExercise.csproj", "{9F7B777C-4942-4079-97B3-026E28B44C9F}"
20+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdGeneratorExercise", "IdGeneratorExercise\IdGeneratorExercise.csproj", "{9F7B777C-4942-4079-97B3-026E28B44C9F}"
2121
EndProject
22-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FusionCacheExercise", "FusionCacheExercise\FusionCacheExercise.csproj", "{1B5936BA-F3EA-4E6E-B86C-9ED0CC5EB9C2}"
22+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FusionCacheExercise", "FusionCacheExercise\FusionCacheExercise.csproj", "{1B5936BA-F3EA-4E6E-B86C-9ED0CC5EB9C2}"
23+
EndProject
24+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpectreExercise", "SpectreExercise\SpectreExercise.csproj", "{C35E6A45-24B4-4870-9FBF-7A8EB0CD3BA7}"
2325
EndProject
2426
Global
2527
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -63,6 +65,10 @@ Global
6365
{1B5936BA-F3EA-4E6E-B86C-9ED0CC5EB9C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
6466
{1B5936BA-F3EA-4E6E-B86C-9ED0CC5EB9C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
6567
{1B5936BA-F3EA-4E6E-B86C-9ED0CC5EB9C2}.Release|Any CPU.Build.0 = Release|Any CPU
68+
{C35E6A45-24B4-4870-9FBF-7A8EB0CD3BA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
69+
{C35E6A45-24B4-4870-9FBF-7A8EB0CD3BA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
70+
{C35E6A45-24B4-4870-9FBF-7A8EB0CD3BA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
71+
{C35E6A45-24B4-4870-9FBF-7A8EB0CD3BA7}.Release|Any CPU.Build.0 = Release|Any CPU
6672
EndGlobalSection
6773
GlobalSection(SolutionProperties) = preSolution
6874
HideSolutionNode = FALSE

SpectreExercise/Program.cs

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Spectre.Console" Version="0.49.1" />
12+
</ItemGroup>
13+
14+
</Project>

0 commit comments

Comments
 (0)