Skip to main content

openbutler_protocol/
screen.rs

1//! Finished screen lines: the host composes a screen, the client prints it.
2//!
3//! A screen is a decision — which rows exist, what they say, in what order
4//! and how they read — so it is made once, in the host, and travels as data.
5//! The tone is part of that decision; the glyph that renders a tone belongs
6//! to the client's own palette.
7
8use serde::{Deserialize, Serialize};
9
10/// How a line reads. The host picks the tone; each client maps it to its own
11/// marker (or to styling, on a surface without markers).
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
13#[serde(rename_all = "lowercase")]
14pub enum Tone {
15    /// Body text: rows, values, blank separators.
16    Plain,
17    /// A note the reader may act on.
18    Info,
19    /// Something that completed.
20    Success,
21    /// Something that needs attention but did not fail.
22    Warn,
23    /// Something that failed.
24    Failure,
25}
26
27/// One finished screen line: a tone and the text the host composed.
28#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
29pub struct ScreenLine {
30    pub tone: Tone,
31    pub text: String,
32}
33
34impl ScreenLine {
35    /// A plain body line.
36    pub fn plain(text: impl Into<String>) -> Self {
37        Self {
38            tone: Tone::Plain,
39            text: text.into(),
40        }
41    }
42
43    /// A line with an explicit tone.
44    pub fn with(tone: Tone, text: impl Into<String>) -> Self {
45        Self {
46            tone,
47            text: text.into(),
48        }
49    }
50}