diff --git a/PwshSpectreConsole/private/Start-AnsiConsoleProgress.ps1 b/PwshSpectreConsole/private/Start-AnsiConsoleProgress.ps1 index 08391868..e6477a38 100644 --- a/PwshSpectreConsole/private/Start-AnsiConsoleProgress.ps1 +++ b/PwshSpectreConsole/private/Start-AnsiConsoleProgress.ps1 @@ -20,10 +20,13 @@ function Start-AnsiConsoleProgress { [Parameter(Mandatory)] [scriptblock] $ScriptBlock ) + $resultVariableName = "AnsiConsoleProgressResult-$([guid]::NewGuid())" + New-Variable -Name $resultVariableName -Scope "Script" [Spectre.Console.AnsiConsole]::Progress().Start({ param ( $ctx ) - & $ScriptBlock $ctx + Set-Variable -Name $resultVariableName -Value (& $ScriptBlock $ctx) -Scope "Script" }) + return Get-Variable -Name $resultVariableName -ValueOnly } \ No newline at end of file diff --git a/PwshSpectreConsole/private/Start-AnsiConsoleStatus.ps1 b/PwshSpectreConsole/private/Start-AnsiConsoleStatus.ps1 index 33526aea..32ed6e0e 100644 --- a/PwshSpectreConsole/private/Start-AnsiConsoleStatus.ps1 +++ b/PwshSpectreConsole/private/Start-AnsiConsoleStatus.ps1 @@ -9,12 +9,15 @@ function Start-AnsiConsoleStatus { [Parameter(Mandatory)] [scriptblock] $ScriptBlock ) + $resultVariableName = "AnsiConsoleStatusResult-$([guid]::NewGuid())" + New-Variable -Name $resultVariableName -Scope "Script" [Spectre.Console.AnsiConsole]::Status().Start($Title, { param ( $ctx ) $ctx.Spinner = $Spinner $ctx.SpinnerStyle = $SpinnerStyle - & $ScriptBlock $ctx + Set-Variable -Name $resultVariableName -Value (& $ScriptBlock $ctx) -Scope "Script" }) + return Get-Variable -Name $resultVariableName -ValueOnly }