Cotton code
54 lines · 2.0 KB · RustRaw
//! Cotton Health's screens as data: the phone module//! `cotton_ffi::phone::health_app` reads one person's rows and these modules//! decide what each screen says, in the shapes [`shapes`] publishes//! (a `shapes.md` kept beside the work, in prose)./// The wire shapes of every `health.*` screen method.pub mod shapes;/// Labs, a parameter's history, Reports, a report, the people switcher.pub mod labs;/// Body: the owner's Apple Health by section, and anyone's report vitals.pub mod body;/// Settings.pub mod settings;#[cfg(test)]mod tests;use crate::keys::app::look::Look;use crate::rules::shell_lines::LineSet;/// The look, as shipped (`kits/health/look.json`).pub const LOOK: &str = include_str!("../../../kits/health/look.json");pub fn look() -> &'static Look {    static SHIPPED: std::sync::OnceLock<Look> = std::sync::OnceLock::new();    SHIPPED.get_or_init(|| Look::parse(LOOK).expect("kits/health/look.json reads"))}/// The health set, read once per process.pub fn lines() -> &'static LineSet {    static LINES: std::sync::OnceLock<LineSet> = std::sync::OnceLock::new();    LINES.get_or_init(|| LineSet::shipped("health").expect("the kit ships the health line set"))}/// One line; a missing one is a kit bug the line test catches, said as its key.pub fn say(line: &str) -> String {    lines().say(line, &[]).unwrap_or_else(|| line.to_string())}pub fn sayf(line: &str, fills: &[(&str, &str)]) -> String {    lines().say(line, fills).unwrap_or_else(|| line.to_string())}/// `2024-03-12` as `12 Mar 2024`.pub fn day_said(day: &str) -> String {    chrono::NaiveDate::parse_from_str(day, "%Y-%m-%d").map(|d| d.format("%-d %b %Y").to_string()).unwrap_or_else(|_| day.to_string())}/// A number as few digits say it: `212`, `5.8`, `0.05`, three decimals at most.pub fn number_said(value: f64) -> String {    let text = format!("{value:.3}");    let text = text.trim_end_matches('0').trim_end_matches('.');    if text == "-0" { "0".into() } else { text.to_string() }}