Skip to content

Commit 369bd43

Browse files
author
donald
committed
finish 0.5.0
1 parent 7234658 commit 369bd43

File tree

9 files changed

+148
-508
lines changed

9 files changed

+148
-508
lines changed

AnyBox.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
ModuleToProcess = 'AnyBox.psm1'
44

55
# Version number of this module.
6-
ModuleVersion = '0.4.1'
6+
ModuleVersion = '0.5.0'
77

88
# Supported PSEditions
99
# CompatiblePSEditions = 'Desktop'
@@ -92,6 +92,7 @@
9292
FileList = @(
9393
'AnyBox.psd1',
9494
'AnyBox.psm1',
95+
'Types\AnyBox.cs',
9596
'Types\AnyBox.ps1',
9697
'Public\Show-AnyBox.ps1',
9798
'Public\New-AnyBoxPrompt.ps1',

CHANGELOG.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
# Changelog
22

3-
## v0.5.0 - 2022-05-31
3+
## v0.5.0 - 2022-06-01
44

55
### Added
66

77
- compatibility with pwsh v7
88
- function `ConvertTo-AnyBoxPrompts`, for building AnyBox prompts from function parameters
9-
- parameter `-PromptsFromFunc`, for displaying AnyBox of prompts for given function
10-
- aliases, e.g., `anybox -m hello -b hi` is `Show-AnyBox -Message hello -Button hi`
11-
- added more examples and an interactive test
9+
- parameter `-PromptsFromFunc` / `-PromptsFromScriptblock` for displaying AnyBox of prompts for given function / scriptblock.
10+
- more examples and an interactive test
11+
- aliases:
12+
- `show` = `Show-AnyBox`
13+
- `anybox` = `Show-AnyBox`
14+
- `-i` = `-Icon`
15+
- `-t` = `-Title`
16+
- `-m` = `-Messages`
17+
- `-c` = `-Comments`
18+
- `-b` = `-Buttons`
19+
- `-p` = `-Prompts`
20+
- `-d` = `-GridData`
21+
- `-f` = `-PromptsFromFunc`
22+
- `-pb` = `-ProgressBar`
23+
- `-bg` = `-BackgroundColor`
24+
- `-fg` = `-FontColor`
25+
- `-sec` = `-Timeout`
26+
- `-count` = `-Countdown`
1227

1328
## v0.4.0 - 2019-06-11
1429

Examples/Get-Greeting.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ function Get-Greeting
2727

2828
[string]$func_name = 'Get-Greeting'
2929

30-
[hashtable]$params = @{
30+
[hashtable]$style = @{
3131
Title = $func_name
3232
Button = 'OK'
3333
MinWidth = 300
3434
}
3535

36-
[hashtable]$resp = Show-AnyBox @params -PromptsFromFunc $func_name
36+
[hashtable]$resp = Show-AnyBox @style -PromptsFromFunc $func_name
3737

3838
if ($resp['OK'])
3939
{
4040
[hashtable]$func_params = Get-DictSubset -Source $resp -KeyStartsWith 'param_' -Trim
4141

4242
[string]$msg = & (Get-Command $func_name).ScriptBlock @func_params
4343

44-
$null = Show-AnyBox @params -Message $msg
44+
$null = Show-AnyBox @style -Message $msg
4545
}

Examples/banner.png

-6.98 KB
Binary file not shown.

Public/ConvertTo-AnyBoxPrompts.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function ConvertTo-AnyBoxPrompts
1010

1111
$ScriptBlock.Ast.Body.ParamBlock.Parameters | ForEach-Object {
1212
[string]$name = $_.Name.VariablePath.UserPath
13-
$attrs = $_ | Select-Object -ExpandProperty Attributes
13+
$attrs = @($_ | Select-Object -ExpandProperty Attributes)
1414

1515
[bool]$mandatory = $false
1616
[bool]$not_null = $false
@@ -53,12 +53,12 @@ function ConvertTo-AnyBoxPrompts
5353
}
5454
}
5555

56-
$default = $attrs | Select-Object -ExpandProperty Parent -First 1 | Select-Object -ExpandProperty DefaultValue | Select-Object -ExpandProperty Value
56+
$default = $attrs | Select-Object -ExpandProperty Parent -First 1 | Select-Object -ExpandProperty DefaultValue | Select-Object -ExpandProperty Value -EA 0
5757

5858
$param_config = @{
5959
'InputType' = $input_type
6060
'Name' = $Key_Prefix + $name
61-
'Message' = $name
61+
'Message' = $name + ":"
6262
'ValidateNotEmpty' = ($mandatory -or $not_null)
6363
'ValidateScript' = $validate_script
6464
'ValidateSet' = $validate_set

Public/Show-AnyBox.ps1

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ function Show-AnyBox
9090
[Parameter(ParameterSetName = 'create')]
9191
[string]$Image,
9292
[Parameter(ParameterSetName = 'create')]
93-
[Alias('m', 'Msg')]
94-
[string[]]$Message,
93+
[Alias('m', 'Message')]
94+
[string[]]$Messages,
9595
[Parameter(ParameterSetName = 'create')]
9696
[Alias('p', 'Prompt')]
9797
[object[]]$Prompts,
@@ -100,7 +100,7 @@ function Show-AnyBox
100100
[string]$PromptsFromFunc,
101101
[scriptblock]$PromptsFromScriptblock,
102102
[Parameter(ParameterSetName = 'create')]
103-
[Alias('b', 'Btn', 'Button')]
103+
[Alias('b', 'Button')]
104104
[object[]]$Buttons,
105105
[Parameter(ParameterSetName = 'create')]
106106
[string]$CancelButton,
@@ -110,9 +110,11 @@ function Show-AnyBox
110110
[ValidateScript({ $_ -gt 0 })]
111111
[uint16]$ButtonRows = 1,
112112
[Parameter(ParameterSetName = 'create')]
113-
[string[]]$Comment,
113+
[Alias('c', 'Comment')]
114+
[string[]]$Comments,
114115
[Parameter(ParameterSetName = 'create')]
115116
[ValidateSet('Left', 'Center')]
117+
[Alias('Alignment')]
116118
[string]$ContentAlignment = 'Left',
117119
[Parameter(ParameterSetName = 'create')]
118120
[switch]$CollapsibleGroups,
@@ -128,10 +130,10 @@ function Show-AnyBox
128130
[uint16]$FontSize = 12,
129131
[Parameter(ParameterSetName = 'create')]
130132
[ValidateNotNullOrEmpty()]
131-
[Alias('FgColor')]
133+
[Alias('fg')]
132134
[System.Windows.Media.Brush]$FontColor = 'Black',
133135
[Parameter(ParameterSetName = 'create')]
134-
[Alias('BgColor')]
136+
[Alias('bg')]
135137
[System.Windows.Media.Brush]$BackgroundColor,
136138
[Parameter(ParameterSetName = 'create')]
137139
[System.Windows.Media.Brush]$AccentColor = 'Gainsboro',
@@ -156,10 +158,13 @@ function Show-AnyBox
156158
[Parameter(ParameterSetName = 'create')]
157159
[switch]$HideTaskbarIcon,
158160
[Parameter(ParameterSetName = 'create')]
161+
[Alias('sec')]
159162
[uint32]$Timeout,
160163
[Parameter(ParameterSetName = 'create')]
164+
[Alias('count')]
161165
[switch]$Countdown,
162166
[Parameter(ParameterSetName = 'create')]
167+
[Alias('pb')]
163168
[switch]$ProgressBar,
164169
[Parameter(ParameterSetName = 'create')]
165170
[scriptblock]$While,
@@ -168,6 +173,7 @@ function Show-AnyBox
168173
[Parameter(ParameterSetName = 'create')]
169174
[System.Windows.Window]$ParentWindow = $null,
170175
[Parameter(ParameterSetName = 'create')]
176+
[Alias('d')]
171177
[object[]]$GridData,
172178
[Parameter(ParameterSetName = 'create')]
173179
[switch]$GridAsList,
@@ -353,7 +359,7 @@ function Show-AnyBox
353359
}
354360

355361
# Add message textblocks.
356-
if (($txtMsg = New-TextBlock -RefForm ([ref]$form) -Text $($Message -join [environment]::NewLine) -Name 'Message' -FontFamily $FontFamily -FontSize $FontSize -FontColor $FontColor -ContentAlignment $ContentAlignment))
362+
if (($txtMsg = New-TextBlock -RefForm ([ref]$form) -Text $($Messages -join [environment]::NewLine) -Name 'Message' -FontFamily $FontFamily -FontSize $FontSize -FontColor $FontColor -ContentAlignment $ContentAlignment))
357363
{
358364
$form.highStack.AddChild($txtMsg)
359365
}
@@ -565,7 +571,7 @@ function Show-AnyBox
565571
$inBox.HorizontalContentAlignment = 'Left'
566572

567573
# add with default value that is true boolean, not string
568-
$form.Result[$prmpt.Name] = $($prmpt.DefaultValue -eq [bool]::TrueString)
574+
$form.Result[$prmpt.Name] = $inBox.IsChecked
569575

570576
$inBox.add_Click({
571577
$form.Result[$_.Source.Name] = $_.Source.IsChecked
@@ -1163,7 +1169,7 @@ function Show-AnyBox
11631169
}
11641170

11651171
# Add comment textblocks.
1166-
if (($txtMsg = New-TextBlock -RefForm ([ref]$form) -text $($Comment -join [environment]::NewLine) -name 'txt_Explain' -FontFamily $FontFamily -FontSize $FontSize -FontColor $FontColor -ContentAlignment $ContentAlignment))
1172+
if (($txtMsg = New-TextBlock -RefForm ([ref]$form) -text $($Comments -join [environment]::NewLine) -name 'txt_Explain' -FontFamily $FontFamily -FontSize $FontSize -FontColor $FontColor -ContentAlignment $ContentAlignment))
11671173
{
11681174
$txtMsg.FontStyle = 'Italic'
11691175
$txtMsg.FontWeight = 'Normal'
@@ -1513,3 +1519,4 @@ $form.Result | Foreach-Object -Process {{
15131519
}
15141520

15151521
Set-Alias -Name 'anybox' -Value 'Show-AnyBox' -Description 'Show-AnyBox' -Scope 'Global'
1522+
Set-Alias -Name 'show' -Value 'Show-AnyBox' -Description 'Show-AnyBox' -Scope 'Global'

0 commit comments

Comments
 (0)