diff --git a/Guppi.Console/Guppi.Console.csproj b/Guppi.Console/Guppi.Console.csproj index 4fea213..119df23 100644 --- a/Guppi.Console/Guppi.Console.csproj +++ b/Guppi.Console/Guppi.Console.csproj @@ -13,7 +13,7 @@ https://github.com/rprouse/guppi https://github.com/rprouse/guppi dotnet-guppi - 6.1.2 + 6.2.0 true guppi ./nupkg diff --git a/Guppi.Console/Properties/launchSettings.json b/Guppi.Console/Properties/launchSettings.json index 5dcfc93..9a590db 100644 --- a/Guppi.Console/Properties/launchSettings.json +++ b/Guppi.Console/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Guppi.Console": { "commandName": "Project", - "commandLineArgs": "cal agenda" + "commandLineArgs": "cal agenda -t" } } } diff --git a/Guppi.Console/Skills/CalendarSkill.cs b/Guppi.Console/Skills/CalendarSkill.cs index f439784..4689e5f 100644 --- a/Guppi.Console/Skills/CalendarSkill.cs +++ b/Guppi.Console/Skills/CalendarSkill.cs @@ -19,27 +19,29 @@ internal class CalendarSkill(ICalendarService service) : ISkill public IEnumerable GetCommands() { - var markdown = new Option(new string[] { "--markdown", "-m" }, "Display as Markdown to be copied into Notes"); + var markdown = new Option(["--markdown", "-m"], "Display as Markdown to be copied into Notes"); + var table = new Option(["--table", "-t"], "Display as a markdown table"); + var next = new Command("next", "Views next calendar event") { markdown }; next.AddAlias("view"); next.SetHandler(async (bool markdown) => await Next(markdown), markdown); - var today = new Command("today", "Displays today's agenda") { markdown }; + var today = new Command("today", "Displays today's agenda") { markdown, table }; today.AddAlias("agenda"); - today.SetHandler(async (bool markdown) => + today.SetHandler(async (bool markdown, bool table) => { var now = DateTime.Now; var midnight = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0, DateTimeKind.Local); - await Agenda(midnight, "Today's agenda", markdown); - }, markdown); + await Agenda(midnight, "Today's agenda", markdown, table); + }, markdown, table); - var tomorrow = new Command("tomorrow", "Displays tomorrow's agenda") { markdown }; - tomorrow.SetHandler(async (bool markdown) => + var tomorrow = new Command("tomorrow", "Displays tomorrow's agenda") { markdown, table }; + tomorrow.SetHandler(async (bool markdown, bool table) => { var now = DateTime.Now.AddDays(1); var midnight = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0, DateTimeKind.Local); - await Agenda(midnight, "Tomorrow's agenda", markdown); - }, markdown); + await Agenda(midnight, "Tomorrow's agenda", markdown, table); + }, markdown, table); var free = new Command("free", "Displays free time for a given day"); free.AddArgument(new Argument("date", "The date to check")); @@ -99,7 +101,7 @@ private async Task Next(bool markdown) var line = $"- **{start}{end}** {eventItem.Summary}{JoinLink(eventItem)}"; sb.AppendLine(line); AnsiConsole.WriteLine(line); - TextCopy.ClipboardService.SetText(sb.ToString()); + await TextCopy.ClipboardService.SetTextAsync(sb.ToString()); AnsiConsole.MarkupLine("[green]:green_circle: Copied to clipboard[/]"); AnsiConsole.WriteLine(); } @@ -126,7 +128,7 @@ private async Task Next(bool markdown) } } - private async Task Agenda(DateTime now, string title, bool markdown) + private async Task Agenda(DateTime now, string title, bool markdown, bool table) { try { @@ -135,21 +137,27 @@ private async Task Agenda(DateTime now, string title, bool markdown) AnsiConsoleHelper.TitleRule($":calendar: {title}"); StringBuilder sb = new(); + if (table) + { + sb.AppendLine("| Time | Meeting | Participants | Objective |"); + sb.AppendLine("| ---- | ------- | ------------ | --------- |"); + } + try { if (events.Any()) { bool found = false; - foreach (var _ in events.Where(eventItem => DisplayEvent(eventItem, markdown, sb)).Select(eventItem => new { })) + foreach (var _ in events.Where(eventItem => DisplayEvent(eventItem, markdown, table, sb)).Select(eventItem => new { })) { found = true; } if (found) { - if (markdown) + if (markdown || table) { - TextCopy.ClipboardService.SetText(sb.ToString()); + await TextCopy.ClipboardService.SetTextAsync(sb.ToString()); AnsiConsole.WriteLine(); AnsiConsole.MarkupLine("[green]:green_circle: Copied to clipboard[/]"); } @@ -175,7 +183,7 @@ private async Task Agenda(DateTime now, string title, bool markdown) } } - private static bool DisplayEvent(Core.Entities.Calendar.Event eventItem, bool markdown, StringBuilder markdownBuffer) + private static bool DisplayEvent(Core.Entities.Calendar.Event eventItem, bool markdown, bool table, StringBuilder markdownBuffer) { string start = eventItem.Start?.ToString("HH:mm"); if (string.IsNullOrEmpty(start)) @@ -183,7 +191,14 @@ private static bool DisplayEvent(Core.Entities.Calendar.Event eventItem, bool ma return false; } string end = eventItem.End?.ToString("-HH:mm") ?? ""; - if (markdown) + + if (table) + { + var line = $"| {eventItem.Start.GetEmoji()} **{start}{end}** | {TableLinkedSummary(eventItem)} | | |"; + markdownBuffer.AppendLine(line); + AnsiConsole.WriteLine(line); + } + else if (markdown) { var line = $"- {eventItem.Start.GetEmoji()} **{start}{end}** {eventItem.Summary}{JoinLink(eventItem)}"; markdownBuffer.AppendLine(line); @@ -241,4 +256,7 @@ private async Task FreeTime(DateTime date) private static string JoinLink(Core.Entities.Calendar.Event eventItem) => string.IsNullOrEmpty(eventItem.MeetingUrl) ? "" : $" [Join]({eventItem.MeetingUrl})"; + + private static string TableLinkedSummary(Core.Entities.Calendar.Event eventItem) => + string.IsNullOrEmpty(eventItem.MeetingUrl) ? eventItem.Summary : $"[{eventItem.Summary}]({eventItem.MeetingUrl})"; }