Skip to content

Commit

Permalink
Displaying progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
galassie committed May 1, 2024
1 parent c217866 commit 7d7aae3
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions Program.fs
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
open FsSpectre
open System.Threading.Tasks
open FsSpectre
open Spectre.Console

let focusColor = Color.Lime.ToMarkup()
let breakColor = Color.Aqua.ToMarkup()

let focusTime =
AnsiConsole.Prompt
<| selectionPrompt {
title "[lime]Focus time[/]"
title $"[{focusColor}]Focus time[/]"
choices [| "25 minutes"; "30 minutes"; "45 minutes"; "1 hour" |]
}

AnsiConsole.MarkupLine($"You have [lime]{focusTime}[/] of focus time!")
AnsiConsole.MarkupLine($"You have [{focusColor}]{focusTime}[/] of focus time!")

let breakTime =
AnsiConsole.Prompt
<| selectionPrompt {
title "[aqua]Break time[/]"
title $"[{breakColor}]Break time[/]"
choices [| "5 minutes"; "10 minutes"; "15 minutes"; "20 minutes" |]
}

AnsiConsole.MarkupLine($"You have [aqua]{breakTime}[/] of break time!")
AnsiConsole.MarkupLine($"You have [{breakColor}]{breakTime}[/] of break time!")

let progress = AnsiConsole.Progress()

let result =
progress.StartAsync(fun (ctx) ->
task {
let task1 = ctx.AddTask($"[{focusColor}]Focus[/]")
let task2 = ctx.AddTask($"[{breakColor}]Break[/]")

while (not ctx.IsFinished) do
do! Task.Delay(250)
task1.Increment(1.5)
task2.Increment(0.5)

return 0
})

Task.WaitAll(result)

AnsiConsole.WriteLine("Finished!")

0 comments on commit 7d7aae3

Please sign in to comment.