New-ConsoleClock
Creates a run clock (ConsoleMonster.Live.SimulatedClock) the script moves forward, for simulated runs whose screen shows simulated time.
Syntax
New-ConsoleClock [[-Speed] <Double>] [<CommonParameters>]#All Parameter SetsDescription
Creates a run clock (ConsoleMonster.Live.SimulatedClock) the script moves forward, for simulated runs whose screen shows simulated time.
A live session reads the clock for the header clock, the summary bar's elapsed time and time left, the times of log lines and activities, and the run result's duration, so a demo or a replay of logged work shows its own time instead of the wall clock. Give it to a menu run as the third argument of $MenuContext.Run($dashboard, { ... }, $clock), or to Start-ConsoleDashboard -Clock. In the script, $clock.Wait(seconds) and $clock.WaitUntil(seconds) move it forward in small steps, sleeping 1/-Speed of each simulated second (never at speed 0, which runs at once); $clock.Advance(seconds) jumps without waiting and $clock.Hold(seconds) waits real time with the clock standing still. $clock.Elapsed is the time on the clock. Once the dashboard is stopped (Ctrl+C) waits stop sleeping, so the script reaches its end at once.
Examples
EXAMPLE 1
New-ConsoleMenuItem 'Run checks' -Action {
$clock = New-ConsoleClock -Speed 7
$dashboard = New-ConsoleDashboard -Title 'Checks' { New-ConsoleSummaryBar -Total 3; New-ConsoleLog -Height 5 }
$null = $MenuContext.Run($dashboard, {
foreach ($done in 1..3) {
$clock.Wait(4.5)
Update-ConsoleSummaryBar -Done $done -Counter @{ passed = $done }
Write-ConsoleLog "Check $done passed"
}
New-ConsoleRunResult 'Checks finished'
}, $clock)
}A menu run on a simulated clock seven times faster than real time
EXAMPLE 2
$clock = New-ConsoleClock -Speed 10
Start-ConsoleDashboard $dashboard -Clock $clock -ArgumentList $clock, $entries {
param($Clock, $Entries)
foreach ($entry in $Entries) { $Clock.WaitUntil($entry.Seconds); Write-ConsoleLog $entry.Text }
}A dashboard replaying logged work at its recorded pace, ten times faster
Parameters
- -Speed Double
- Simulated seconds per real second while the script waits (default 1, real time); 0 never sleeps.
Common Parameters
This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
For more information, see about_CommonParameters.