← Back to Home • Next: Calendar — Operations →
Every fluent method on ICalendarControl. Each returns the same control instance, so calls chain
in any order. Call Run last.
The factory is
PromptPlus.Controls.Calendar(string prompt = "", string? description = null), which returnsICalendarControl.
Quick jump: Layout · Culture · FirstDayOfWeek · Range · DisableDates · DisabledWeekend · AddNote · AddNotes · PageSize · Highlights · Interaction · InteractionAsync · Default · PredicateSelected · PredicateSelectedAsync · ChangeDescription · ChangeDescriptionAsync · EnableHistory · Styles · Options · Run
LayoutICalendarControl Layout(CalendarLayout layout = CalendarLayout.SingleGrid)
Sets how the grid and its lines are drawn.
CalendarLayout |
Renders |
|---|---|
SingleGrid |
Single-line box drawing (default) |
DoubleGrid |
Double-line box drawing |
AsciiSingleGrid |
ASCII single-line grid (portable, no Unicode) |
AsciiDoubleGrid |
ASCII double-line grid |
PromptPlus.Controls.Calendar("Date")
.Layout(CalendarLayout.AsciiSingleGrid)
.Run();
CultureICalendarControl Culture(CultureInfo culture)
ICalendarControl Culture(string cultureName)
Sets the culture used to display month names, day names, and date formatting — and to parse and
validate dates. The default is the current PromptPlus culture. The string overload is shorthand for
Culture(new CultureInfo(cultureName)).
using PromptPlusLibrary;
using System.Globalization;
PromptPlus.Controls.Calendar("Data")
.Culture("pt-BR")
.Run();
PromptPlus.Controls.Calendar("Date")
.Culture(new CultureInfo("en-US"))
.Run();
Culture(CultureInfo)throwsArgumentNullExceptionifcultureisnull;Culture(string)throwsArgumentExceptionifcultureNameisnullor empty.
FirstDayOfWeekICalendarControl FirstDayOfWeek(DayOfWeek firstDayOfWeek)
Sets which weekday appears in the first column. When not set, defaults to
PromptPlus.Config.FirstDayOfWeek (DayOfWeek.Sunday unless you’ve changed it globally) —
not the active culture’s own first-day-of-week convention.
using PromptPlusLibrary;
using System;
PromptPlus.Controls.Calendar("Date")
.FirstDayOfWeek(DayOfWeek.Monday)
.Run();
RangeICalendarControl Range(DateTime minValue, DateTime maxValue)
Defines an inclusive window of selectable dates. Days outside it are shown but cannot be confirmed.
using PromptPlusLibrary;
using System;
var today = DateTime.Now.Date;
PromptPlus.Controls.Calendar("Date")
.Range(today.AddDays(-3), today.AddDays(3))
.Run();
Throws
ArgumentOutOfRangeExceptionifminValueis greater thanmaxValue. ADefaultoutside the range is ignored.
DisableDatesICalendarControl DisableDates(params DateTime[] dates)
Marks specific dates as non-selectable (rendered with the Disabled style).
using PromptPlusLibrary;
using System;
var today = DateTime.Now.Date;
PromptPlus.Controls.Calendar("Date")
.DisableDates(today.AddDays(1), today.AddDays(2))
.Run();
Throws
ArgumentNullExceptionifdatesisnull.
DisabledWeekendICalendarControl DisabledWeekend(bool value = true)
Blocks Saturday and Sunday from selection. Default true when called.
PromptPlus.Controls.Calendar("Business date")
.DisabledWeekend()
.Run();
AddNoteICalendarControl AddNote(DateTime value, string? note = null)
Attaches a note to a single date. A null note becomes an empty string. Notes for the highlighted
day are shown when the user presses F2 (see Operations).
using PromptPlusLibrary;
using System;
PromptPlus.Controls.Calendar("Date", "Press [F2] to read notes")
.AddNote(DateTime.Now.Date, "Team standup at 09:00")
.Run();
AddNotesICalendarControl AddNotes((DateTime, string?)[] notes)
Adds several notes at once as (date, note) tuples. A null note becomes an empty string.
using PromptPlusLibrary;
using System;
var today = DateTime.Now.Date;
PromptPlus.Controls.Calendar("Date")
.AddNotes(
[
(today.AddDays(1), "Tomorrow note"),
(today.AddDays(2), "Day+2 note")
])
.Run();
PageSizeICalendarControl PageSize(byte value)
Maximum number of notes shown per page (valid range 0–255). 0 (default) auto-computes from
terminal height, reserving lines for header, footer, and pagination. Values above the available
height are clamped.
PromptPlus.Controls.Calendar("Date").PageSize(3).Run();
HighlightsICalendarControl Highlights(params DateTime[] dates)
Marks one or more dates so they stand out (rendered with the CalendarHighlight style). Highlighted
dates remain selectable — the marking is purely visual.
using PromptPlusLibrary;
using System;
var today = DateTime.Now.Date;
PromptPlus.Controls.Calendar("Date")
.Highlights(today, today.AddDays(3))
.Run();
Throws
ArgumentNullExceptionifdatesisnull.
InteractionICalendarControl Interaction<T>(IEnumerable<T> items, Action<T, ICalendarControl> interactionAction)
Iterates a source collection and lets you configure the calendar programmatically per item — useful for generating notes from data.
using PromptPlusLibrary;
using System;
var today = DateTime.Now.Date;
PromptPlus.Controls.Calendar("Date")
.Interaction(myEvents, (evt, ctrl) => ctrl.AddNote(evt.Date, evt.Title))
.Run();
Throws
ArgumentNullExceptionifitemsorinteractionActionisnull.
InteractionAsyncICalendarControl InteractionAsync<T>(IEnumerable<T> items, Func<T, ICalendarControl, Task> interactionAction)
Asynchronous version of Interaction, for sources that need awaiting per item.
using PromptPlusLibrary;
using System;
var today = DateTime.Now.Date;
PromptPlus.Controls.Calendar("Date")
.InteractionAsync([8, 9], async (offset, ctrl) =>
{
await Task.Delay(1).ConfigureAwait(false);
ctrl.AddNote(today.AddDays(offset), $"Async note {offset}");
})
.Run();
Throws
ArgumentNullExceptionifitemsorinteractionActionisnull.
DefaultICalendarControl Default(DateTime value, bool useDefaultHistory = true)
Opens the grid on value (default is today). When useDefaultHistory is true and
history is enabled, the last history value is preferred. A value outside the
Range is ignored.
using PromptPlusLibrary;
using System;
PromptPlus.Controls.Calendar("Date")
.Default(DateTime.Now)
.Run();
Validation runs on Enter. On failure the grid stays open and shows an error.
PredicateSelectedICalendarControl PredicateSelected(Func<DateTime?, bool> isValidSelection)
ICalendarControl PredicateSelected(Func<DateTime?, (bool, string?)> validateSelection)
| Overload | Return | Behavior |
|---|---|---|
Func<DateTime?, bool> |
true = valid |
Generic error on failure |
Func<DateTime?, (bool, string?)> |
(isValid, message) |
Custom message on failure |
using PromptPlusLibrary;
using System;
// bool overload — only odd days allowed
PromptPlus.Controls.Calendar("Select odd day")
.PredicateSelected(date => date.HasValue && date.Value.Day % 2 == 1)
.Run();
// message overload — custom error text
PromptPlus.Controls.Calendar("Select day <= 28")
.PredicateSelected(date =>
{
if (!date.HasValue)
return (false, "Date is required");
return date.Value.Day <= 28
? (true, (string?)null)
: (false, "Only days up to 28 are allowed");
})
.Run();
PredicateSelectedAsyncICalendarControl PredicateSelectedAsync(Func<DateTime?, Task<bool>> isValidSelection)
ICalendarControl PredicateSelectedAsync(Func<DateTime?, Task<(bool, string?)>> validateSelection)
Asynchronous counterparts of PredicateSelected.
using PromptPlusLibrary;
using System;
var today = DateTime.Now.Date;
PromptPlus.Controls.Calendar("Select future date")
.PredicateSelectedAsync(async date =>
{
await Task.Delay(1).ConfigureAwait(false);
return date.HasValue && date.Value.Date >= today;
})
.Run();
⚠️ The async predicate is awaited synchronously (blocking) on the UI thread — keep it fast.
ChangeDescriptionICalendarControl ChangeDescription(Func<DateTime?, string> value)
Recomputes the description from the currently highlighted date as the user navigates.
using PromptPlusLibrary;
using System;
PromptPlus.Controls.Calendar("Date")
.ChangeDescription(date => $"Selected day: {date:yyyy-MM-dd}")
.Run();
Throws
ArgumentNullExceptionifvalueisnull.
ChangeDescriptionAsyncICalendarControl ChangeDescriptionAsync(Func<DateTime?, Task<string>> value)
Asynchronous version of ChangeDescription.
using PromptPlusLibrary;
using System;
PromptPlus.Controls.Calendar("Date")
.ChangeDescriptionAsync(date => Task.FromResult($"Async: {date:dddd, dd MMM yyyy}"))
.Run();
Throws
ArgumentNullExceptionifvalueisnull.
EnableHistoryICalendarControl EnableHistory(string filename, Action<IHistoryOptions>? options = null)
Persists confirmed dates to filename and can pre-select the last one (via
Default(..., useDefaultHistory: true)). The IHistoryOptions builder is identical to
the one documented for
Input → EnableHistory (MinPrefixLength, MaxItems,
ExpirationTime, FilterType, PageSize).
using PromptPlusLibrary;
using System;
PromptPlus.Controls.Calendar("Date")
.Default(DateTime.Now, useDefaultHistory: true)
.EnableHistory("calendar-history", opt => opt.MaxItems(5))
.Run();
Throws
ArgumentNullExceptioniffilenameisnull.
StylesICalendarControl Styles(CalendarStyles styleType, Style style)
Recolors one visual region of this control. See the region list and examples on the Styles page.
using PromptPlusLibrary;
using ConsolePlusLibrary; // Color, Style live here
PromptPlus.Controls.Calendar("Date")
.Styles(CalendarStyles.Selected, new Style(Color.Green, Color.Default))
.Run();
Throws
ArgumentNullExceptionifstyleisnull.
OptionsICalendarControl Options(Action<IControlOptions> options)
Overrides global behaviors for this one control (prompt/description text, abort key, tooltip, hide-after-finish). See Global Behaviors → Per-Control Override.
PromptPlus.Controls.Calendar("Date")
.Options(opt =>
{
opt.Description("Custom options sample");
opt.ShowTooltip(true);
opt.EnabledAbortKey(true);
})
.Run();
Throws
ArgumentNullExceptionifoptionsisnull.
RunResultPrompt<DateTime?> Run(CancellationToken token = default)
Renders the grid and blocks until the user confirms (Enter) or aborts (Esc). Returns
ResultPrompt<DateTime?> — the .Content is null when
aborted.
var result = PromptPlus.Controls.Calendar("Date").Run();
if (!result.IsAborted && result.Content.HasValue)
PromptPlus.Console.WriteLine(result.Content.Value.ToString("d"));
CalendarStyles regions