Compare commits
4 Commits
cceaa95735
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 3c2d32d522 | |||
| fd2e74e658 | |||
| 017aae6782 | |||
| 5fb336b84a |
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.Json;
|
||||
using SpectreDemos;
|
||||
|
||||
#region "Previous Lessons"
|
||||
//Lesson 2 - Initial Setup
|
||||
@ -100,36 +102,86 @@
|
||||
//// AnsiConsole.MarkupLine($"[bold red]{name}[/]");
|
||||
////}
|
||||
|
||||
#endregion
|
||||
|
||||
// Lesson 7 - Adding tables to your console
|
||||
|
||||
List<Text> person = [
|
||||
new("Bilbo"),
|
||||
new("Baggins"),
|
||||
new("111")
|
||||
];
|
||||
////List<Text> person = [
|
||||
//// new("Bilbo"),
|
||||
//// new("Baggins"),
|
||||
//// new("111")
|
||||
////];
|
||||
|
||||
Table table = new Table();
|
||||
table.Centered();
|
||||
//table.Expand();
|
||||
//table.Border(TableBorder.Double);
|
||||
table.Border(TableBorder.Rounded);
|
||||
table.ShowRowSeparators();
|
||||
////Table table = new Table();
|
||||
////table.Centered();
|
||||
//////table.Expand();
|
||||
//////table.Border(TableBorder.Double);
|
||||
////table.Border(TableBorder.Rounded);
|
||||
////table.ShowRowSeparators();
|
||||
|
||||
table.AddColumn("First Name");
|
||||
table.AddColumn("Last Name");
|
||||
table.AddColumn("Age");
|
||||
////table.AddColumn("First Name");
|
||||
////table.AddColumn("Last Name");
|
||||
////table.AddColumn("Age");
|
||||
|
||||
table.Columns[0].PadLeft(5).PadRight(5);
|
||||
table.Columns[1].Width(15);
|
||||
table.Columns[2].RightAligned();
|
||||
////table.Columns[0].PadLeft(5).PadRight(5);
|
||||
////table.Columns[1].Width(15);
|
||||
////table.Columns[2].RightAligned();
|
||||
|
||||
table.AddRow("Tim", "Corey", "46");
|
||||
table.AddRow("Sue", "Storm", "23");
|
||||
table.AddRow(person);
|
||||
////table.AddRow("Tim", "Corey", "46");
|
||||
////table.AddRow("Sue", "Storm", "23");
|
||||
////table.AddRow(person);
|
||||
|
||||
AnsiConsole.Write(table);
|
||||
////AnsiConsole.Write(table);
|
||||
|
||||
|
||||
//Lesson 8 - Panels
|
||||
////List<string> names = [
|
||||
//// "Tim Corey",
|
||||
//// "Sue Storm",
|
||||
//// "[red]Bilbo Baggins[/]",
|
||||
//// "John Doe",
|
||||
//// "Princess Donaut",
|
||||
//// "Steve Rogers"
|
||||
////];
|
||||
|
||||
////string panelInfo = string.Join("\n", names);
|
||||
//////Panel panel = new Panel(panelInfo);
|
||||
////Panel panel = new(new Markup(panelInfo).Centered());
|
||||
////panel.Header = new PanelHeader("Default names");
|
||||
////panel.Border = BoxBorder.Rounded;
|
||||
////panel.Padding(2, 1);
|
||||
|
||||
////AnsiConsole.Write(panel);
|
||||
|
||||
// Lesson 9 - FIGlet Text
|
||||
|
||||
////AnsiConsole.Write(new FigletText("Hello")
|
||||
//// .Centered()
|
||||
//// .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)
|
||||
);
|
||||
|
||||
Console.ReadLine();
|
||||
AnsiConsole.Clear();
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Spectre.Console" Version="0.50.0" />
|
||||
<PackageReference Include="Spectre.Console.Json" Version="0.50.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</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