openbutler-protocol 0.0.1

The wire contract between the OpenButler daemon and its clients: frame encoding, action envelopes, and the shared state types.
Documentation
//! Finished screen lines: the host composes a screen, the client prints it.
//!
//! A screen is a decision — which rows exist, what they say, in what order
//! and how they read — so it is made once, in the host, and travels as data.
//! The tone is part of that decision; the glyph that renders a tone belongs
//! to the client's own palette.

use serde::{Deserialize, Serialize};

/// How a line reads. The host picks the tone; each client maps it to its own
/// marker (or to styling, on a surface without markers).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Tone {
    /// Body text: rows, values, blank separators.
    Plain,
    /// A note the reader may act on.
    Info,
    /// Something that completed.
    Success,
    /// Something that needs attention but did not fail.
    Warn,
    /// Something that failed.
    Failure,
}

/// One finished screen line: a tone and the text the host composed.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ScreenLine {
    pub tone: Tone,
    pub text: String,
}

impl ScreenLine {
    /// A plain body line.
    pub fn plain(text: impl Into<String>) -> Self {
        Self {
            tone: Tone::Plain,
            text: text.into(),
        }
    }

    /// A line with an explicit tone.
    pub fn with(tone: Tone, text: impl Into<String>) -> Self {
        Self {
            tone,
            text: text.into(),
        }
    }
}