๐Ÿ“ฆ sleepyfran / duets

๐Ÿ“„ BarChart.fs ยท 31 lines
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[<AutoOpen>]
module Duets.Cli.Components.BarChart

open Spectre.Console

/// Returns the associated color given the level of a skill or the quality
/// of a song.
let private colorForLevel level =
    match level with
    | level when level < 30 -> Color.Red
    | level when level < 60 -> Color.Orange1
    | level when level < 80 -> Color.Green
    | _ -> Color.Blue

/// <summary>
/// Shows a bar chart with a max value of 100.
/// </summary>
/// <param name="items">List of tuples of value and text to display</param>
let showBarChart items =
    let mutable barChart = BarChart()
    barChart.MaxValue <- 100.0

    barChart <-
        barChart.AddItems(
            items,
            fun (progress, label) ->
                BarChartItem(label, float progress, colorForLevel progress)
        )

    AnsiConsole.Write(barChart)