-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Month calendars #207
Merged
Month calendars #207
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Google.Apis.Calendar.v3.Data; | ||
using Guppi.Core.Exceptions; | ||
using Guppi.Core.Extensions; | ||
using Guppi.Core.Interfaces.Services; | ||
|
@@ -43,6 +44,13 @@ public IEnumerable<Command> GetCommands() | |
await Agenda(midnight, "Tomorrow's agenda", markdown, table); | ||
}, markdown, table); | ||
|
||
var month = new Command("month", "Displays this month's calendar") { markdown }; | ||
month.SetHandler(async (bool markdown) => | ||
{ | ||
if (markdown) await MonthMarkdown(); | ||
else Month(); | ||
}, markdown); | ||
|
||
var free = new Command("free", "Displays free time for a given day"); | ||
free.AddArgument(new Argument<DateTime>("date", "The date to check")); | ||
free.Handler = CommandHandler.Create<DateTime>(FreeTime); | ||
|
@@ -59,6 +67,7 @@ public IEnumerable<Command> GetCommands() | |
next, | ||
today, | ||
tomorrow, | ||
month, | ||
free, | ||
logout, | ||
configure | ||
|
@@ -260,4 +269,72 @@ private static string JoinLink(Core.Entities.Calendar.Event eventItem) => | |
|
||
private static string TableLinkedSummary(Core.Entities.Calendar.Event eventItem) => | ||
string.IsNullOrEmpty(eventItem.MeetingUrl) ? eventItem.Summary : $"[{eventItem.Summary}]({eventItem.MeetingUrl})"; | ||
|
||
private static void Month() | ||
{ | ||
(DateOnly start, DateOnly end) = GetMonthRange(); | ||
|
||
AnsiConsoleHelper.TitleRule($":calendar: {start:MMMM yyyy}"); | ||
|
||
var table = new Table(); | ||
table.Border(TableBorder.Rounded); | ||
|
||
table.AddColumn(new TableColumn(new Markup("[yellow]Sun[/]")).RightAligned()); | ||
table.AddColumn(new TableColumn(new Markup("[yellow]Mon[/]")).RightAligned()); | ||
table.AddColumn(new TableColumn(new Markup("[yellow]Tue[/]")).RightAligned()); | ||
table.AddColumn(new TableColumn(new Markup("[yellow]Wed[/]")).RightAligned()); | ||
table.AddColumn(new TableColumn(new Markup("[yellow]Thu[/]")).RightAligned()); | ||
table.AddColumn(new TableColumn(new Markup("[yellow]Fri[/]")).RightAligned()); | ||
table.AddColumn(new TableColumn(new Markup("[yellow]Sat[/]")).RightAligned()); | ||
|
||
// Add empty cells for the last days of the previous month | ||
var row = Enumerable.Range(0, 7).Select(_ => "").ToArray(); | ||
for (var day = start; day <= end; day = day.AddDays(1)) | ||
{ | ||
row[(int)day.DayOfWeek] = day.Day.ToString(); | ||
if (day.DayOfWeek == DayOfWeek.Saturday) | ||
{ | ||
table.AddRow(row); | ||
row = Enumerable.Range(0, 7).Select(_ => "").ToArray(); | ||
} | ||
} | ||
if (end.DayOfWeek != DayOfWeek.Saturday) | ||
table.AddRow(row); | ||
|
||
AnsiConsole.Write(table); | ||
|
||
AnsiConsole.WriteLine(); | ||
AnsiConsoleHelper.Rule("white"); | ||
} | ||
|
||
private static async Task MonthMarkdown() | ||
{ | ||
(DateOnly start, DateOnly end) = GetMonthRange(); | ||
StringBuilder cal = new(); | ||
cal.AppendLine("| Day | Date | Habits | Notes |"); | ||
cal.AppendLine("| --- | ---- | ------ | ----- |"); | ||
for (var day = start; day <= end; day = day.AddDays(1)) | ||
{ | ||
cal.AppendLine($"| **{day:ddd}** | [[{day:yyyy-MM-dd}]] | | |"); | ||
} | ||
|
||
AnsiConsoleHelper.TitleRule($":calendar: {start:MMMM yyyy}"); | ||
|
||
AnsiConsole.WriteLine(); | ||
AnsiConsole.WriteLine(cal.ToString()); | ||
await TextCopy.ClipboardService.SetTextAsync(cal.ToString()); | ||
AnsiConsole.WriteLine(); | ||
AnsiConsole.MarkupLine("[green]:green_circle: Copied to clipboard[/]"); | ||
|
||
AnsiConsole.WriteLine(); | ||
AnsiConsoleHelper.Rule("white"); | ||
} | ||
|
||
private static (DateOnly start, DateOnly end) GetMonthRange() | ||
{ | ||
var now = DateTime.Now; | ||
var start = new DateOnly(now.Year, now.Month, 1); | ||
var end = new DateOnly(now.Year, now.Month, DateTime.DaysInMonth(now.Year, now.Month)); | ||
return (start, end); | ||
} | ||
Comment on lines
+273
to
+339
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add unit tests and improve error handling. The new calendar functionality needs test coverage and better error handling:
Would you like me to help create:
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Enhance calendar display with current day highlight and events.
The calendar display implementation is functional but could be improved:
Here's a suggested improvement:
Would you like me to provide an implementation for including all-day events in the calendar display?