-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmini-timer-1.0.ps1
64 lines (38 loc) · 1.53 KB
/
mini-timer-1.0.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function Is-Numeric ($Value) {
return $Value -match "^[\d\.]+$"
}
function Beep-multi ([int]$freq, [int] $millis, [int] $num){
for ($i = 0; $i-lt $num; $i++){
[console]::Beep($freq, $millis)
}
}
function cursor-goto-fine ([int] $x_coordinate, [int] $y_coordinate){
[Console]::SetCursorPosition($x_coordinate, $y_coordinate);
}
$timestop = Read-Host("Input time in seconds")
if (Is-Numeric($timestop)) {
$timestop = [math]::Round($timestop, 3) # convert string input into integer value
}
$timestop_string = '{0:N3}' -f $timestop
cls;
$time = [Diagnostics.Stopwatch]::StartNew()
$loop = 1
while ($loop -eq 1){
Start-Sleep -Milliseconds 1
$time_now = $time.elapsed.totalseconds
if ($time_now -gt $timestop){
$loop = 0
}
$time_now_round = [math]::Round($time_now, 3)
$remain = $timestop - $time_now_round
$percentage_remain = [math]::Round(100 * $remain / $timestop, 2)
$percentage_remain_string = '{0:N2}' -f $percentage_remain
$time_now_round_string = '{0:N3}' -f $time_now_round
$remain_string = '{0:N3}' -f $remain
cursor-goto-fine(2)(2)
[console]::Write("$time_now_round_string of $timestop_string seconds `nTime remaining: $remain_string seconds ($percentage_remain_string%) `n")
}
cls;
[console]::Write("Time's up! Time elapsed: $timestop_string seconds.`n ctrl + C to close.")
Beep-multi (2000)(500)(30)
start-sleep 60