obs-powershell.format.ps1xml
<?xml version="1.0" encoding="utf-16"?> <!-- Generated with EZOut 1.9.9: Install-Module EZOut or https://github.com/StartAutomating/EZOut --> <Configuration> <ViewDefinitions> <View> <Name>OBS.GetInputList.Response</Name> <ViewSelectedBy> <TypeName>OBS.GetInputList.Response</TypeName> </ViewSelectedBy> <TableControl> <TableHeaders> <TableColumnHeader> </TableColumnHeader> <TableColumnHeader> </TableColumnHeader> </TableHeaders> <TableRowEntries> <TableRowEntry> <TableColumnItems> <TableColumnItem> <PropertyName>InputName</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>InputKind</PropertyName> </TableColumnItem> </TableColumnItems> </TableRowEntry> </TableRowEntries> </TableControl> </View> <View> <Name>OBS.GetMonitorList.Response</Name> <ViewSelectedBy> <TypeName>OBS.GetMonitorList.Response</TypeName> </ViewSelectedBy> <TableControl> <TableHeaders> <TableColumnHeader> </TableColumnHeader> <TableColumnHeader> </TableColumnHeader> <TableColumnHeader> </TableColumnHeader> <TableColumnHeader> </TableColumnHeader> <TableColumnHeader> </TableColumnHeader> <TableColumnHeader> </TableColumnHeader> </TableHeaders> <TableRowEntries> <TableRowEntry> <TableColumnItems> <TableColumnItem> <PropertyName>monitorIndex</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>monitorName</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>monitorWidth</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>monitorHeight</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>monitorPositionX</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>monitorPositionY</PropertyName> </TableColumnItem> </TableColumnItems> </TableRowEntry> </TableRowEntries> </TableControl> </View> <View> <Name>OBS.GetSceneItemList.Response</Name> <ViewSelectedBy> <TypeName>OBS.GetSceneItemList.Response</TypeName> </ViewSelectedBy> <GroupBy> <PropertyName>SceneName</PropertyName> </GroupBy> <TableControl> <TableHeaders> <TableColumnHeader> </TableColumnHeader> <TableColumnHeader> </TableColumnHeader> <TableColumnHeader> </TableColumnHeader> <TableColumnHeader> </TableColumnHeader> <TableColumnHeader> </TableColumnHeader> </TableHeaders> <TableRowEntries> <TableRowEntry> <TableColumnItems> <TableColumnItem> <PropertyName>SceneItemID</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>sourceName</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>inputKind</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>Layer</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>Enabled</PropertyName> </TableColumnItem> </TableColumnItems> </TableRowEntry> </TableRowEntries> </TableControl> </View> <View> <Name>OBS.GetSceneList.Response</Name> <ViewSelectedBy> <TypeName>OBS.GetSceneList.Response</TypeName> </ViewSelectedBy> <TableControl> <TableHeaders> <TableColumnHeader> <Label>Scenes</Label> </TableColumnHeader> </TableHeaders> <TableRowEntries> <TableRowEntry> <Wrap /> <TableColumnItems> <TableColumnItem> <ScriptBlock>$moduleName = 'obs-powershell' do { $lm = Get-Module -Name $moduleName -ErrorAction Ignore if (-not $lm) { continue } if ($lm.FormatPartsLoaded) { break } $wholeScript = @(foreach ($formatFilePath in $lm.exportedFormatFiles) { foreach ($partNodeName in Select-Xml -LiteralPath $formatFilePath -XPath "/Configuration/Controls/Control/Name[starts-with(., '$')]") { $ParentNode = $partNodeName.Node.ParentNode "$($ParentNode.Name)={ $($ParentNode.CustomControl.CustomEntries.CustomEntry.CustomItem.ExpressionBinding.ScriptBlock)}" } }) -join [Environment]::NewLine New-Module -Name "${ModuleName}.format.ps1xml" -ScriptBlock ([ScriptBlock]::Create(($wholeScript + ';Export-ModuleMember -Variable *'))) | Import-Module -Global $onRemove = [ScriptBlock]::Create("Remove-Module '${ModuleName}.format.ps1xml'") if (-not $lm.OnRemove) { $lm.OnRemove = $onRemove } else { $lm.OnRemove = [ScriptBlock]::Create($onRemove.ToString() + '' + [Environment]::NewLine + $lm.OnRemove) } $lm | Add-Member NoteProperty FormatPartsLoaded $true -Force } while ($false) @(foreach ($sceneInfo in $_.scenes) { $currentOrPreview = @( if ($sceneInfo.sceneName -eq $_.currentProgramSceneName) { & ${obs-powershell_Format-RichText} -InputObject 'current' -ForegroundColor Warning } if ($sceneInfo.sceneName -eq $_.currentPreviewSceneName) { & ${obs-powershell_Format-RichText} -InputObject 'preview' -ForegroundColor Verbose } ) $sceneInfo.sceneName + ' ' + $( if ($currentOrPreview) { "$($currentOrPreview -join ' ')" } ) }) -join [Environment]::Newline </ScriptBlock> </TableColumnItem> </TableColumnItems> </TableRowEntry> </TableRowEntries> </TableControl> </View> <View> <Name>OBS.GetSceneList.Response</Name> <ViewSelectedBy> <TypeName>OBS.GetSceneList.Response</TypeName> </ViewSelectedBy> <CustomControl> <CustomEntries> <CustomEntry> <CustomItem> <ExpressionBinding> <ScriptBlock>$moduleName = 'obs-powershell' do { $lm = Get-Module -Name $moduleName -ErrorAction Ignore if (-not $lm) { continue } if ($lm.FormatPartsLoaded) { break } $wholeScript = @(foreach ($formatFilePath in $lm.exportedFormatFiles) { foreach ($partNodeName in Select-Xml -LiteralPath $formatFilePath -XPath "/Configuration/Controls/Control/Name[starts-with(., '$')]") { $ParentNode = $partNodeName.Node.ParentNode "$($ParentNode.Name)={ $($ParentNode.CustomControl.CustomEntries.CustomEntry.CustomItem.ExpressionBinding.ScriptBlock)}" } }) -join [Environment]::NewLine New-Module -Name "${ModuleName}.format.ps1xml" -ScriptBlock ([ScriptBlock]::Create(($wholeScript + ';Export-ModuleMember -Variable *'))) | Import-Module -Global $onRemove = [ScriptBlock]::Create("Remove-Module '${ModuleName}.format.ps1xml'") if (-not $lm.OnRemove) { $lm.OnRemove = $onRemove } else { $lm.OnRemove = [ScriptBlock]::Create($onRemove.ToString() + '' + [Environment]::NewLine + $lm.OnRemove) } $lm | Add-Member NoteProperty FormatPartsLoaded $true -Force } while ($false) @(foreach ($sceneInfo in $_.scenes) { $currentOrPreview = @( if ($sceneInfo.sceneName -eq $_.currentProgramSceneName) { & ${obs-powershell_Format-RichText} -InputObject 'current' -ForegroundColor Warning } if ($sceneInfo.sceneName -eq $_.currentPreviewSceneName) { & ${obs-powershell_Format-RichText} -InputObject 'preview' -ForegroundColor Verbose } ) $sceneInfo.SceneName + ' ' + $( if ($currentOrPreview) { "$($currentOrPreview -join ' ')" } ) }) -join [Environment]::Newline </ScriptBlock> </ExpressionBinding> </CustomItem> </CustomEntry> </CustomEntries> </CustomControl> </View> <View> <Name>OBS.GetSourceFilterList.ResponseOBS.GetSourceFilter.Response</Name> <ViewSelectedBy> <TypeName>OBS.GetSourceFilterList.Response</TypeName> <TypeName>OBS.GetSourceFilter.Response</TypeName> </ViewSelectedBy> <GroupBy> <PropertyName>SourceName</PropertyName> </GroupBy> <TableControl> <TableHeaders> <TableColumnHeader> <Alignment>Left</Alignment> </TableColumnHeader> <TableColumnHeader> <Alignment>Right</Alignment> </TableColumnHeader> <TableColumnHeader> <Alignment>Center</Alignment> </TableColumnHeader> <TableColumnHeader> <Alignment>Center</Alignment> </TableColumnHeader> <TableColumnHeader> <Label>Settings</Label> <Alignment>Left</Alignment> </TableColumnHeader> </TableHeaders> <TableRowEntries> <TableRowEntry> <Wrap /> <TableColumnItems> <TableColumnItem> <PropertyName>FilterName</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>Kind</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>Index</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>Enabled</PropertyName> </TableColumnItem> <TableColumnItem> <ScriptBlock>$moduleName = 'obs-powershell' do { $lm = Get-Module -Name $moduleName -ErrorAction Ignore if (-not $lm) { continue } if ($lm.FormatPartsLoaded) { break } $wholeScript = @(foreach ($formatFilePath in $lm.exportedFormatFiles) { foreach ($partNodeName in Select-Xml -LiteralPath $formatFilePath -XPath "/Configuration/Controls/Control/Name[starts-with(., '$')]") { $ParentNode = $partNodeName.Node.ParentNode "$($ParentNode.Name)={ $($ParentNode.CustomControl.CustomEntries.CustomEntry.CustomItem.ExpressionBinding.ScriptBlock)}" } }) -join [Environment]::NewLine New-Module -Name "${ModuleName}.format.ps1xml" -ScriptBlock ([ScriptBlock]::Create(($wholeScript + ';Export-ModuleMember -Variable *'))) | Import-Module -Global $onRemove = [ScriptBlock]::Create("Remove-Module '${ModuleName}.format.ps1xml'") if (-not $lm.OnRemove) { $lm.OnRemove = $onRemove } else { $lm.OnRemove = [ScriptBlock]::Create($onRemove.ToString() + '' + [Environment]::NewLine + $lm.OnRemove) } $lm | Add-Member NoteProperty FormatPartsLoaded $true -Force } while ($false) ($_.Settings | & ${obs-powershell_Format-YAML}).Trim() </ScriptBlock> </TableColumnItem> </TableColumnItems> </TableRowEntry> </TableRowEntries> </TableControl> </View> <View> <Name>OBS.GetVideoSettings.Response</Name> <ViewSelectedBy> <TypeName>OBS.GetVideoSettings.Response</TypeName> </ViewSelectedBy> <TableControl> <AutoSize /> <TableHeaders> <TableColumnHeader> </TableColumnHeader> <TableColumnHeader> </TableColumnHeader> <TableColumnHeader> </TableColumnHeader> <TableColumnHeader> </TableColumnHeader> <TableColumnHeader> </TableColumnHeader> <TableColumnHeader> </TableColumnHeader> </TableHeaders> <TableRowEntries> <TableRowEntry> <TableColumnItems> <TableColumnItem> <PropertyName>BaseWidth</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>BaseHeight</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>OutputWidth</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>OutputHeight</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>FPSDenominator</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>FPSNumerator</PropertyName> </TableColumnItem> </TableColumnItems> </TableRowEntry> </TableRowEntries> </TableControl> </View> <View> <Name>OBS.PowerShell.Effect</Name> <ViewSelectedBy> <TypeName>OBS.PowerShell.Effect</TypeName> </ViewSelectedBy> <TableControl> <TableHeaders> <TableColumnHeader> </TableColumnHeader> <TableColumnHeader> </TableColumnHeader> </TableHeaders> <TableRowEntries> <TableRowEntry> <TableColumnItems> <TableColumnItem> <PropertyName>EffectName</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>EffectType</PropertyName> </TableColumnItem> </TableColumnItems> </TableRowEntry> </TableRowEntries> </TableControl> </View> <View> <Name>Default</Name> <ViewSelectedBy> <TypeName>OBS.PowerShell</TypeName> </ViewSelectedBy> <CustomControl> <CustomEntries> <CustomEntry> <CustomItem> <ExpressionBinding> <ScriptBlock>$moduleName = 'obs-powershell' do { $lm = Get-Module -Name $moduleName -ErrorAction Ignore if (-not $lm) { continue } if ($lm.FormatPartsLoaded) { break } $wholeScript = @(foreach ($formatFilePath in $lm.exportedFormatFiles) { foreach ($partNodeName in Select-Xml -LiteralPath $formatFilePath -XPath "/Configuration/Controls/Control/Name[starts-with(., '$')]") { $ParentNode = $partNodeName.Node.ParentNode "$($ParentNode.Name)={ $($ParentNode.CustomControl.CustomEntries.CustomEntry.CustomItem.ExpressionBinding.ScriptBlock)}" } }) -join [Environment]::NewLine New-Module -Name "${ModuleName}.format.ps1xml" -ScriptBlock ([ScriptBlock]::Create(($wholeScript + ';Export-ModuleMember -Variable *'))) | Import-Module -Global $onRemove = [ScriptBlock]::Create("Remove-Module '${ModuleName}.format.ps1xml'") if (-not $lm.OnRemove) { $lm.OnRemove = $onRemove } else { $lm.OnRemove = [ScriptBlock]::Create($onRemove.ToString() + '' + [Environment]::NewLine + $lm.OnRemove) } $lm | Add-Member NoteProperty FormatPartsLoaded $true -Force } while ($false) @(& ${obs-powershell_Format-RichText} -ForegroundColor 'Success' -NoClear) -join ''</ScriptBlock> </ExpressionBinding> <ExpressionBinding> <ScriptBlock> "obs-powershell@$($_.OBSPowerShellVersion)" </ScriptBlock> </ExpressionBinding> <ExpressionBinding> <ScriptBlock>@(& ${obs-powershell_Format-RichText} -ForegroundColor 'Success' ) -join ''</ScriptBlock> </ExpressionBinding> <ExpressionBinding> <ScriptBlock>@(& ${obs-powershell_Format-RichText} -ForegroundColor 'Verbose' -NoClear) -join ''</ScriptBlock> </ExpressionBinding> <ExpressionBinding> <ScriptBlock> " Script your streaming." </ScriptBlock> </ExpressionBinding> <ExpressionBinding> <ScriptBlock>@(& ${obs-powershell_Format-RichText} -ForegroundColor 'Verbose' ) -join ''</ScriptBlock> </ExpressionBinding> <NewLine /> <ExpressionBinding> <ScriptBlock> @( "" " Everything in PowerShell is an object, and every object can be extended." "" " See what this object can do:" "" " Get-OBS | Get-Member" "" ) -join [Environment]::NewLine </ScriptBlock> </ExpressionBinding> <ExpressionBinding> <ScriptBlock>@(& ${obs-powershell_Format-RichText} -ForegroundColor 'Verbose' -NoClear) -join ''</ScriptBlock> </ExpressionBinding> <ExpressionBinding> <ScriptBlock> @( "" "This object can be viewed in different ways:" "" foreach ($view in (Get-FormatData -TypeName OBS.PowerShell).FormatViewDefinition) { " Get-OBS | Format-$($view.Control.GetType().Name -replace 'Control$') -View $($view.Name)" } ) -join [Environment]::NewLine </ScriptBlock> </ExpressionBinding> <ExpressionBinding> <ScriptBlock>@(& ${obs-powershell_Format-RichText} -ForegroundColor 'Verbose' ) -join ''</ScriptBlock> </ExpressionBinding> </CustomItem> </CustomEntry> </CustomEntries> </CustomControl> </View> <View> <Name>Version</Name> <ViewSelectedBy> <TypeName>OBS.PowerShell</TypeName> </ViewSelectedBy> <TableControl> <AutoSize /> <TableHeaders> <TableColumnHeader> <Alignment>Center</Alignment> </TableColumnHeader> <TableColumnHeader> <Alignment>Center</Alignment> </TableColumnHeader> <TableColumnHeader> <Alignment>Center</Alignment> </TableColumnHeader> </TableHeaders> <TableRowEntries> <TableRowEntry> <TableColumnItems> <TableColumnItem> <PropertyName>OBSVersion</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>OBSWebSocketVersion</PropertyName> </TableColumnItem> <TableColumnItem> <PropertyName>OBSPowerShellVersion</PropertyName> </TableColumnItem> </TableColumnItems> </TableRowEntry> </TableRowEntries> </TableControl> </View> <View> <Name>Version</Name> <ViewSelectedBy> <TypeName>OBS.PowerShell</TypeName> </ViewSelectedBy> <ListControl> <ListEntries> <ListEntry> <ListItems> <ListItem> <PropertyName>OBSVersion</PropertyName> </ListItem> <ListItem> <PropertyName>OBSWebSocketVersion</PropertyName> </ListItem> <ListItem> <PropertyName>OBSPowerShellVersion</PropertyName> </ListItem> </ListItems> </ListEntry> </ListEntries> </ListControl> </View> <View> <Name>Inputs</Name> <ViewSelectedBy> <TypeName>OBS.PowerShell</TypeName> </ViewSelectedBy> <TableControl> <TableHeaders> <TableColumnHeader> <Label>Inputs</Label> </TableColumnHeader> </TableHeaders> <TableRowEntries> <TableRowEntry> <Wrap /> <TableColumnItems> <TableColumnItem> <ScriptBlock>$_.Inputs.InputName -join [Environment]::NewLine</ScriptBlock> </TableColumnItem> </TableColumnItems> </TableRowEntry> </TableRowEntries> </TableControl> </View> <View> <Name>Scenes</Name> <ViewSelectedBy> <TypeName>OBS.PowerShell</TypeName> </ViewSelectedBy> <TableControl> <TableHeaders> <TableColumnHeader> <Label>Scenes</Label> </TableColumnHeader> </TableHeaders> <TableRowEntries> <TableRowEntry> <Wrap /> <TableColumnItems> <TableColumnItem> <ScriptBlock>$_.Scenes.SceneName -join [Environment]::NewLine</ScriptBlock> </TableColumnItem> </TableColumnItems> </TableRowEntry> </TableRowEntries> </TableControl> </View> <View> <Name>Status</Name> <ViewSelectedBy> <TypeName>OBS.PowerShell</TypeName> </ViewSelectedBy> <CustomControl> <CustomEntries> <CustomEntry> <CustomItem> <ExpressionBinding> <ScriptBlock>$moduleName = 'obs-powershell' do { $lm = Get-Module -Name $moduleName -ErrorAction Ignore if (-not $lm) { continue } if ($lm.FormatPartsLoaded) { break } $wholeScript = @(foreach ($formatFilePath in $lm.exportedFormatFiles) { foreach ($partNodeName in Select-Xml -LiteralPath $formatFilePath -XPath "/Configuration/Controls/Control/Name[starts-with(., '$')]") { $ParentNode = $partNodeName.Node.ParentNode "$($ParentNode.Name)={ $($ParentNode.CustomControl.CustomEntries.CustomEntry.CustomItem.ExpressionBinding.ScriptBlock)}" } }) -join [Environment]::NewLine New-Module -Name "${ModuleName}.format.ps1xml" -ScriptBlock ([ScriptBlock]::Create(($wholeScript + ';Export-ModuleMember -Variable *'))) | Import-Module -Global $onRemove = [ScriptBlock]::Create("Remove-Module '${ModuleName}.format.ps1xml'") if (-not $lm.OnRemove) { $lm.OnRemove = $onRemove } else { $lm.OnRemove = [ScriptBlock]::Create($onRemove.ToString() + '' + [Environment]::NewLine + $lm.OnRemove) } $lm | Add-Member NoteProperty FormatPartsLoaded $true -Force } while ($false) $recordStatus = $_.RecordStatus $streamStatus = $_.StreamStatus $virtualCameraStatus = $_.VirtualCameraStatus @( @(if ($recordStatus.OutputActive) { if ($recordStatus.Paused) { & ${obs-powershell_Format-RichText} -ForegroundColor Warning -InputObject "Recording Paused" } else { & ${obs-powershell_Format-RichText} -ForegroundColor Error -InputObject "Recording" } } else { & ${obs-powershell_Format-RichText} -ForegroundColor Success -InputObject "Not Recording" } if ($recordStatus.OutputDuration) { & ${obs-powershell_Format-RichText} -ForegroundColor Cyan -InputObject $recordStatus.OutputTimecode }) -join ' ' @(if ($streamStatus.OutputActive) { if ($streamStatus.Paused) { & ${obs-powershell_Format-RichText} -ForegroundColor Warning -InputObject "Streaming Paused" } else { & ${obs-powershell_Format-RichText} -ForegroundColor Error -InputObject "Streaming" } } else { & ${obs-powershell_Format-RichText} -ForegroundColor Success -InputObject "Not Streaming" } if ($streamStatus.OutputDuration) { & ${obs-powershell_Format-RichText} -ForegroundColor Cyan -InputObject $streamStatus.OutputTimecode }) -join ' ' ) -join [Environment]::Newline </ScriptBlock> </ExpressionBinding> </CustomItem> </CustomEntry> </CustomEntries> </CustomControl> </View> </ViewDefinitions> <Controls> <Control> <Name>${obs-powershell_Format-RichText}</Name> <CustomControl> <CustomEntries> <CustomEntry> <CustomItem> <ExpressionBinding> <ScriptBlock> <# .Synopsis Formats the text color of output .Description Formats the text color of output * ForegroundColor * BackgroundColor * Bold * Underline .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)) #> [Management.Automation.Cmdlet("Format","Object")] [ValidateScript({ $canUseANSI = $host.UI.SupportsVirtualTerminal $canUseHTML = $Request -or $host.UI.SupportsHTML -or $OutputMode -eq 'HTML' if (-not ($canUseANSI -or $canUseHTML)) { return $false} return $true })] [OutputType([string])] param( # The input object [Parameter(ValueFromPipeline)] [PSObject] $InputObject, # The foreground color [string]$ForegroundColor, # The background color [string]$BackgroundColor, # If set, will render as bold [switch]$Bold, # If set, will render as italic. [Alias('Italics')] [switch]$Italic, # If set, will render as faint [switch]$Faint, # If set, will render as hidden text. [switch]$Hide, # If set, will render as blinking (not supported in all terminals or HTML) [switch]$Blink, # If set, will render as strikethru [Alias('Strikethrough', 'Crossout')] [switch]$Strikethru, # If set, will underline text [switch]$Underline, # If set, will double underline text. [switch]$DoubleUnderline, # 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, # 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 { $canUseANSI = $host.UI.SupportsVirtualTerminal $canUseHTML = $Request -or $host.UI.SupportsHTML -or $OutputMode -eq 'HTML' $knownStreams = @{ Output='';Error='BrightRed';Warning='BrightYellow'; Verbose='BrightCyan';Debug='Yellow';Progress='Cyan'; Success='BrightGreen';Failure='Red';Default=''} $ansiCode = [Regex]::new(@' (?<ANSI_Code> (?-i)\e # An Escape \[ # Followed by a bracket (?<ParameterBytes>[\d\:\;\<\=\>\?]{0,}) # Followed by zero or more parameter bytes (?<IntermediateBytes>[\s\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/]{0,}) # Followed by zero or more intermediate bytes (?<FinalByte>[\@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 = @() $colorAttributes = @(:nextColor foreach ($hc in $ForegroundColor,$BackgroundColor) { $n++ if (-not $hc) { continue } if ($hc[0] -eq $esc) { if ($canUseANSI) { $hc; continue } } $ansiStartPoint = if ($n -eq 1) { 30 } else { 40 } if ($knownStreams.ContainsKey($hc)) { $i = $brightColors.IndexOf($knownStreams[$hc]) if ($canUseHTML) { $cssClasses += $hc } else { if ($i -ge 0 -and $canUseANSI) { '' + $esc + "[1;$($ansiStartPoint + $i)m" } else { $i = $standardColors.IndexOf($knownStreams[$hc]) if ($i -ge 0 -and $canUseANSI) { '' + $esc + "[1;$($ansiStartPoint + $i)m" } elseif ($i -le 0 -and $canUseANSI) { '' + $esc + "[$($ansistartpoint + 8):5m" } } } continue nextColor } elseif ($standardColors -contains $hc) { for ($i = 0; $i -lt $standardColors.Count;$i++) { if ($standardColors[$i] -eq $hc) { if ($canUseANSI -and -not $canUseHTML) { '' + $esc + "[$($ansiStartPoint + $i)m" } else { $cssClasses += $standardColors[$i] } continue nextColor } } } elseif ($brightColors -contains $hc) { for ($i = 0; $i -lt $brightColors.Count;$i++) { if ($brightColors[$i] -eq $hc) { if ($canUseANSI -and -not $canUseHTML) { '' + $esc + "[1;$($ansiStartPoint + $i)m" } else { $cssClasses += $standardColors[$i] } continue nextColor } } } elseif ($psStyle -and $psStyle.Formatting.$hc -and $psStyle.Formatting.$hc -match '^\e') { if ($canUseANSI -and -not $canUseHTML) { $psStyle.Formatting.$hc } else { $cssClasses += "formatting-$hc" } } elseif (-not $n -and $psStyle -and $psStyle.Foreground.$hc -and $psStyle.Foreground.$hc -match '^\e' ) { if ($canUseANSI -and -not $canUseHTML) { $psStyle.Foreground.$hc } else { $cssClasses += "foreground-$hc" } } elseif ($n -and $psStyle -and $psStyle.Background.$hc -and $psStyle.Background.$hc -match '^\e') { if ($canUseANSI -and -not $canUseHTML) { $psStyle.Background.$hc } else { $cssClasses += "background-$hc" } } if ($hc -and $hc -notmatch '^[\#\e]') { $placesToLook= @(if ($hc.Contains('.')) { $module, $setting = $hc -split '\.', 2 $theModule = Get-Module $module $theModule.PrivateData.Color, $theModule.PrivateData.Colors, $theModule.PrivateData.Colour, $theModule.PrivateData.Colours, $theModule.PrivateData.EZOut, $global:PSColors, $global:PSColours } else { $setting = $hc $moduleColorSetting = $theModule.PrivateData.PSColors.$setting }) foreach ($place in $placesToLook) { if (-not $place) { continue } foreach ($propName in $setting -split '\.') { $place = $place.$propName if (-not $place) { break } } if ($place -and "$place".StartsWith('#') -and 4,7 -contains "$place".Length) { $hc = $place continue } } if (-not $hc.StartsWith -or -not $hc.StartsWith('#')) { continue } } $r,$g,$b = if ($hc.Length -eq 7) { [int]::Parse($hc[1..2]-join'', 'HexNumber') [int]::Parse($hc[3..4]-join '', 'HexNumber') [int]::Parse($hc[5..6] -join'', 'HexNumber') }elseif ($hc.Length -eq 4) { [int]::Parse($hc[1], 'HexNumber') * 16 [int]::Parse($hc[2], 'HexNumber') * 16 [int]::Parse($hc[3], 'HexNumber') * 16 } if ($canUseHTML) { if ($n -eq 1) { "color:$hc" } elseif ($n -eq 2) { "background-color:$hc"} } elseif ($canUseANSI) { if ($n -eq 1) { $esc+"[38;2;$r;$g;${b}m" } elseif ($n -eq 2) { $esc+"[48;2;$r;$g;${b}m" } } }) $styleAttributes = @() + $colorAttributes $styleAttributes += @( if ($Bold) { if ($canUseHTML) {"font-weight:bold"} elseif ($canUseANSI) { '' + $esc + "[1m" } } if ($Faint) { if ($canUseHTML) { "opacity:.5" } elseif ($canUseANSI) { '' + $esc + "[2m" } } if ($Italic) { if ($canUseHTML) { "font-weight:bold" } elseif ($canUseANSI) {'' + $esc + "[3m" } } if ($Underline -and -not $doubleUnderline) { if ($canUseHTML) { "text-decoration:underline"} elseif ($canUseANSI) {'' +$esc + "[4m" } } if ($Blink) { if ($canUseANSI) { '' +$esc + "[5m" } } if ($invert) { if ($canUseHTML) {"filter:invert(100%)"} elseif ($canUseANSI) { '' + $esc + "[7m"} } if ($hide) { if ($canUseHTML) {"opacity:0"} elseif ($canUseANSI) { '' + $esc + "[8m"} } if ($Strikethru) { if ($canUseHTML) {"text-decoration: line-through"} elseif ($canUseANSI) { '' +$esc + "[9m" } } if ($DoubleUnderline) { 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 + ']8m;;' + $Link + $esc + '\' } } ) $header = if ($canUseHTML) { "<span$( if ($styleAttributes) { " style='$($styleAttributes -join ';')'"} )$( if ($cssClasses) { " class='$($cssClasses -join ' ')'"} )>" + $( if ($Link) { "<a href='$link'>" } ) } elseif ($canUseANSI) { $styleAttributes -join '' } } process { $inputObjectAsString = "$(if ($inputObject) { $inputObject | Out-String})".Trim() $inputObjectAsString = if ($Alignment -and -not $canUseHTML) { (@(foreach ($inputObjectLine in ($inputObjectAsString -split '(?>\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) { $allOutput += if ($canUseHTML) { if ($Link) { "</a>" } "</span>" } 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> </CustomItem> </CustomEntry> </CustomEntries> </CustomControl> </Control> <Control> <Name>${obs-powershell_Format-YAML}</Name> <CustomControl> <CustomEntries> <CustomEntry> <CustomItem> <ExpressionBinding> <ScriptBlock> <# .SYNOPSIS Formats objects as YAML .DESCRIPTION Formats an object as YAML. .EXAMPLE Format-Yaml -InputObject @("a", "b", "c") .EXAMPLE @{a="b";c="d";e=@{f=@('g')}} | Format-Yaml #> [Management.Automation.Cmdlet("Format","Object")] [ValidateScript({return $true})] param( # The InputObject. [Parameter(ValueFromPipeline)] [PSObject] $InputObject, # If set, will make a YAML header by adding a YAML Document tag above and below output. [Alias('YAMLDocument')] [switch] $YamlHeader, [int] $Indent = 0, # The maximum depth of objects to include. # Beyond this depth, an empty string will be returned. [int] $Depth ) begin { $toYaml = { param( [Parameter(ValueFromPipeline,Position=0)]$Object, [Object]$Parent, [Object]$GrandParent, [int]$Indent = 0) begin { $n = 0; $mySelf = $myInvocation.MyCommand.ScriptBlock } process { $n++ if ($Object -eq $null) { return } if ($depth) { $myDepth = $indent / 2 if ($myDepth -gt $depth) { return '' } } if ($Parent -and $Parent -is [Collections.IList]) { if ($Parent.IndexOf($Object) -gt 0) { ' ' * $Indent } '- ' } #region Primitives if ( $Object -is [string] ) { # If it's a string if ($object -match '\n') { # see if it's a multline string. "|" # If it is, emit the multiline indicator $indent +=2 foreach ($l in $object -split '(?>\r\n|\n)') { # and emit each line indented [Environment]::NewLine ' ' * $indent $l } $indent -=2 } elseif ("$object".Contains('*')) { "'$($Object -replace "'","''")'" } else { $object } if ($Parent -is [Collections.IList]) { # If the parent object was a list [Environment]::NewLine # emit a newline. } return # Once the string has been emitted, return. } if ( $Object.GetType().IsPrimitive ) { # If it is a primitive type "$Object".ToLower() # Emit it in lowercase. if ($Parent -is [Collections.IList]) { [Environment]::NewLine } return } #endregion Primitives #region KVP if ( $Object -is [Collections.DictionaryEntry] -or $object -is [Management.Automation.PSPropertyInfo]) { if ($Parent -isnot [Collections.IList] -and ($GrandParent -isnot [Collections.IList] -or $n -gt 1)) { [Environment]::NewLine + (" " * $Indent) } if ($object.Key -and $Object.Key -is [string]) { $Object.Key +": " } elseif ($object.Name -and $object.Name -is [string]) { $Object.Name +": " } } if ( $Object -is [Collections.DictionaryEntry] -or $Object -is [Management.Automation.PSPropertyInfo]) { & $mySelf -Object $Object.Value -Parent $Object -GrandParent $parent -Indent $Indent return } #endregion KVP #region Nested if ($parent -and ($Object -is [Collections.IDictionary] -or $Object -is [PSObject])) { $Indent += 2 } elseif ($object -is [Collections.IList]) { $allPrimitive = 1 foreach ($Obj in $Object) { $allPrimitive = $allPrimitive -band ( $Obj -is [string] -or $obj.GetType().IsPrimitive ) } if ($parent -and -not $allPrimitive) { $Indent += 2 } } if ( $Object -is [Collections.IDictionary] ) { $Object.GetEnumerator() | & $mySelf -Parent $Object -GrandParent $Parent -Indent $Indent } elseif ($Object -is [Collections.IList]) { [Environment]::NewLine + (' ' * $Indent) $Object | & $mySelf -Parent $Object -GrandParent $Parent -Indent $Indent } elseif ($object -is [enum]) { $object.ToString() } elseif ($Object.PSObject.Properties) { $Object.psobject.properties | & $mySelf -Parent $Object -GrandParent $Parent -Indent $Indent } if ($Object -is [Collections.IDictionary] -or $Object -is [PSCustomObject] -or $Object -is [Collections.IList]) { if ($Parent -is [Collections.IList]) { [Environment]::NewLine } $Indent -= 2; } #endregion Nested } } function IndentString([string]$String,[int]$Indent) { @(foreach ($line in @($String -split '(?>\r\n|\n)')) { (' ' * $indent) + $line }) -join [Environment]::NewLine } $inputWasNotPiped = $PSBoundParameters.InputObject -as [bool] $allInputObjects = @() } process { if ($inputWasNotPiped) { IndentString ('' + $(if ($YamlHeader) { '---' + [Environment]::NewLine }) + ( (& $toYaml -object $inputObject) -join '' -replace "$([Environment]::NewLine * 2)", [Environment]::NewLine ) + $(if ($YamlHeader) { [Environment]::NewLine + '---'})) -Indent $Indent } else { $allInputObjects += $inputObject } } end { if (-not $allInputObjects) { return } if ($allInputObjects.Length -eq 1) { IndentString ('' + $(if ($YamlHeader) { '---' + [Environment]::NewLine}) + ( (& $toYaml -object $inputObject) -join '' -replace "$([Environment]::NewLine * 2)", [Environment]::NewLine ) + $(if ($YamlHeader) { [Environment]::NewLine + '---'})) -Indent $Indent } else { IndentString ('' + $(if ($YamlHeader) { '---' + [Environment]::NewLine}) + ( (& $toYaml -object $allInputObjects) -join '' -replace "$([Environment]::NewLine * 2)", [Environment]::NewLine ) + $(if ($YamlHeader) { [Environment]::NewLine + '---'})) -Indent $Indent } } </ScriptBlock> </ExpressionBinding> </CustomItem> </CustomEntry> </CustomEntries> </CustomControl> </Control> </Controls> </Configuration> |