Skip to main content

boxmux_lib/model/
choice.rs

1use std::hash::{Hash, Hasher};
2
3use serde::{Deserialize, Serialize};
4
5use crate::model::common::deserialize_script;
6use crate::ExecutionMode;
7
8#[derive(Debug, Deserialize, Serialize, Default)]
9pub struct Choice {
10    pub id: String,
11    pub content: Option<String>,
12    #[serde(deserialize_with = "deserialize_script", default)]
13    pub script: Option<Vec<String>>,
14    pub redirect_output: Option<String>,
15    pub append_output: Option<bool>,
16    // F0222: Choice ExecutionMode Field - Replace thread+pty boolean flags with single execution_mode enum
17    #[serde(default)]
18    pub execution_mode: ExecutionMode,
19    #[serde(skip, default)]
20    pub selected: bool,
21    #[serde(skip, default)]
22    pub waiting: bool,
23    #[serde(skip, default)]
24    pub hovered: bool,
25}
26
27impl Choice {}
28
29impl Hash for Choice {
30    fn hash<H: Hasher>(&self, state: &mut H) {
31        self.id.hash(state);
32        self.content.hash(state);
33        self.script.hash(state);
34        self.redirect_output.hash(state);
35        self.append_output.hash(state);
36        // F0222: Hash ExecutionMode field
37        self.execution_mode.hash(state);
38        self.selected.hash(state);
39        self.waiting.hash(state);
40        self.hovered.hash(state);
41    }
42}
43
44impl PartialEq for Choice {
45    fn eq(&self, other: &Self) -> bool {
46        self.id == other.id
47            && self.content == other.content
48            && self.script == other.script
49            && self.redirect_output == other.redirect_output
50            && self.append_output == other.append_output
51            // F0222: Compare ExecutionMode field
52            && self.execution_mode == other.execution_mode
53            && self.selected == other.selected
54            && self.waiting == other.waiting
55            && self.hovered == other.hovered
56    }
57}
58
59impl Eq for Choice {}
60
61impl Clone for Choice {
62    fn clone(&self) -> Self {
63        Choice {
64            id: self.id.clone(),
65            content: self.content.clone(),
66            script: self.script.clone(),
67            redirect_output: self.redirect_output.clone(),
68            append_output: self.append_output,
69            // F0222: Clone ExecutionMode field
70            execution_mode: self.execution_mode.clone(),
71            selected: self.selected,
72            waiting: self.waiting,
73            hovered: self.hovered,
74        }
75    }
76}