1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
use serde::{Deserialize, Serialize};
use zellij_utils::{input::config::Config, pane_size::Size};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct WebClientToWebServerControlMessage {
pub web_client_id: String,
pub payload: WebClientToWebServerControlMessagePayload,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "type")]
pub enum WebClientToWebServerControlMessagePayload {
TerminalResize(Size),
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "type")]
pub enum WebServerToWebClientControlMessage {
SetConfig(SetConfigPayload),
QueryTerminalSize,
Log { lines: Vec<String> },
LogError { lines: Vec<String> },
SwitchedSession { new_session_name: String },
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SetConfigPayload {
pub font: String,
pub theme: SetConfigPayloadTheme,
pub cursor_blink: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor_inactive_style: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor_style: Option<String>,
pub mac_option_is_meta: bool,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[serde(rename_all = "camelCase")]
pub struct SetConfigPayloadTheme {
#[serde(skip_serializing_if = "Option::is_none")]
pub background: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub foreground: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub black: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub blue: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bright_black: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bright_blue: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bright_cyan: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bright_green: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bright_magenta: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bright_red: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bright_white: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bright_yellow: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor_accent: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub cyan: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub green: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub magenta: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub red: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub selection_background: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub selection_foreground: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub selection_inactive_background: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub white: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub yellow: Option<String>,
}
impl From<&Config> for SetConfigPayload {
fn from(config: &Config) -> Self {
let font = config.web_client.font.clone();
let palette = config.theme_config(config.options.theme.as_ref());
let web_client_theme_from_config = config.web_client.theme.as_ref();
let mut theme = SetConfigPayloadTheme::default();
theme.background = web_client_theme_from_config
.and_then(|theme| theme.background.clone())
.or_else(|| palette.map(|p| p.text_unselected.background.as_rgb_str()));
theme.foreground = web_client_theme_from_config
.and_then(|theme| theme.foreground.clone())
.or_else(|| palette.map(|p| p.text_unselected.base.as_rgb_str()));
theme.black = web_client_theme_from_config.and_then(|theme| theme.black.clone());
theme.blue = web_client_theme_from_config.and_then(|theme| theme.blue.clone());
theme.bright_black =
web_client_theme_from_config.and_then(|theme| theme.bright_black.clone());
theme.bright_blue =
web_client_theme_from_config.and_then(|theme| theme.bright_blue.clone());
theme.bright_cyan =
web_client_theme_from_config.and_then(|theme| theme.bright_cyan.clone());
theme.bright_green =
web_client_theme_from_config.and_then(|theme| theme.bright_green.clone());
theme.bright_magenta =
web_client_theme_from_config.and_then(|theme| theme.bright_magenta.clone());
theme.bright_red = web_client_theme_from_config.and_then(|theme| theme.bright_red.clone());
theme.bright_white =
web_client_theme_from_config.and_then(|theme| theme.bright_white.clone());
theme.bright_yellow =
web_client_theme_from_config.and_then(|theme| theme.bright_yellow.clone());
theme.cursor = web_client_theme_from_config.and_then(|theme| theme.cursor.clone());
theme.cursor_accent =
web_client_theme_from_config.and_then(|theme| theme.cursor_accent.clone());
theme.cyan = web_client_theme_from_config.and_then(|theme| theme.cyan.clone());
theme.green = web_client_theme_from_config.and_then(|theme| theme.green.clone());
theme.magenta = web_client_theme_from_config.and_then(|theme| theme.magenta.clone());
theme.red = web_client_theme_from_config.and_then(|theme| theme.red.clone());
theme.selection_background = web_client_theme_from_config
.and_then(|theme| theme.selection_background.clone())
.or_else(|| palette.map(|p| p.text_selected.background.as_rgb_str()));
theme.selection_foreground = web_client_theme_from_config
.and_then(|theme| theme.selection_foreground.clone())
.or_else(|| palette.map(|p| p.text_selected.base.as_rgb_str()));
theme.selection_inactive_background = web_client_theme_from_config
.and_then(|theme| theme.selection_inactive_background.clone());
theme.white = web_client_theme_from_config.and_then(|theme| theme.white.clone());
theme.yellow = web_client_theme_from_config.and_then(|theme| theme.yellow.clone());
let cursor_blink = config.web_client.cursor_blink;
let mac_option_is_meta = config.web_client.mac_option_is_meta;
let cursor_style = config
.web_client
.cursor_style
.as_ref()
.map(|s| s.to_string());
let cursor_inactive_style = config
.web_client
.cursor_inactive_style
.as_ref()
.map(|s| s.to_string());
SetConfigPayload {
font,
theme,
cursor_blink,
mac_option_is_meta,
cursor_style,
cursor_inactive_style,
}
}
}
|