Compare commits
2 Commits
017aae6782
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 3c2d32d522 | |||
| fd2e74e658 |
25
SpectreDemos/Helpers.cs
Normal file
25
SpectreDemos/Helpers.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using Spectre.Console;
|
||||||
|
|
||||||
|
namespace SpectreDemos;
|
||||||
|
|
||||||
|
public static class Helpers
|
||||||
|
{
|
||||||
|
public static async Task<string> FetchApiDataAsync(string apiUrl)
|
||||||
|
{
|
||||||
|
using var client = new HttpClient();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpResponseMessage response = await client.GetAsync(apiUrl);
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
return await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
AnsiConsole.MarkupLine($"[red]Error fetching data from API:[/]{ex.Message}");
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,6 @@
|
|||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
|
using Spectre.Console.Json;
|
||||||
|
using SpectreDemos;
|
||||||
|
|
||||||
#region "Previous Lessons"
|
#region "Previous Lessons"
|
||||||
//Lesson 2 - Initial Setup
|
//Lesson 2 - Initial Setup
|
||||||
@ -149,21 +151,38 @@
|
|||||||
////panel.Padding(2, 1);
|
////panel.Padding(2, 1);
|
||||||
|
|
||||||
////AnsiConsole.Write(panel);
|
////AnsiConsole.Write(panel);
|
||||||
#endregion
|
|
||||||
|
|
||||||
// Lesson 9 - FIGlet Text
|
// Lesson 9 - FIGlet Text
|
||||||
|
|
||||||
AnsiConsole.Write(new FigletText("Hello")
|
////AnsiConsole.Write(new FigletText("Hello")
|
||||||
.Centered()
|
//// .Centered()
|
||||||
.Color(Color.Red)
|
//// .Color(Color.Red)
|
||||||
|
////);
|
||||||
|
|
||||||
|
////FigletText figlet = new("World");
|
||||||
|
////figlet.Centered();
|
||||||
|
////figlet.Color(Color.Red);
|
||||||
|
|
||||||
|
////AnsiConsole.Write(figlet);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// Lesson 10 - Displaying Json
|
||||||
|
|
||||||
|
string jsonResponse = await Helpers.FetchApiDataAsync("https://thesampleapi.com/courses/12");
|
||||||
|
|
||||||
|
JsonText json = new JsonText(jsonResponse);
|
||||||
|
|
||||||
|
json.StringColor(Color.Yellow);
|
||||||
|
json.ColonColor(Color.Orange1);
|
||||||
|
|
||||||
|
|
||||||
|
AnsiConsole.Write(
|
||||||
|
new Panel(json)
|
||||||
|
.Header("API Results")
|
||||||
|
.Collapse()
|
||||||
|
.BorderColor(Color.White)
|
||||||
);
|
);
|
||||||
|
|
||||||
FigletText figlet = new("World");
|
|
||||||
figlet.Centered();
|
|
||||||
figlet.Color(Color.Red);
|
|
||||||
|
|
||||||
AnsiConsole.Write(figlet);
|
|
||||||
|
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
AnsiConsole.Clear();
|
AnsiConsole.Clear();
|
||||||
|
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Spectre.Console" Version="0.50.0" />
|
<PackageReference Include="Spectre.Console" Version="0.50.0" />
|
||||||
|
<PackageReference Include="Spectre.Console.Json" Version="0.50.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
5
SpectreDemos/linkfile.txt
Normal file
5
SpectreDemos/linkfile.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
L<EFBFBD>nk till Spectre-info.txt: https://spectreconsole.net/
|
||||||
Reference in New Issue
Block a user