Patrik Svensson 8261b25e5c Fix tree rendering
Fixes some tree rendering problems where lines were not properly drawn
at some levels during some circumstances.

* Change the API back to only allow one root.
* Now uses a stack based approach to rendering instead of recursion.
* Removes the need for measuring the whole tree in advance.
  Leave this up to each child to render.
2021-01-10 15:55:11 +01:00

4.6 KiB

Title: Calendar Order: 40 RedirectFrom: calendar

The Calendar is used to render a calendar to the terminal.

Usage

To render a calendar, create a Calendar instance with a target date.

var calendar = new Calendar(2020,10);
AnsiConsole.Render(calendar);
               2020 October
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│ Sun │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │
├─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│     │     │     │     │ 1   │ 2   │ 3   │
│ 4   │ 5   │ 6   │ 7   │ 8   │ 9   │ 10  │
│ 11  │ 12  │ 13  │ 14  │ 15  │ 16  │ 17  │
│ 18  │ 19  │ 20  │ 21  │ 22  │ 23  │ 24  │
│ 25  │ 26  │ 27  │ 28  │ 29  │ 30  │ 31  │
│     │     │     │     │     │     │     │
└─────┴─────┴─────┴─────┴─────┴─────┴─────┘

Culture

You can set the calendar's culture to show localized weekdays.

var calendar = new Calendar(2020,10);
calendar.Culture("ja-JP");
AnsiConsole.Render(calendar);
               Oktober 2020
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│ Mån │ Tis │ Ons │ Tor │ Fre │ Lör │ Sön │
├─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│     │     │     │ 1   │ 2   │ 3   │ 4   │
│ 5   │ 6   │ 7   │ 8   │ 9   │ 10  │ 11* │
│ 12  │ 13  │ 14  │ 15  │ 16  │ 17  │ 18  │
│ 19  │ 20  │ 21  │ 22  │ 23  │ 24  │ 25  │
│ 26  │ 27  │ 28  │ 29  │ 30  │ 31  │     │
│     │     │     │     │     │     │     │
└─────┴─────┴─────┴─────┴─────┴─────┴─────┘

Header

You can hide the calendar header.

var calendar = new Calendar(2020,10);
calendar.ShowHeader();
AnsiConsole.Render(calendar);
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│ Sun │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │
├─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│     │     │     │     │ 1   │ 2   │ 3   │
│ 4   │ 5   │ 6   │ 7   │ 8   │ 9   │ 10  │
│ 11  │ 12  │ 13  │ 14  │ 15  │ 16  │ 17  │
│ 18  │ 19  │ 20  │ 21  │ 22  │ 23  │ 24  │
│ 25  │ 26  │ 27  │ 28  │ 29  │ 30  │ 31  │
│     │     │     │     │     │     │     │
└─────┴─────┴─────┴─────┴─────┴─────┴─────┘

You can set the header style of the calendar.

var calendar = new Calendar(2020, 10);
calendar.HeaderStyle(Style.Parse("blue bold"));
AnsiConsole.Render(calendar);

Calendar Events

You can add an event to the calendar. If a date has an event associated with it, the date gets highlighted in the calendar.

var calendar = new Calendar(2020,10);
calendar.AddCalendarEvent(2020, 10, 11);
AnsiConsole.Render(calendar);
               2020 October
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│ Sun │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │
├─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│     │     │     │     │ 1   │ 2   │ 3   │
│ 4   │ 5   │ 6   │ 7   │ 8   │ 9   │ 10  │
│ 11* │ 12  │ 13  │ 14  │ 15  │ 16  │ 17  │
│ 18  │ 19  │ 20  │ 21  │ 22  │ 23  │ 24  │
│ 25  │ 26  │ 27  │ 28  │ 29  │ 30  │ 31  │
│     │     │     │     │     │     │     │
└─────┴─────┴─────┴─────┴─────┴─────┴─────┘

Highlight style

You can set the highlight style for a calendar event via SetHighlightStyle.

var calendar = new Calendar(2020, 10);
calendar.AddCalendarEvent(2020, 10, 11);
calendar.HighlightStyle(Style.Parse("yellow bold"));
AnsiConsole.Render(calendar);