-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.fs
157 lines (125 loc) · 4.76 KB
/
Program.fs
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
open System
open System.Threading.Tasks
open FsSpectre
open Spectre.Console
let focusColor = Color.Lime.ToMarkup()
let breakColor = Color.Aqua.ToMarkup()
[<RequireQualifiedAccess>]
type FocusTime =
| ``25Mins``
| ``30Mins``
| ``45Mins``
| ``1Hour``
override this.ToString() : string =
match this with
| FocusTime.``25Mins`` -> "25 minutes"
| FocusTime.``30Mins`` -> "30 minutes"
| FocusTime.``45Mins`` -> "45 minutes"
| FocusTime.``1Hour`` -> "1 hour"
member this.ToSeconds() : float =
match this with
| FocusTime.``25Mins`` -> 1500
| FocusTime.``30Mins`` -> 1800
| FocusTime.``45Mins`` -> 2700
| FocusTime.``1Hour`` -> 3600
[<RequireQualifiedAccess>]
type BreakTime =
| ``5Mins``
| ``10Mins``
| ``15Mins``
| ``20Mins``
override this.ToString() : string =
match this with
| BreakTime.``5Mins`` -> "5 minutes"
| BreakTime.``10Mins`` -> "10 minutes"
| BreakTime.``15Mins`` -> "15 minutes"
| BreakTime.``20Mins`` -> "20 minutes"
member this.ToSeconds() : float =
match this with
| BreakTime.``5Mins`` -> 300
| BreakTime.``10Mins`` -> 600
| BreakTime.``15Mins`` -> 900
| BreakTime.``20Mins`` -> 1200
let focusTime =
AnsiConsole.Prompt
<| selectionPrompt {
title $"[{focusColor}]Focus time[/]"
choices
[| FocusTime.``25Mins``
FocusTime.``30Mins``
FocusTime.``45Mins``
FocusTime.``1Hour`` |]
}
AnsiConsole.MarkupLine($"You have [{focusColor}]{focusTime}[/] of focus time!")
let breakTime =
AnsiConsole.Prompt
<| selectionPrompt {
title $"[{breakColor}]Break time[/]"
choices
[| BreakTime.``5Mins``
BreakTime.``10Mins``
BreakTime.``15Mins``
BreakTime.``20Mins`` |]
}
AnsiConsole.MarkupLine($"You have [{breakColor}]{breakTime}[/] of break time!\n")
let mutable pause: bool = false
let mutable skip: bool = false
let mutable quit: bool = false
let mutable cmd: option<ConsoleKey> = None
let write =
Task.Run(fun () ->
while not quit do
match Console.ReadKey(true).Key with
| ConsoleKey.P -> pause <- true
| ConsoleKey.R -> pause <- false
| ConsoleKey.S -> skip <- true
| ConsoleKey.Q -> quit <- true
| _ -> ())
let focusBreakCycle =
Task.Run(
Func<Task>(fun () ->
task {
while not quit do
skip <- false
pause <- false
do!
progressAsync {
auto_clear true
start (fun (ctx) ->
task {
let description = $"[{focusColor}]Focus[/]"
let task = ctx.AddTask(description, true, focusTime.ToSeconds())
while (not ctx.IsFinished && not quit && not skip) do
do! Task.Delay(1000)
let incrementTime = if pause then 0.0 else 1.0
task.Increment(incrementTime)
task.Description <- if pause then "Pause" else description
return ()
})
}
skip <- false
pause <- false
do!
progressAsync {
auto_clear true
start (fun (ctx) ->
task {
let description = $"[{breakColor}]Break[/]"
let task = ctx.AddTask(description, true, breakTime.ToSeconds())
while (not ctx.IsFinished && not quit && not skip) do
do! Task.Delay(1000)
let incrementTime = if pause then 0.0 else 1.0
task.Increment(incrementTime)
task.Description <- if pause then "Pause" else description
return ()
})
}
})
)
AnsiConsole.WriteLine("Running...\n")
AnsiConsole.MarkupLine("[grey]Press 'p' to pause[/]")
AnsiConsole.MarkupLine("[grey]Press 'r' to resume[/]")
AnsiConsole.MarkupLine("[grey]Press 's' to skip[/]")
AnsiConsole.MarkupLine("[grey]Press 'q' to quit[/]")
focusBreakCycle.Wait()
AnsiConsole.WriteLine("\nFinished!\n")