-
Notifications
You must be signed in to change notification settings - Fork 766
Expand file tree
/
Copy pathDatePicker.ps1
More file actions
53 lines (44 loc) · 1.3 KB
/
DatePicker.ps1
File metadata and controls
53 lines (44 loc) · 1.3 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using namespace Terminal.Gui.App
using namespace Terminal.Gui.ViewBase
using namespace Terminal.Gui.Views
# DatePicker.ps1 - Demonstrates Prompt API with DatePicker
#
# Usage:
# ./DatePicker.ps1 # Uses today's date
# ./DatePicker.ps1 '9/10/1966' # Uses specified date
#
# Prerequisites:
# dotnet build ..\Terminal.Gui -c Debug /p:CopyLocalLockFileAssemblies=true
#
# Returns:
# Selected date (yyyy-MM-dd format) if user accepts
# Nothing if user cancels
param(
[string]$InitialDate = ""
)
$dllFolder = "Terminal.Gui\bin\Debug\net10.0"
# Load all Terminal.Gui DLLs
Get-ChildItem $dllFolder -Filter *.dll | ForEach-Object {
Add-Type -Path $_.FullName -ErrorAction SilentlyContinue
}
# Parse initial date or use today
$date = if ($InitialDate) {
[DateTime]::Parse($InitialDate)
} else {
[DateTime]::Now
}
$app = [Application]::Create().Init()
$app.Init()
try {
$datePicker = [DatePicker]::new($date)
# Use the bool-returning overload (simpler for PowerShell)
# The generic Func<>-based overload requires complex delegate creation
$accepted = [Prompt]::Show($app, "Select Date", $datePicker)
if ($accepted) {
Write-Output $datePicker.Date.ToString("yyyy-MM-dd")
}
}
finally {
if ($datePicker) { $datePicker.Dispose() }
$app.Dispose()
}