Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Guppi.Console/Guppi.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageProjectUrl>https://github.com/rprouse/guppi</PackageProjectUrl>
<RepositoryUrl>https://github.com/rprouse/guppi</RepositoryUrl>
<PackageId>dotnet-guppi</PackageId>
<Version>7.0.1</Version>
<Version>7.1.0</Version>
<PackAsTool>true</PackAsTool>
<ToolCommandName>guppi</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
Expand Down
4 changes: 4 additions & 0 deletions Guppi.Console/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"commandName": "Project",
"commandLineArgs": "calendar agenda"
},
"Guppi calendar month": {
"commandName": "Project",
"commandLineArgs": "calendar month -m --offset 3"
},
"Guppi todo sync": {
"commandName": "Project",
"commandLineArgs": "todo sync"
Expand Down
26 changes: 14 additions & 12 deletions Guppi.Console/Skills/CalendarSkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ public IEnumerable<Command> GetCommands()
}, markdown, table);

var nextMonth = new Option<bool>(["--next", "-n"], "Display next month's calendar");
var month = new Command("month", "Displays this month's calendar") { markdown, nextMonth };
month.SetHandler(async (bool markdown, bool nextMonth) =>
var offset = new Option<int>(["--offset", "-o"], "Offset the month by a number of months, e.g. -1 for last month, 0 for this month, 1 for next month");
nextMonth.SetDefaultValue(false);
offset.SetDefaultValue(0);
var month = new Command("month", "Displays this month's calendar") { markdown, nextMonth, offset };
month.SetHandler(async (bool markdown, bool nextMonth, int offset) =>
{
if (markdown) await MonthMarkdown(nextMonth);
else Month(nextMonth);
}, markdown, nextMonth);
int monthOffset = nextMonth ? 1 : offset;
(DateOnly start, DateOnly end) = GetMonthRange(monthOffset);
if (markdown) await MonthMarkdown(start, end);
else Month(start, end);
}, markdown, nextMonth, offset);

var free = new Command("free", "Displays free time for a given day");
free.AddArgument(new Argument<DateTime>("date", "The date to check"));
Expand Down Expand Up @@ -276,10 +281,8 @@ 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(bool nextMonth)
private static void Month(DateOnly start, DateOnly end)
{
(DateOnly start, DateOnly end) = GetMonthRange(nextMonth);

AnsiConsoleHelper.TitleRule($":calendar: {start:MMMM yyyy}");

var table = new Table();
Expand Down Expand Up @@ -313,9 +316,8 @@ private static void Month(bool nextMonth)
AnsiConsoleHelper.Rule("white");
}

private static async Task MonthMarkdown(bool nextMonth)
private static async Task MonthMarkdown(DateOnly start, DateOnly end)
{
(DateOnly start, DateOnly end) = GetMonthRange(nextMonth);
StringBuilder cal = new();
cal.AppendLine("| Day | Date | Habits | Notes |");
cal.AppendLine("| --- | ---- | ------ | ----- |");
Expand All @@ -336,9 +338,9 @@ private static async Task MonthMarkdown(bool nextMonth)
AnsiConsoleHelper.Rule("white");
}

private static (DateOnly start, DateOnly end) GetMonthRange(bool nextMonth)
private static (DateOnly start, DateOnly end) GetMonthRange(int addMonths)
{
var now = nextMonth ? DateTime.Now.AddMonths(1) : DateTime.Now;
var now = DateTime.Now.AddMonths(addMonths);
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);
Expand Down
Loading