Skip to content

Commit 9d3e7f2

Browse files
author
Donald M
committed
v0.2 final edits, for serious.
1 parent 3d555d2 commit 9d3e7f2

File tree

5 files changed

+153
-114
lines changed

5 files changed

+153
-114
lines changed

AnyBox.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ ScriptsToProcess = 'AnyBoxPrompt', 'HelperFunctions'
6161
# NestedModules = @()
6262

6363
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
64-
FunctionsToExport = 'ConvertTo-Base64', 'ConvertTo-Long', 'Show-AnyBox'
64+
FunctionsToExport = 'ConvertTo-Base64', 'New-AnyBoxPrompt', 'Show-AnyBox'
6565

6666
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
6767
CmdletsToExport = @()
@@ -79,7 +79,7 @@ AliasesToExport = @()
7979
# ModuleList = @()
8080

8181
# List of all files packaged with this module
82-
FileList = 'AnyBox.psd1', 'AnyBox.psm1', 'HelperFunctions.ps1', 'Show-AnyBox.ps1'
82+
FileList = 'AnyBox.psd1', 'AnyBox.psm1', 'HelperFunctions.ps1', 'AnyBoxPrompt.ps1', 'Show-AnyBox.ps1'
8383

8484
# HelpInfo URI of this module
8585
HelpInfoURI = 'https://www.donaldmellenbruch.com/post/introducing-the-anybox'

