1 import Base 2 3 # What the dashboard draws: one value, built by read.bend from the files the 4 # daemon and the CLI keep, drawn by view.bend. Percentages are centi-percent 5 # (4750 = 47.5 %); times are unix seconds. 6 7 # One usage window: "5h", "7d" or a model name; None pct is unknown. 8 type Win is Data: 9 Win{label: String, pct: Maybe<&2, U32>, reset: Maybe<&2, U32>} 10 11 # One managed account. `age` is the seconds since its last good reading; 12 # `note` explains an unreadable one ("" when there is nothing to say). 13 type Acct is Data: 14 Acct{slot: String, email: String, alias: String, tag: String, active: Bool, disabled: Bool, wins: List<&2, Win>, age: Maybe<&2, U32>, note: String} 15 16 # The auto-switch line: is the daemon running, and its settings. 17 type Hdr is Data: 18 Hdr{version: String, live: Bool, pid: Maybe<&2, U32>, threshold: Maybe<&2, U32>, interval: Maybe<&2, U32>, next_poll: Maybe<&2, U32>} 19 20 # Everything for one frame. `off` is the local UTC offset biased by 86400 21 # (Clock.tz), `log` the last daemon.log lines, already formatted. 22 type Snap is Data: 23 Snap{now: U32, off: U32, hdr: Hdr, accts: List<&2, Acct>, log: List<&2, String>} 24 25 # How to draw it: terminal width in columns, colour on or off (NO_COLOR). 26 type View is Data: 27 View{width: U32, color: Bool} 28 29 def win_label(+w: Win) -> String: 30 match w: 31 case Win{l, p, r}: 32 l 33 34 def win_pct(+w: Win) -> Maybe<&2, U32>: 35 match w: 36 case Win{l, p, r}: 37 p 38 39 def win_reset(+w: Win) -> Maybe<&2, U32>: 40 match w: 41 case Win{l, p, r}: 42 r 43 44 def acct_wins(+a: Acct) -> List<&2, Win>: 45 match a: 46 case Acct{s, e, al, t, ac, d, w, g, n}: 47 w 48 49 def acct_slot(+a: Acct) -> String: 50 match a: 51 case Acct{s, e, al, t, ac, d, w, g, n}: 52 s 53 54 def acct_active(+a: Acct) -> Bool: 55 match a: 56 case Acct{s, e, al, t, ac, d, w, g, n}: 57 ac 58 59 def acct_disabled(+a: Acct) -> Bool: 60 match a: 61 case Acct{s, e, al, t, ac, d, w, g, n}: 62 d 63 64 def acct_email(+a: Acct) -> String: 65 match a: 66 case Acct{s, e, al, t, ac, d, w, g, n}: 67 e 68 69 def acct_age(+a: Acct) -> Maybe<&2, U32>: 70 match a: 71 case Acct{s, e, al, t, ac, d, w, g, n}: 72 g 73 74 def acct_note(+a: Acct) -> String: 75 match a: 76 case Acct{s, e, al, t, ac, d, w, g, n}: 77 n