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
75namespace Duets.Cli.Components.Commands
open Duets.Agents
open Duets.Cli.Components
open Duets.Cli.SceneIndex
open Duets.Cli.Text
open Duets.Common
open Duets.Entities
open Duets.Simulation
[<RequireQualifiedAccess>]
module ClockCommand =
let private endOfDay = "End of day" |> Styles.faded
/// Command which shows the current day moment and the number of day moments
/// until the end of the day.
let create
(dayMomentsWithEvents: (DayMoment * CalendarEventType list) list)
=
{ Name = "clock"
Description =
"Shows the current day moment and the number of day moments until the end of the day"
Handler =
(fun _ ->
let turnInfo =
Queries.Calendar.currentTurnInformation (State.get ())
dayMomentsWithEvents
|> List.indexed
|> List.fold
(fun acc (index, (dayMoment, events)) ->
let style =
match events with
| [] when index = 0 -> Styles.faded
| [] -> id
| _ -> Styles.highlight
let styledDayMoment =
$"{dayMoment |> Generic.dayMomentName |> style}"
let isLastItem =
index = List.length dayMomentsWithEvents - 1
match index with
| 0 when isLastItem ->
$"""{styledDayMoment} โ {endOfDay}"""
| _ when isLastItem ->
$"""{acc} โ {styledDayMoment} โ {endOfDay}"""
| 0 -> styledDayMoment
| _ -> $"{acc} โ {styledDayMoment}")
""
|> showMessage
let hasAnyEvent =
dayMomentsWithEvents
|> List.collect snd
|> List.isEmpty
|> not
if hasAnyEvent then
lineBreak ()
"* An event is scheduled at this time, check calendar for more details"
|> Styles.highlight
|> showMessage
let formatDayMoment =
Generic.dayMomentName >> String.lowercase >> Styles.time
$"Spent {turnInfo.TimeSpent} minutes on {turnInfo.CurrentDayMoment |> formatDayMoment}. {turnInfo.TimeLeft} minutes until {turnInfo.NextDayMoment |> formatDayMoment}"
|> Styles.faded
|> showMessage
Scene.World) }