Skip to content

Commit

Permalink
feat: Mounting $LightScript ( Fixes #96, Fixes #97, Fixes #98 )
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Jan 14, 2024
2 parents 8e183fc + 2b22b90 commit 28c4e3f
Show file tree
Hide file tree
Showing 58 changed files with 1,851 additions and 5,563 deletions.
205 changes: 146 additions & 59 deletions LightScript.format.ps1xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-16"?>
<!-- Generated with EZOut 1.9.7: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
<!-- Generated with EZOut 2.0.3: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
<Configuration>
<ViewDefinitions>
<View>
Expand Down Expand Up @@ -289,24 +289,24 @@ $(@(foreach ($_ in $actionLines) {
} while ($false)



$__ = $_
$ci = . {

$CellColorValue = $($Script:_LastCellStyle = $($__ = $_;. {
if ($_.Status -eq 'Enabled') {
'#00ff00'
} else {
'#ff0000'
}
}
$_ = $__
if ($ci -is [string]) {
$ci = &amp; ${LightScript_Format-RichText} -NoClear -ForegroundColor $ci
} else {
$ci = &amp; ${LightScript_Format-RichText} -NoClear @ci
}
$output = . {$_.'Status'}
@($ci; $output; &amp; ${LightScript_Format-RichText}) -join ""
</ScriptBlock>
};$_ = $__);$Script:_LastCellStyle)

if ($CellColorValue -and $CellColorValue -is [string]) {
$CellColorValue = &amp; ${LightScript_Format-RichText} -NoClear -ForegroundColor $CellColorValue
} elseif (`$CellColorValue -is [Collections.IDictionary]) {
$CellColorValue = &amp; ${LightScript_Format-RichText} -NoClear @CellColorValue
}

$output = . {$_.'Status'}
@($CellColorValue; $output; &amp; ${LightScript_Format-RichText}) -join ''
</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Time</PropertyName>
Expand Down Expand Up @@ -853,7 +853,7 @@ New-Object PSObject -Property ([Ordered]@{
.Notes
Stylized Output works in two contexts at present:
* Rich consoles (Windows Terminal, PowerShell.exe, Pwsh.exe) (when $host.UI.SupportsVirtualTerminal)
* Web pages (Based off the presence of a $Request variable, or when $host.UI.SupportsHTML (you must add this property to $host.UI))
* Web pages (Based off the presence of a $Request variable, or when $host.UI.SupportsHTML (you must add this property to $host.UI))
#&gt;
[Management.Automation.Cmdlet("Format","Object")]
[ValidateScript({
Expand All @@ -862,12 +862,13 @@ New-Object PSObject -Property ([Ordered]@{
if (-not ($canUseANSI -or $canUseHTML)) { return $false}
return $true
})]
[OutputType([string])]
param(
# The input object
[Parameter(ValueFromPipeline)]
[PSObject]
$InputObject,

# The foreground color
[string]$ForegroundColor,

Expand Down Expand Up @@ -902,8 +903,23 @@ New-Object PSObject -Property ([Ordered]@{

# If set, will invert text
[switch]$Invert,

# If provided, will create a hyperlink to a given uri
[Alias('Hyperlink', 'Href')]
[uri]
$Link,

# If set, will not clear formatting
[switch]$NoClear
[switch]$NoClear,

# The alignment. Defaulting to Left.
# Setting an alignment will pad the remaining space on each line.
[ValidateSet('Left','Right','Center')]
[string]
$Alignment,

# The length of a line. By default, the buffer width
[int]$LineLength = $($host.UI.RawUI.BufferSize.Width)
)

begin {
Expand All @@ -913,12 +929,27 @@ New-Object PSObject -Property ([Ordered]@{
Output='';Error='BrightRed';Warning='BrightYellow';
Verbose='BrightCyan';Debug='Yellow';Progress='Cyan';
Success='BrightGreen';Failure='Red';Default=''}

$ansiCode = [Regex]::new(@'
(?&lt;ANSI_Code&gt;
(?-i)\e # An Escape
\[ # Followed by a bracket
(?&lt;ParameterBytes&gt;[\d\:\;\&lt;\=\&gt;\?]{0,}) # Followed by zero or more parameter
bytes
(?&lt;IntermediateBytes&gt;[\s\!\"\#\$\%\&amp;\'\(\)\*\+\,\-\.\/]{0,}) # Followed by zero or more
intermediate bytes
(?&lt;FinalByte&gt;[\@ABCDEFGHIJKLMNOPQRSTUVWXYZ\[\\\]\^_\`abcdefghijklmnopqrstuvwxyz\{\|\}\~]) # Followed by a final byte

)
'@)
$esc = [char]0x1b
$standardColors = 'Black', 'Red', 'Green', 'Yellow', 'Blue','Magenta', 'Cyan', 'White'
$brightColors = 'BrightBlack', 'BrightRed', 'BrightGreen', 'BrightYellow', 'BrightBlue','BrightMagenta', 'BrightCyan', 'BrightWhite'

$allOutput = @()

$n =0
$cssClasses = @()
$cssClasses = @()
$colorAttributes =
@(:nextColor foreach ($hc in $ForegroundColor,$BackgroundColor) {
$n++
Expand Down Expand Up @@ -1095,6 +1126,21 @@ New-Object PSObject -Property ([Ordered]@{
if ($canUseHTML) { "border-bottom: 3px double;"}
elseif ($canUseANSI) {'' +$esc + "[21m" }
}

if ($Alignment -and $canUseHTML) {
"display:block;text-align:$($Alignment.ToLower())"
}

if ($Link) {
if ($canUseHTML) {
# Hyperlinks need to be a nested element
# so we will not add it to style attributes for HTML
}
elseif ($canUseANSI) {
# For ANSI,
'' + $esc + ']8;;' + $Link + $esc + '\'
}
}

)

Expand All @@ -1104,61 +1150,102 @@ New-Object PSObject -Property ([Ordered]@{
if ($styleAttributes) { " style='$($styleAttributes -join ';')'"}
)$(
if ($cssClasses) { " class='$($cssClasses -join ' ')'"}
)&gt;"
)&gt;" + $(
if ($Link) {
"&lt;a href='$link'&gt;"
}
)
} elseif ($canUseANSI) {
$styleAttributes -join ''
}
}

process {
if ($header) {
"$header" + "$(if ($inputObject) { $inputObject | Out-String})".Trim()
}
elseif ($inputObject) {
($inputObject | Out-String).Trim()
}
$inputObjectAsString =
"$(if ($inputObject) { $inputObject | Out-String})".Trim()

$inputObjectAsString =
if ($Alignment -and -not $canUseHTML) {
(@(foreach ($inputObjectLine in ($inputObjectAsString -split '(?&gt;\r\n|\n)')) {
$inputObjectLength = $ansiCode.Replace($inputObjectLine, '').Length
if ($inputObjectLength -lt $LineLength) {
if ($Alignment -eq 'Left') {
$inputObjectLine
} elseif ($Alignment -eq 'Right') {
(' ' * ($LineLength - $inputObjectLength)) + $inputObjectLine
} else {
$half = ($LineLength - $inputObjectLength)/2
(' ' * [Math]::Floor($half)) + $inputObjectLine +
(' ' * [Math]::Ceiling($half))
}
}
else {
$inputObjectLine
}
}) -join [Environment]::NewLine) + [Environment]::newline
} else {
$inputObjectAsString
}

$allOutput +=
if ($header) {
"$header" + $inputObjectAsString
}
elseif ($inputObject) {
$inputObjectAsString
}
}

end {

if (-not $NoClear) {
if ($canUseHTML) {
"&lt;/span&gt;"
}
elseif ($canUseANSI) {
if ($Bold -or $Faint -or $colorAttributes -match '\[1;') {
"$esc[22m"
}
if ($Italic) {
"$esc[23m"
}
if ($Underline -or $doubleUnderline) {
"$esc[24m"
}
if ($Blink) {
"$esc[25m"
}
if ($Invert) {
"$esc[27m"
}
if ($hide) {
"$esc[28m"
}
if ($Strikethru) {
"$esc[29m"
}
if ($ForegroundColor) {
"$esc[39m"
}
if ($BackgroundColor) {
"$esc[49m"
$allOutput +=
if ($canUseHTML) {
if ($Link) {
"&lt;/a&gt;"
}
"&lt;/span&gt;"
}

if (-not ($Underline -or $Bold -or $Invert -or $ForegroundColor -or $BackgroundColor)) {
'' + $esc + '[0m'
elseif ($canUseANSI) {
if ($Bold -or $Faint -or $colorAttributes -match '\[1;') {
"$esc[22m"
}
if ($Italic) {
"$esc[23m"
}
if ($Underline -or $doubleUnderline) {
"$esc[24m"
}
if ($Blink) {
"$esc[25m"
}
if ($Invert) {
"$esc[27m"
}
if ($hide) {
"$esc[28m"
}
if ($Strikethru) {
"$esc[29m"
}
if ($ForegroundColor) {
"$esc[39m"
}
if ($BackgroundColor) {
"$esc[49m"
}

if ($Link) {
"$esc]8;;$esc\"
}

if (-not ($Underline -or $Bold -or $Invert -or $ForegroundColor -or $BackgroundColor)) {
'' + $esc + '[0m'
}
}
}
}

$allOutput -join ''
}
</ScriptBlock>
</ExpressionBinding>
Expand Down
2 changes: 1 addition & 1 deletion LightScript.types.ps1xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-16"?>
<!-- Generated with EZOut 1.9.7: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
<!-- Generated with EZOut 2.0.3: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
<Types>
<Type>
<Name>Hue.Sensor</Name>
Expand Down
43 changes: 17 additions & 26 deletions docs/Add-HueLight.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,67 @@
Add-HueLight
------------

### Synopsis
Adds lights to Hue

---

### Description

Adds new lights to a Hue Bridge.

---

### Related Links
* [Get-HueLight](Get-HueLight.md)



* [Set-HueLight](Set-HueLight.md)



---

### Examples
#### EXAMPLE 1
> EXAMPLE 1
```PowerShell
Add-HueLight # Search for new lights
```
> EXAMPLE 2
#### EXAMPLE 2
```PowerShell
Add-HueLight -DeviceID $serialNumber # Add a new light by serial number.
```
> EXAMPLE 3
#### EXAMPLE 3
```PowerShell
Add-HueLight # Search for new lights
Add-HueLight # Search for new lights
Get-HueLight -New # Get-HueLight -New will return the new lights
```

---

### Parameters
#### **DeviceID**

One or more Device Identifiers (serial numbers ).
One or more Device Identifiers (serial numbers ).
Use this parameter when adding lights that have already been assigned to another bridge.

|Type |Required|Position|PipelineInput|Aliases |
|------------|--------|--------|-------------|------------|
|`[String[]]`|false |1 |false |SerialNumber|


> **Type**: ```[String[]]```
> **Required**: false
> **Position**: 1
> **PipelineInput**:false


---
#### **WhatIf**
-WhatIf is an automatic variable that is created when a command has ```[CmdletBinding(SupportsShouldProcess)]```.
-WhatIf is used to see what would happen, or return operations without executing them
#### **Confirm**
-Confirm is an automatic variable that is created when a command has ```[CmdletBinding(SupportsShouldProcess)]```.
-Confirm is used to -Confirm each operation.

If you pass ```-Confirm:$false``` you will not be prompted.



If the command sets a ```[ConfirmImpact("Medium")]``` which is lower than ```$confirmImpactPreference```, you will not be prompted unless -Confirm is passed.

---

### Syntax
```PowerShell
Add-HueLight [[-DeviceID] <String[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
```
---
Loading

0 comments on commit 28c4e3f

Please sign in to comment.