AnyBoxPrompt.ps1

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ namespace AnyBox {
33
public enum InputType {
44
None, Text, FileOpen, FileSave, Checkbox, Password, Date, Link
55
};
6+
7+
public enum MessagePosition { Top, Left };
68
79
public class Prompt
810
{
11+
public InputType InputType = InputType.Text;
912
public string Message;
13+
public MessagePosition MessagePosition = MessagePosition.Top;
1014
public string DefaultValue;
11-
public InputType InputType = InputType.Text;
1215
public System.UInt16 LineHeight = 1;
1316
public bool ReadOnly = false;
1417
public string[] ValidateSet;
@@ -17,3 +20,59 @@ namespace AnyBox {
1720
}
1821
}
1922
"@
23+
24+
function New-AnyBoxPrompt
25+
{
26+
[cmdletbinding()]
27+
param(
28+
[ValidateNotNullOrEmpty()]
29+
[AnyBox.InputType]$InputType = [AnyBox.InputType]::Text,
30+
[string]$Message,
31+
[ValidateNotNullOrEmpty()]
32+
[AnyBox.MessagePosition]$MessagePosition = [AnyBox.MessagePosition]::Top,
33+
[string]$DefaultValue,
34+
[ValidateScript({$_ -gt 0})]
35+
[UInt16]$LineHeight = 1,
36+
[switch]$ReadOnly,
37+
[switch]$ValidateNotEmpty,
38+
[string[]]$ValidateSet,
39+
[System.Management.Automation.ScriptBlock]$ValidateScript
40+
)
41+
42+
if ($InputType -ne [AnyBox.InputType]::Text)
43+
{
44+
if ($InputType -eq [AnyBox.InputType]::None) {
45+
return($null)
46+
}
47+
48+
if ($LineHeight -gt 1) {
49+
Write-Warning "'-LineHeight' parameter is only valid with text input."
50+
}
51+
52+
if ($InputType -eq [AnyBox.InputType]::Checkbox) {
53+
if (-not $Message) {
54+
Write-Warning "Checkbox input requires a message."
55+
$Message = 'Message'
56+
}
57+
}
58+
elseif ($InputType -eq [AnyBox.InputType]::Password) {
59+
if ($DefaultValue) {
60+
Write-Warning 'Password input does not accept a default value.'
61+
$DefaultValue = $null
62+
}
63+
}
64+
}
65+
66+
$p = New-Object AnyBox.Prompt
67+
68+
$p.InputType = $InputType
69+
$p.Message = $Message
70+
$p.MessagePosition = $MessagePosition
71+
$p.DefaultValue = $DefaultValue
72+
$p.LineHeight = $LineHeight
73+
$p.ValidateNotEmpty = $ValidateNotEmpty -as [bool]
74+
$p.ValidateSet = $ValidateSet
75+
$p.ValidateScript = $ValidateScript
76+
77+
return($p)
78+
}

HelperFunctions.ps1

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,3 @@
1-
function New-AnyBoxPrompt
2-
{
3-
<#
4-
.SYNOPSIS
5-
Short description
6-
.DESCRIPTION
7-
Long description
8-
.PARAMETER Path
9-
Specifies a path to one or more locations.
10-
.PARAMETER LiteralPath
11-
Specifies a path to one or more locations. Unlike Path, the value of LiteralPath is used exactly as it
12-
is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose
13-
it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any
14-
characters as escape sequences.
15-
.PARAMETER InputObject
16-
Specifies the object to be processed. You can also pipe the objects to this command.
17-
.EXAMPLE
18-
C:\PS>
19-
Example of how to use this cmdlet
20-
.EXAMPLE
21-
$prompt = New-AnyBoxPrompt -
22-
Show-AnyB
23-
.INPUTS
24-
Inputs to this cmdlet (if any)
25-
.OUTPUTS
26-
Output from this cmdlet (if any)
27-
#>
28-
[cmdletbinding()]
29-
param(
30-
[AnyBox.InputType]$InputType = [AnyBox.InputType]::Text,
31-
[string]$Message,
32-
[string]$DefaultValue,
33-
[ValidateScript({$_ -gt 0})]
34-
[UInt16]$LineHeight,
35-
[switch]$ReadOnly,
36-
[switch]$ValidateNotEmpty,
37-
[string[]]$ValidateSet,
38-
[System.Management.Automation.ScriptBlock]$ValidateScript
39-
)
40-
41-
if ($InputType -ne [AnyBox.InputType]::Text)
42-
{
43-
if ($InputType -eq [AnyBox.InputType]::None) {
44-
return($null)
45-
}
46-
47-
if ($LineHeight -gt 1) {
48-
Write-Warning "'-LineHeight' parameter is only valid with text input."
49-
}
50-
51-
if ($InputType -eq [AnyBox.InputType]::Checkbox) {
52-
if (-not $Message) {
53-
Write-Warning "Checkbox input requires a message."
54-
$Message = 'Message'
55-
}
56-
}
57-
elseif ($InputType -eq [AnyBox.InputType]::Password) {
58-
if ($DefaultValue) {
59-
Write-Warning 'Password input does not accept a default value.'
60-
$DefaultValue = $null
61-
}
62-
}
63-
}
64-
65-
$p = New-Object AnyBox.Prompt
66-
67-
$p.InputType = $InputType
68-
$p.Message = $Message
69-
$p.DefaultValue = $DefaultValue
70-
$p.LineHeight = $LineHeight
71-
$p.ValidateNotEmpty = $ValidateNotEmpty -as [bool]
72-
$p.ValidateSet = $ValidateSet
73-
$p.ValidateScript = $ValidateScript
74-
75-
return($p)
76-
}
77-
781
function ConvertTo-Base64
792
{
803
<#

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
# [Introducing the AnyBox](https://www.donaldmellenbruch.com/post/introducing-the-anybox/)
3+
4+
# Changelog
5+
All notable changes to this project will be documented in this file.
6+
7+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
8+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
9+
10+
## 0.2 - 2018-03-12
11+
12+
### Added
13+
14+
- `New-AnyBoxPrompt` function wrapper around the `AnyBox.Prompt` class. It includes a new parameter, `-MessagePosition`, which specifies whether to print the prompt message above or beside the input control (default='Top').
15+
- When `-GridData` is provided, DataGrid now fills all available space when window is resized.
16+
- `-GridAsList` parameter as a shortcut for `ConvertTo-Long`.
17+
18+
## 0.1 - 2018-03-06
19+
20+
- Initial release

0 commit comments

Comments
 (0)