Commit ff4d92e890

ff4d92e890d8d44b75ba98dfedb0dda74ea2ae05

parent: f605eeae85

Unregistered key

vaw <git@nlih.de> · 2026-09-24 02:01 UTC
committer: <noreply@github.com>

Support styling user interface (#472)

Co-authored-by: Ulyssa <git@ulyssa.dev>

Layout: unified · split

config.example.toml +6
@@ -88,3 +88,9 @@ split = [
8888cache = "/home/user/.cache/iamb/"
8989logs = "/home/user/.local/share/iamb/logs/"
9090downloads = "/home/user/Downloads/"
91
92[theme]
93timeline.state.color = "cyan"
94timeline.redacted.color = "245" # light gray
95# How to use truecolor for terminals that support it:
96# rooms.unread.color = "#ff55bb" # pink
docs/iamb.5 +133 −19
@@ -374,6 +374,38 @@ and
374374Both can be used via
375375.Dq Sy title|prompt .
376376.El
377.Sh COLORS
378The
379.Sy settings.users
380and
381.Sy theme
382subsections allows configuring the appearance of many elements.
383For settings that take a color value, you can use either a named color, an 8-bit color value or a hex value.
384.Pp
385The named colors are:
386.Dq Sy black ,
387.Dq Sy red ,
388.Dq Sy green ,
389.Dq Sy yellow ,
390.Dq Sy blue ,
391.Dq Sy magenta ,
392.Dq Sy cyan ,
393.Dq Sy gray ,
394.Dq Sy dark-gray ,
395.Dq Sy light-red ,
396.Dq Sy light-green ,
397.Dq Sy light-yellow ,
398.Dq Sy light-blue ,
399.Dq Sy light-magenta ,
400.Dq Sy light-cyan ,
401.Dq Sy white ,
402and
403.Dq Sy reset ,
404The 8-bit ANSI color must in the range of 0 to 255 where the first 16 colors correspond to the named colors.
405The hex value is given as
406.Dq Sy #RRGGBB .
407If the terminal does not support truecolor, all hex colors will fall back to the default text color.
408All values must be given as a string.
377409.Sh IMAGE PREVIEWS
378410The
379411.Sy settings.image_preview
@@ -639,6 +671,104 @@ Whether to set the title of the terminal window to
639671.Dq Sy iamb (<user_id>) .
640672Defaults to true.
641673.El
674.Sh "THEME OVERRIDES"
675The
676.Sy theme
677subsection allows you to override the colors used for different parts of the user interface.
678Individual, stylable UI elements have the following properties:
679.Bl -tag -width Ds
680.It Sy color
681Configure the foreground color for text.
682See the
683.Sx "COLORS"
684section for the supported color format.
685.It Sy background
686Configure the background color for text.
687See the
688.Sx "COLORS"
689section for the supported color format.
690.El
691Within
692.Sy theme ,
693there are several subsections for specific UI areas:
694.Bl -tag -width Ds
695.It Sy messages
696For controlling how the bodies of messages are styled.
697UI elements you can set within this subsection are:
698.Bl -tag -width Ds
699.It Sy default
700Configure the default styling for messages.
701.It Sy code
702Configure the styling for
703.Sy "<code>"
704elements in formatted message bodies.
705.It Sy "code_block"
706Configure the styling for
707.Sy "<pre>"
708elements in formatted message bodies.
709.El
710.It Sy timeline
711For controlling how other elements within the timeline are styled.
712UI elements you can set within this subsection are:
713.Bl -tag -width Ds
714.It Sy default
715Configure the default styling for text in the timeline.
716.It Sy date
717Configure the how the dates for messages are styled.
718.It Sy time
719Configure the how the time a message was sent is styled.
720.It Sy state
721Configure how the text shown for state events is styled.
722.It Sy sticker
723Configure how any text shown for stickers is styled.
724.It Sy poll
725Configure how the text in polls is styled.
726.It Sy notice
727Configure how server notices is styled.
728.It Sy redacted
729Configure how redacted events in the timeline is styled.
730.El
731.It Sy windows
732For controlling how the windows are styled.
733.Bl -tag -width Ds
734.It Sy border
735Configure how the border characters are styled.
736.It Sy border_focused
737Configure how the border characters for focused window are styled.
738.It Sy title
739Configure how the window titles are styled.
740.El
741.It Sy tabs
742For controlling how tabs are styled.
743UI elements you can set within this subsection are:
744.Bl -tag -width Ds
745.It Sy title
746Configure how tab titles are styled.
747.It Sy title_focused
748Configure how the title of the focused tab is styled.
749.El
750.It Sy rooms
751For controlling how lists of rooms like
752.Sy :unreads
753or
754.Sy :chats
755are styled.
756UI elements you can set within this subsection are:
757.Bl -tag -width Ds
758.It Sy default
759Configure the default style for text in room lists.
760.It Sy unread
761Configure the text for unread rooms in lists is styled.
762.El
763.El
764.Ss Example: Make code blocks a lighter gray background and state events red
765.Bd -literal -offset indent
766[theme.messages]
767code_block.background = "245"
768
769[theme.timeline]
770state.color = "cyan"
771.Ed
642772.Sh "USER OVERRIDES"
643773The
644774.Sy settings.users
@@ -651,25 +781,9 @@ and are typically written as inline tables containing the following keys:
651781Change the display name of the user.
652782.It Sy color
653783Change the color the user is shown as.
654Possible values are:
655.Dq Sy black ,
656.Dq Sy blue ,
657.Dq Sy cyan ,
658.Dq Sy dark-gray ,
659.Dq Sy gray ,
660.Dq Sy green ,
661.Dq Sy light-blue ,
662.Dq Sy light-cyan ,
663.Dq Sy light-green ,
664.Dq Sy light-magenta ,
665.Dq Sy light-red ,
666.Dq Sy light-yellow ,
667.Dq Sy magenta ,
668.Dq Sy none ,
669.Dq Sy red ,
670.Dq Sy white ,
671and
672.Dq Sy yellow .
784See the
785.Sx "COLORS"
786section for the supported color format.
673787.El
674788.Ss Example 1: Override how @ada:example.com appears in chat
675789.Bd -literal -offset indent
src/config.rs → src/config/mod.rs renamed +59 −54
@@ -6,6 +6,7 @@ use std::fs::File;
66use std::hash::{Hash, Hasher};
77use std::io::{BufReader, BufWriter, Write as _};
88use std::process;
9use std::sync::Arc;
910
1011use clap::Parser;
1112use indexmap::IndexMap;
@@ -27,6 +28,8 @@ use serde::{Deserialize, Deserializer, Serialize};
2728use crate::base::{SortColumn, SortFieldRoom, SortFieldUser, SortOrder};
2829use crate::prelude::*;
2930
31pub mod theme;
32
3033pub type Aliases = IndexMap<String, String>;
3134type Macros = HashMap<VimModes, HashMap<Keys, Keys>>;
3235
@@ -228,7 +231,6 @@ macro_rules! deserialize_str_with_visitor {
228231
229232deserialize_str_with_visitor!(Keys, KeysVisitor);
230233deserialize_str_with_visitor!(VimModes, VimModesVisitor);
231deserialize_str_with_visitor!(UserColor, UserColorVisitor);
232234deserialize_str_with_visitor!(EncryptionIndicatorLocation, EncryptionIndicatorLocationVisitor);
233235deserialize_str_with_visitor!(NotifyVia, NotifyViaVisitor);
234236deserialize_str_with_visitor!(ProxyUrl, ProxyUrlVisitor);
@@ -290,44 +292,6 @@ impl Visitor<'_> for VimModesVisitor {
290292 }
291293}
292294
293#[derive(Clone, Debug, Eq, PartialEq)]
294pub struct UserColor(pub Color);
295pub struct UserColorVisitor;
296
297impl Visitor<'_> for UserColorVisitor {
298 type Value = UserColor;
299
300 fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
301 formatter.write_str("a valid color")
302 }
303
304 fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
305 where
306 E: SerdeError,
307 {
308 match value {
309 "none" => Ok(UserColor(Color::Reset)),
310 "red" => Ok(UserColor(Color::Red)),
311 "black" => Ok(UserColor(Color::Black)),
312 "green" => Ok(UserColor(Color::Green)),
313 "yellow" => Ok(UserColor(Color::Yellow)),
314 "blue" => Ok(UserColor(Color::Blue)),
315 "magenta" => Ok(UserColor(Color::Magenta)),
316 "cyan" => Ok(UserColor(Color::Cyan)),
317 "gray" => Ok(UserColor(Color::Gray)),
318 "dark-gray" => Ok(UserColor(Color::DarkGray)),
319 "light-red" => Ok(UserColor(Color::LightRed)),
320 "light-green" => Ok(UserColor(Color::LightGreen)),
321 "light-yellow" => Ok(UserColor(Color::LightYellow)),
322 "light-blue" => Ok(UserColor(Color::LightBlue)),
323 "light-magenta" => Ok(UserColor(Color::LightMagenta)),
324 "light-cyan" => Ok(UserColor(Color::LightCyan)),
325 "white" => Ok(UserColor(Color::White)),
326 _ => Err(E::custom("Could not parse color")),
327 }
328 }
329}
330
331295#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
332296pub struct Session {
333297 access_token: String,
@@ -364,7 +328,7 @@ impl From<MatrixSession> for Session {
364328
365329#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
366330pub struct UserDisplayTunables {
367 pub color: Option<UserColor>,
331 pub color: Option<Color>,
368332 pub name: Option<String>,
369333}
370334
@@ -1207,6 +1171,7 @@ pub struct ProfileConfig {
12071171 pub password_file: Option<PathBuf>,
12081172 pub url: Option<Url>,
12091173 pub settings: Option<Tunables>,
1174 pub theme: Option<theme::Theme>,
12101175 pub dirs: Option<Directories>,
12111176 pub layout: Option<Layout>,
12121177 pub macros: Option<Macros>,
@@ -1222,6 +1187,7 @@ pub struct IambConfig {
12221187 pub layout: Option<Layout>,
12231188 pub macros: Option<Macros>,
12241189 pub aliases: Option<Aliases>,
1190 pub theme: Option<theme::Theme>,
12251191}
12261192
12271193impl IambConfig {
@@ -1250,6 +1216,7 @@ pub struct ApplicationSettings {
12501216 pub sqlite_cache_dir: PathBuf,
12511217 pub profile_name: String,
12521218 pub profile: ProfileConfig,
1219 pub theme: Arc<theme::ThemeValues>,
12531220 pub tunables: TunableValues,
12541221 pub dirs: DirectoryValues,
12551222 pub layout: Layout,
@@ -1304,6 +1271,7 @@ impl ApplicationSettings {
13041271 layout,
13051272 macros,
13061273 aliases,
1274 theme,
13071275 } = config;
13081276
13091277 validate_profile_names(&profiles);
@@ -1357,6 +1325,10 @@ impl ApplicationSettings {
13571325 let dirs = profile.dirs.take().unwrap_or_default().merge(dirs);
13581326 let dirs = dirs.values();
13591327
1328 let theme = theme.unwrap_or_default().merge(theme::default_theme());
1329 let theme = profile.theme.take().unwrap_or_default().merge(theme);
1330 let theme = Arc::new(theme.values());
1331
13601332 // Create directories
13611333 dirs.create_dir_all()?;
13621334
@@ -1401,6 +1373,7 @@ impl ApplicationSettings {
14011373 sqlite_cache_dir,
14021374 profile_name,
14031375 profile,
1376 theme,
14041377 tunables,
14051378 dirs,
14061379 layout,
@@ -1451,12 +1424,7 @@ impl ApplicationSettings {
14511424 .tunables
14521425 .users
14531426 .get(user_id)
1454 .map(|user| {
1455 (
1456 user.color.as_ref().map(|c| c.0),
1457 user.name.as_ref().and_then(|s| s.chars().next()),
1458 )
1459 })
1427 .map(|user| (user.color, user.name.as_ref().and_then(|s| s.chars().next())))
14601428 .unwrap_or_default();
14611429
14621430 let color = color.unwrap_or_else(|| user_color(user_id.as_str()));
@@ -1474,7 +1442,7 @@ impl ApplicationSettings {
14741442 self.tunables
14751443 .users
14761444 .get(user_id)
1477 .map(|user| (user.color.as_ref().map(|c| c.0), user.name.clone().map(Cow::Owned)))
1445 .map(|user| (user.color, user.name.clone().map(Cow::Owned)))
14781446 .unwrap_or_default()
14791447 }
14801448
@@ -1482,7 +1450,7 @@ impl ApplicationSettings {
14821450 self.tunables
14831451 .users
14841452 .get(user_id)
1485 .and_then(|user| user.color.as_ref().map(|c| c.0))
1453 .and_then(|user| user.color)
14861454 .unwrap_or_else(|| user_color(user_id.as_str()))
14871455 }
14881456
@@ -1559,13 +1527,13 @@ mod tests {
15591527 fn test_merge_users() {
15601528 let a = None;
15611529 let b = vec![(user_id!("@a:b.c").to_owned(), UserDisplayTunables {
1562 color: Some(UserColor(Color::Red)),
1530 color: Some(Color::Red),
15631531 name: Some("Hello".into()),
15641532 })]
15651533 .into_iter()
15661534 .collect::<HashMap<_, _>>();
15671535 let c = vec![(user_id!("@a:b.c").to_owned(), UserDisplayTunables {
1568 color: Some(UserColor(Color::Green)),
1536 color: Some(Color::Green),
15691537 name: Some("World".into()),
15701538 })]
15711539 .into_iter()
@@ -1611,17 +1579,52 @@ mod tests {
16111579 assert_eq!(res.typing_notice_send, None);
16121580 assert_eq!(res.typing_notice_display, None);
16131581 assert_eq!(res.users, Some(HashMap::new()));
1582 }
16141583
1584 #[test]
1585 fn test_parse_user_colors() {
1586 let expect = |color| UserDisplayTunables { color: Some(color), name: Some("Tim".into()) };
1587
1588 // Unprefixed color:
16151589 let res: Tunables = serde_json::from_str(
16161590 "{\"users\": {\"@a:b.c\": {\"color\": \"black\", \"name\": \"Tim\"}}}",
16171591 )
16181592 .unwrap();
16191593 assert_eq!(res.typing_notice_send, None);
16201594 assert_eq!(res.typing_notice_display, None);
1621 let users = vec![(user_id!("@a:b.c").to_owned(), UserDisplayTunables {
1622 color: Some(UserColor(Color::Black)),
1623 name: Some("Tim".into()),
1624 })];
1595 let users = vec![(user_id!("@a:b.c").to_owned(), expect(Color::Black))];
1596 assert_eq!(res.users, Some(users.into_iter().collect()));
1597
1598 // Color with `light-` prefix:
1599 let res: Tunables = serde_json::from_str(
1600 "{\"users\": {\"@a:b.c\": {\"color\": \"light-red\", \"name\": \"Tim\"}}}",
1601 )
1602 .unwrap();
1603 let users = vec![(user_id!("@a:b.c").to_owned(), expect(Color::LightRed))];
1604 assert_eq!(res.users, Some(users.into_iter().collect()));
1605
1606 // Color name with `light-` prefix:
1607 let res: Tunables = serde_json::from_str(
1608 "{\"users\": {\"@a:b.c\": {\"color\": \"light-red\", \"name\": \"Tim\"}}}",
1609 )
1610 .unwrap();
1611 let users = vec![(user_id!("@a:b.c").to_owned(), expect(Color::LightRed))];
1612 assert_eq!(res.users, Some(users.into_iter().collect()));
1613
1614 // Color name with `light` prefix, no hyphen:
1615 let res: Tunables = serde_json::from_str(
1616 "{\"users\": {\"@a:b.c\": {\"color\": \"lightblue\", \"name\": \"Tim\"}}}",
1617 )
1618 .unwrap();
1619 let users = vec![(user_id!("@a:b.c").to_owned(), expect(Color::LightBlue))];
1620 assert_eq!(res.users, Some(users.into_iter().collect()));
1621
1622 // Hex color name:
1623 let res: Tunables = serde_json::from_str(
1624 "{\"users\": {\"@a:b.c\": {\"color\": \"#ff55bb\", \"name\": \"Tim\"}}}",
1625 )
1626 .unwrap();
1627 let users = vec![(user_id!("@a:b.c").to_owned(), expect(Color::Rgb(0xff, 0x55, 0xbb)))];
16251628 assert_eq!(res.users, Some(users.into_iter().collect()));
16261629 }
16271630
@@ -1924,6 +1927,7 @@ mod tests {
19241927 layout,
19251928 macros,
19261929 aliases,
1930 theme,
19271931 } = &config;
19281932
19291933 // There should be an example object for each top-level field.
@@ -1934,6 +1938,7 @@ mod tests {
19341938 assert!(layout.is_some());
19351939 assert!(macros.is_some());
19361940 assert!(aliases.is_some());
1941 assert!(theme.is_some());
19371942 }
19381943
19391944 #[test]
src/config/theme.rs added +322
@@ -0,0 +1,322 @@
1//! # Logic for parsing styling configuration into [Style].
2use serde::Deserialize;
3
4use crate::prelude::*;
5
6pub fn default_theme() -> Theme {
7 Theme {
8 messages: ThemeMessages {
9 code: Stylable { color: None, background: Some(Color::Indexed(236)) },
10 ..Default::default()
11 },
12 ..Default::default()
13 }
14}
15
16#[derive(Clone, Copy, Debug, Default, Deserialize)]
17pub struct Stylable {
18 pub background: Option<Color>,
19 pub color: Option<Color>,
20}
21
22impl Stylable {
23 fn merge(self, other: Self) -> Self {
24 Self {
25 background: self.background.or(other.background),
26 color: self.color.or(other.color),
27 }
28 }
29}
30
31impl From<Stylable> for Style {
32 fn from(styled: Stylable) -> Self {
33 let mut style = Style::default();
34
35 if let Some(bg) = styled.background {
36 style = style.bg(bg);
37 }
38
39 if let Some(fg) = styled.color {
40 style = style.fg(fg);
41 }
42
43 style
44 }
45}
46
47#[derive(Clone, Debug, Default, Deserialize)]
48pub struct Theme {
49 /// Configuration specificaly for messages shown within a room's timeline.
50 #[serde(default)]
51 messages: ThemeMessages,
52
53 /// Configuration for styling a room's timeline.
54 #[serde(default)]
55 timeline: ThemeTimeline,
56
57 /// Configuration for styling items within room lists.
58 #[serde(default)]
59 rooms: ThemeRooms,
60
61 /// Configuration for styling tabs.
62 #[serde(default)]
63 tabs: ThemeTabs,
64
65 /// Configuration for styling windows.
66 #[serde(default)]
67 windows: ThemeWindows,
68}
69
70impl Theme {
71 pub fn merge(self, other: Self) -> Self {
72 Self {
73 messages: self.messages.merge(other.messages),
74 tabs: self.tabs.merge(other.tabs),
75 timeline: self.timeline.merge(other.timeline),
76 rooms: self.rooms.merge(other.rooms),
77 windows: self.windows.merge(other.windows),
78 }
79 }
80
81 pub fn values(self) -> ThemeValues {
82 let base = Style::default();
83
84 ThemeValues {
85 messages: self.messages.values(base),
86 timeline: self.timeline.values(base),
87 rooms: self.rooms.values(base),
88 tabs: self.tabs.values(base),
89 windows: self.windows.values(base),
90 }
91 }
92}
93
94#[derive(Clone, Debug, Default)]
95pub struct ThemeValues {
96 /// Styling specificaly for messages shown within a room's timeline.
97 pub messages: ThemeMessagesValues,
98
99 /// Styling for a room's timeline.
100 pub timeline: ThemeTimelineValues,
101
102 /// Styling for items within room lists.
103 pub rooms: ThemeRoomsValues,
104
105 /// Styling for rendering tabs.
106 pub tabs: ThemeTabsValues,
107
108 /// Styling for rendering windows.
109 pub windows: ThemeWindowsValues,
110}
111
112#[derive(Clone, Debug, Default, Deserialize)]
113struct ThemeMessages {
114 #[serde(default)]
115 default: Stylable,
116
117 #[serde(default)]
118 code: Stylable,
119
120 #[serde(default)]
121 code_block: Stylable,
122}
123
124impl ThemeMessages {
125 fn merge(self, other: Self) -> Self {
126 Self {
127 default: self.default.merge(other.default),
128 code: self.code.merge(other.code),
129 code_block: self.code_block.merge(other.code_block),
130 }
131 }
132
133 fn values(self, base: Style) -> ThemeMessagesValues {
134 let code = self.code.merge(self.default);
135 let code_block = self.code_block.merge(code);
136
137 ThemeMessagesValues {
138 default: base.patch(self.default),
139 code: base.patch(code),
140 code_block: base.patch(code_block),
141 }
142 }
143}
144
145#[derive(Clone, Debug, Default)]
146pub struct ThemeMessagesValues {
147 pub default: Style,
148 pub code: Style,
149 pub code_block: Style,
150}
151
152#[derive(Clone, Debug, Default, Deserialize)]
153struct ThemeRooms {
154 #[serde(default)]
155 default: Stylable,
156
157 #[serde(default)]
158 unread: Stylable,
159}
160
161impl ThemeRooms {
162 fn merge(self, other: Self) -> Self {
163 Self {
164 default: self.default.merge(other.default),
165 unread: self.unread.merge(other.unread),
166 }
167 }
168
169 fn values(self, base: Style) -> ThemeRoomsValues {
170 let unread = self.unread.merge(self.default);
171
172 ThemeRoomsValues {
173 default: base.patch(self.default),
174 unread: base.patch(unread),
175 }
176 }
177}
178
179#[derive(Clone, Debug, Default)]
180pub struct ThemeRoomsValues {
181 pub default: Style,
182 pub unread: Style,
183}
184
185#[derive(Clone, Debug, Default, Deserialize)]
186struct ThemeTabs {
187 #[serde(default)]
188 title: Stylable,
189
190 #[serde(default)]
191 title_focused: Stylable,
192}
193
194impl ThemeTabs {
195 fn merge(self, other: Self) -> Self {
196 Self {
197 title: self.title.merge(other.title),
198 title_focused: self.title_focused.merge(other.title_focused),
199 }
200 }
201
202 fn values(self, base: Style) -> ThemeTabsValues {
203 let title_focused = self.title_focused.merge(self.title);
204
205 ThemeTabsValues {
206 title: base.patch(self.title),
207 title_focused: base.patch(title_focused),
208 }
209 }
210}
211
212#[derive(Clone, Debug, Default)]
213pub struct ThemeTabsValues {
214 pub title: Style,
215 pub title_focused: Style,
216}
217
218#[derive(Clone, Debug, Default, Deserialize)]
219struct ThemeTimeline {
220 #[serde(default)]
221 default: Stylable,
222
223 #[serde(default)]
224 date: Stylable,
225
226 #[serde(default)]
227 time: Stylable,
228
229 #[serde(default)]
230 state: Stylable,
231
232 #[serde(default)]
233 sticker: Stylable,
234
235 #[serde(default)]
236 poll: Stylable,
237
238 #[serde(default)]
239 notice: Stylable,
240
241 #[serde(default)]
242 redacted: Stylable,
243}
244
245impl ThemeTimeline {
246 fn merge(self, other: Self) -> Self {
247 Self {
248 default: self.default.merge(other.default),
249 date: self.date.merge(other.date),
250 time: self.time.merge(other.time),
251 state: self.state.merge(other.state),
252 sticker: self.sticker.merge(other.sticker),
253 poll: self.poll.merge(other.poll),
254 notice: self.notice.merge(other.notice),
255 redacted: self.redacted.merge(other.redacted),
256 }
257 }
258
259 fn values(self, base: Style) -> ThemeTimelineValues {
260 let base = base.patch(self.default);
261
262 ThemeTimelineValues {
263 default: base,
264 date: base.patch(self.date),
265 time: base.patch(self.time),
266 state: base.patch(self.state),
267 sticker: base.patch(self.sticker),
268 poll: base.patch(self.poll),
269 notice: base.patch(self.notice),
270 redacted: base.patch(self.redacted),
271 }
272 }
273}
274
275#[derive(Clone, Debug, Default)]
276pub struct ThemeTimelineValues {
277 pub default: Style,
278 pub date: Style,
279 pub time: Style,
280 pub state: Style,
281 pub sticker: Style,
282 pub poll: Style,
283 pub notice: Style,
284 pub redacted: Style,
285}
286
287#[derive(Clone, Debug, Default, Deserialize)]
288struct ThemeWindows {
289 #[serde(default)]
290 border: Stylable,
291
292 #[serde(default)]
293 border_focused: Stylable,
294
295 #[serde(default)]
296 title: Stylable,
297}
298
299impl ThemeWindows {
300 fn merge(self, other: Self) -> Self {
301 Self {
302 border: self.border.merge(other.border),
303 border_focused: self.border_focused.merge(other.border_focused),
304 title: self.title.merge(other.title),
305 }
306 }
307
308 fn values(self, base: Style) -> ThemeWindowsValues {
309 ThemeWindowsValues {
310 border: base.patch(self.border),
311 border_focused: base.patch(self.border_focused.merge(self.border)),
312 title: base.patch(self.title),
313 }
314 }
315}
316
317#[derive(Clone, Debug, Default)]
318pub struct ThemeWindowsValues {
319 pub border: Style,
320 pub border_focused: Style,
321 pub title: Style,
322}
src/main.rs +8 −3
@@ -332,6 +332,8 @@ impl Application {
332332 term.clear()?;
333333 }
334334
335 let theme = store.application.settings.theme.clone();
336
335337 term.draw(|f| {
336338 let area = f.area();
337339
@@ -347,9 +349,12 @@ impl Application {
347349 .show_dialog(dialogstr)
348350 .show_mode(modestr)
349351 .borders(true)
350 .border_style(Style::default().add_modifier(StyleModifier::DIM))
351 .tab_style(Style::default().add_modifier(StyleModifier::DIM))
352 .tab_style_focused(Style::default().remove_modifier(StyleModifier::DIM))
352 .border_style(theme.windows.border.add_modifier(StyleModifier::DIM))
353 .border_style_focused(
354 theme.windows.border_focused.remove_modifier(StyleModifier::DIM),
355 )
356 .tab_style(theme.tabs.title.add_modifier(StyleModifier::DIM))
357 .tab_style_focused(theme.tabs.title_focused.remove_modifier(StyleModifier::DIM))
353358 .focus(focused);
354359 f.render_stateful_widget(screen, area, sstate);
355360
src/message/html.rs +38 −29
@@ -368,7 +368,13 @@ impl StyleTreeNode {
368368 }
369369 },
370370 StyleTreeNode::Code(child, _) => {
371 let style = style.patch(printer.settings().theme.messages.code);
372
373 let old_style = printer.replace_base_style(style);
374
371375 child.print(printer, style);
376
377 printer.replace_base_style(old_style);
372378 },
373379 StyleTreeNode::Header(child, level) => {
374380 let style = style.add_modifier(StyleModifier::BOLD);
@@ -415,9 +421,11 @@ impl StyleTreeNode {
415421 },
416422 StyleTreeNode::Pre(child) => {
417423 let mut subp = printer.sub(2).literal(true);
424 let code_style = style.patch(subp.settings().theme.messages.code_block);
425 let _ = subp.replace_base_style(code_style);
418426 let subw = subp.width();
419427
420 child.print(&mut subp, style);
428 child.print(&mut subp, code_style);
421429
422430 printer.commit();
423431 printer.push_line(
@@ -1446,6 +1454,7 @@ pub mod tests {
14461454 fn test_pre_tag() {
14471455 let info = mock_room();
14481456 let settings = mock_settings();
1457 let code_style = settings.theme.messages.code_block;
14491458 let s = concat!(
14501459 "<pre><code class=\"language-rust\">",
14511460 "fn hello() -&gt; usize {\n",
@@ -1469,19 +1478,19 @@ pub mod tests {
14691478 text.lines[1],
14701479 Line::from(vec![
14711480 Span::raw(line::VERTICAL),
1472 Span::raw("fn"),
1473 Span::raw(" "),
1474 Span::raw("hello"),
1475 Span::raw("("),
1476 Span::raw(")"),
1477 Span::raw(" "),
1478 Span::raw("-"),
1479 Span::raw(">"),
1480 Span::raw(" "),
1481 Span::raw("usize"),
1482 Span::raw(" "),
1483 Span::raw("{"),
1484 Span::raw(" "),
1481 Span::styled("fn", code_style),
1482 Span::styled(" ", code_style),
1483 Span::styled("hello", code_style),
1484 Span::styled("(", code_style),
1485 Span::styled(")", code_style),
1486 Span::styled(" ", code_style),
1487 Span::styled("-", code_style),
1488 Span::styled(">", code_style),
1489 Span::styled(" ", code_style),
1490 Span::styled("usize", code_style),
1491 Span::styled(" ", code_style),
1492 Span::styled("{", code_style),
1493 Span::styled(" ", code_style),
14851494 Span::raw(line::VERTICAL)
14861495 ])
14871496 );
@@ -1489,13 +1498,13 @@ pub mod tests {
14891498 text.lines[2],
14901499 Line::from(vec![
14911500 Span::raw(line::VERTICAL),
1492 Span::raw(" "),
1493 Span::raw(" "),
1494 Span::raw("/"),
1495 Span::raw("/"),
1496 Span::raw(" "),
1497 Span::raw("weired"),
1498 Span::raw(" "),
1501 Span::styled(" ", code_style),
1502 Span::styled(" ", code_style),
1503 Span::styled("/", code_style),
1504 Span::styled("/", code_style),
1505 Span::styled(" ", code_style),
1506 Span::styled("weired", code_style),
1507 Span::styled(" ", code_style),
14991508 Span::raw(line::VERTICAL)
15001509 ])
15011510 );
@@ -1503,12 +1512,12 @@ pub mod tests {
15031512 text.lines[3],
15041513 Line::from(vec![
15051514 Span::raw(line::VERTICAL),
1506 Span::raw(" "),
1507 Span::raw("return"),
1508 Span::raw(" "),
1509 Span::raw("5"),
1510 Span::raw(";"),
1511 Span::raw(" "),
1515 Span::styled(" ", code_style),
1516 Span::styled("return", code_style),
1517 Span::styled(" ", code_style),
1518 Span::styled("5", code_style),
1519 Span::styled(";", code_style),
1520 Span::styled(" ", code_style),
15121521 Span::raw(line::VERTICAL)
15131522 ])
15141523 );
@@ -1516,8 +1525,8 @@ pub mod tests {
15161525 text.lines[4],
15171526 Line::from(vec![
15181527 Span::raw(line::VERTICAL),
1519 Span::raw("}"),
1520 Span::raw(" ".repeat(22)),
1528 Span::styled("}", code_style),
1529 Span::styled(" ".repeat(22), code_style),
15211530 Span::raw(line::VERTICAL)
15221531 ])
15231532 );
src/message/mod.rs +38 −20
@@ -117,14 +117,6 @@ const fn span_static(s: &'static str) -> Span<'static> {
117117 }
118118}
119119
120const BOLD_STYLE: Style = Style {
121 fg: None,
122 bg: None,
123 add_modifier: StyleModifier::BOLD,
124 sub_modifier: StyleModifier::empty(),
125 underline_color: None,
126};
127
128120const TIME_GUTTER: usize = 12;
129121const READ_GUTTER: usize = 5;
130122const MIN_MSG_LEN: usize = 30;
@@ -228,10 +220,10 @@ impl MessageTimeStamp {
228220 dt1.date_naive() == dt2.date_naive()
229221 }
230222
231 fn show_date(self) -> Span<'static> {
223 fn show_date(self, settings: &ApplicationSettings) -> Span<'static> {
232224 let time = self.as_datetime().format("%A, %B %d %Y").to_string();
233225
234 Span::styled(time, BOLD_STYLE)
226 Span::styled(time, settings.theme.timeline.date.add_modifier(StyleModifier::BOLD))
235227 }
236228
237229 /// A compact date and time, for places without a date separator line.
@@ -239,11 +231,11 @@ impl MessageTimeStamp {
239231 self.as_datetime().format("%Y-%m-%d %H:%M").to_string()
240232 }
241233
242 fn show_time(self) -> Span<'static> {
234 fn show_time(self, settings: &ApplicationSettings) -> Span<'static> {
243235 let time = self.as_datetime().format("%T");
244236 let time = format!(" [{time}]");
245237
246 Span::raw(time)
238 Span::styled(time, settings.theme.timeline.time)
247239 }
248240}
249241
@@ -492,6 +484,33 @@ impl MessageEvent {
492484 self.msgtype().and_then(content_filename)
493485 }
494486
487 fn message_style(&self, settings: &ApplicationSettings) -> Style {
488 let content = match self {
489 MessageEvent::EncryptedOriginal(_) | MessageEvent::EncryptedRedacted(_) => {
490 return settings.theme.timeline.default;
491 },
492 MessageEvent::Redacted(..) => return settings.theme.timeline.redacted,
493 MessageEvent::State(_) => return settings.theme.timeline.state,
494 MessageEvent::Original(ev, _) => &ev.content,
495 MessageEvent::Local(_, _, content) => content,
496 MessageEvent::Sticker(..) => return settings.theme.timeline.sticker,
497 MessageEvent::Poll(..) | MessageEvent::UnstablePoll(..) => {
498 return settings.theme.timeline.poll;
499 },
500 };
501
502 match &content.msgtype {
503 MessageType::Text(_) |
504 MessageType::Audio(_) |
505 MessageType::Emote(_) |
506 MessageType::File(_) |
507 MessageType::Image(_) |
508 MessageType::Video(_) => settings.theme.messages.default,
509 MessageType::Notice(_) | MessageType::ServerNotice(_) => settings.theme.timeline.notice,
510 _ => settings.theme.messages.default,
511 }
512 }
513
495514 fn redact(&mut self, redaction: SyncRoomRedactionEvent) {
496515 match self {
497516 MessageEvent::EncryptedOriginal(_) => return,
@@ -819,7 +838,7 @@ impl<'a> MessageFormatter<'a> {
819838 let reply_style = if settings.tunables.message_user_color {
820839 style.patch(settings.get_user_color(&msg.sender))
821840 } else {
822 style
841 style.patch(msg.event.message_style(settings))
823842 };
824843
825844 let width = self.width();
@@ -932,14 +951,13 @@ impl<'a> MessageFormatter<'a> {
932951 protos
933952 }
934953
935 fn push_thread_reply_count(&mut self, len: usize, text: &mut Text<'a>) {
954 fn push_thread_reply_count(&mut self, len: usize, text: &mut Text<'a>, style: Style) {
936955 if len == 0 {
937956 return;
938957 }
939958
940959 // If we have threaded replies to this message, show how many.
941960 let plural = len != 1;
942 let style = Style::default();
943961 let mut threaded =
944962 printer::TextPrinter::new(self.width(), style, self.settings, self.info).literal(true);
945963 let len = Span::styled(len.to_string(), style.add_modifier(StyleModifier::BOLD));
@@ -1055,7 +1073,7 @@ impl Message {
10551073 }
10561074
10571075 fn get_render_style(&self, selected: bool, settings: &ApplicationSettings) -> Style {
1058 let mut style = Style::default();
1076 let mut style = self.event.message_style(settings);
10591077
10601078 if selected {
10611079 style = style.add_modifier(StyleModifier::REVERSED)
@@ -1133,7 +1151,7 @@ impl Message {
11331151 settings: &'a ApplicationSettings,
11341152 ) -> MessageFormatter<'a> {
11351153 let orig = width;
1136 let date = self.show_date(prev).then(|| self.timestamp.show_date());
1154 let date = self.show_date(prev).then(|| self.timestamp.show_date(settings));
11371155 let trackbar = self.show_trackbar(prev, info, settings);
11381156 let user_gutter = settings.tunables.user_gutter_width;
11391157
@@ -1143,7 +1161,7 @@ impl Message {
11431161 let cols = MessageColumns::Four;
11441162 let fill = width - user_gutter - TIME_GUTTER - READ_GUTTER;
11451163 let user = self.show_sender(prev, true, info, settings, width);
1146 let time = Some(self.timestamp.show_time());
1164 let time = Some(self.timestamp.show_time(settings));
11471165
11481166 let read = self
11491167 .event
@@ -1176,7 +1194,7 @@ impl Message {
11761194 let cols = MessageColumns::Three;
11771195 let fill = width - user_gutter - TIME_GUTTER;
11781196 let user = self.show_sender(prev, true, info, settings, width);
1179 let time = Some(self.timestamp.show_time());
1197 let time = Some(self.timestamp.show_time(settings));
11801198 let read = Vec::new();
11811199
11821200 MessageFormatter {
@@ -1323,7 +1341,7 @@ impl Message {
13231341 }
13241342
13251343 if let Some(thread) = self.event.event_id().and_then(|id| info.get_thread(Some(id))) {
1326 fmt.push_thread_reply_count(thread.len(), &mut text);
1344 fmt.push_thread_reply_count(thread.len(), &mut text, style);
13271345 }
13281346
13291347 (text, protos)
src/message/printer.rs +5
@@ -69,6 +69,11 @@ impl<'a> TextPrinter<'a> {
6969 self
7070 }
7171
72 /// Set the base style and return the old style.
73 pub fn replace_base_style(&mut self, style: Style) -> Style {
74 std::mem::replace(&mut self.base_style, style)
75 }
76
7277 /// Indicates whether emojis should be replaced by shortcodes
7378 pub fn emoji_shortcodes(&self) -> bool {
7479 self.tunables().message_shortcode_display
src/tests.rs +3 −1
@@ -178,7 +178,7 @@ pub fn mock_tunables() -> TunableValues {
178178 typing_notice_send: true,
179179 typing_notice_display: true,
180180 users: vec![(TEST_USER5.clone(), UserDisplayTunables {
181 color: Some(UserColor(Color::Black)),
181 color: Some(Color::Black),
182182 name: Some("USER 5".into()),
183183 })]
184184 .into_iter()
@@ -224,12 +224,14 @@ pub fn mock_settings() -> ApplicationSettings {
224224 layout: None,
225225 macros: None,
226226 aliases: None,
227 theme: None,
227228 },
228229 tunables: mock_tunables(),
229230 dirs: mock_dirs(),
230231 layout: Default::default(),
231232 macros: HashMap::default(),
232233 aliases: Aliases::default(),
234 theme: crate::config::theme::default_theme().values().into(),
233235 enable_enhanced_keys: false,
234236 }
235237}
src/windows/mod.rs +48 −42
@@ -31,26 +31,21 @@ pub mod welcome;
3131const MEMBER_FETCH_DEBOUNCE: Duration = Duration::from_secs(5);
3232
3333#[inline]
34fn bold_style() -> Style {
35 Style::default().add_modifier(StyleModifier::BOLD)
34fn bold_span(s: &str, style: Style) -> Span<'_> {
35 Span::styled(s, style.bold())
3636}
3737
3838#[inline]
39fn bold_span(s: &str) -> Span<'_> {
40 Span::styled(s, bold_style())
39fn bold_spans(s: &str, style: Style) -> Line<'_> {
40 bold_span(s, style).into()
4141}
4242
4343#[inline]
44fn bold_spans(s: &str) -> Line<'_> {
45 bold_span(s).into()
46}
47
48#[inline]
49pub fn selected_style(selected: bool) -> Style {
44pub fn selected_style(selected: bool, style: Style) -> Style {
5045 if selected {
51 Style::default().add_modifier(StyleModifier::REVERSED)
46 style.add_modifier(StyleModifier::REVERSED)
5247 } else {
53 Style::default()
48 style
5449 }
5550}
5651
@@ -409,8 +404,11 @@ impl IambWindow {
409404}
410405
411406pub type MemberListState = ListState<MemberItem, IambInfo>;
407
412408pub type PinnedListState = ListState<PinnedItem, IambInfo>;
409
413410pub type RoomListState = ListState<GenericRoomItem, IambInfo>;
411
414412pub type VerifyListState = ListState<VerifyItem, IambInfo>;
415413
416414impl From<RoomState> for IambWindow {
@@ -783,24 +781,25 @@ impl Window<IambInfo> for IambWindow {
783781 }
784782
785783 fn get_tab_title(&self, store: &mut ProgramStore) -> Line<'_> {
784 let style = Default::default();
786785 match self {
787 IambWindow::DirectList(_) => bold_spans("Direct Messages"),
788 IambWindow::RoomList(_) => bold_spans("Rooms"),
789 IambWindow::SpaceList(_) => bold_spans("Spaces"),
790 IambWindow::VerifyList(_) => bold_spans("Verifications"),
791 IambWindow::Welcome(_) => bold_spans("Welcome to iamb"),
792 IambWindow::ChatList(_) => bold_spans("DMs & Rooms"),
793 IambWindow::UnreadList(_) => bold_spans("Unread Messages"),
794 IambWindow::MentionsList(_) => bold_spans("Unread Mentions"),
795 IambWindow::InvitesList(_) => bold_spans("Open Invites"),
786 IambWindow::DirectList(_) => bold_spans("Direct Messages", style),
787 IambWindow::RoomList(_) => bold_spans("Rooms", style),
788 IambWindow::SpaceList(_) => bold_spans("Spaces", style),
789 IambWindow::VerifyList(_) => bold_spans("Verifications", style),
790 IambWindow::Welcome(_) => bold_spans("Welcome to iamb", style),
791 IambWindow::ChatList(_) => bold_spans("DMs & Rooms", style),
792 IambWindow::UnreadList(_) => bold_spans("Unread Messages", style),
793 IambWindow::MentionsList(_) => bold_spans("Unread Mentions", style),
794 IambWindow::InvitesList(_) => bold_spans("Open Invites", style),
796795
797796 IambWindow::Room(w) => w.get_tab_title(store),
798797 IambWindow::MemberList(state, room_id, _) => {
799798 let title = store.application.get_room_title(room_id.as_ref());
800799 let n = state.len();
801800 let v = vec![
802 bold_span("Room Members "),
803 Span::styled(format!("({n}): "), bold_style()),
801 bold_span("Room Members ", style),
802 Span::styled(format!("({n}): "), style.bold()),
804803 title.into(),
805804 ];
806805 Line::from(v)
@@ -809,8 +808,8 @@ impl Window<IambInfo> for IambWindow {
809808 let title = store.application.get_room_title(room_id.as_ref());
810809 let n = state.len();
811810 let v = vec![
812 bold_span("Pinned Messages "),
813 Span::styled(format!("({n}): "), bold_style()),
811 bold_span("Pinned Messages ", style),
812 Span::styled(format!("({n}): "), style.bold()),
814813 title.into(),
815814 ];
816815 Line::from(v)
@@ -819,24 +818,25 @@ impl Window<IambInfo> for IambWindow {
819818 }
820819
821820 fn get_win_title(&self, store: &mut ProgramStore) -> Line<'_> {
821 let style = store.application.settings.theme.windows.title;
822822 match self {
823 IambWindow::DirectList(_) => bold_spans("Direct Messages"),
824 IambWindow::RoomList(_) => bold_spans("Rooms"),
825 IambWindow::SpaceList(_) => bold_spans("Spaces"),
826 IambWindow::VerifyList(_) => bold_spans("Verifications"),
827 IambWindow::Welcome(_) => bold_spans("Welcome to iamb"),
828 IambWindow::ChatList(_) => bold_spans("DMs & Rooms"),
829 IambWindow::UnreadList(_) => bold_spans("Unread Messages"),
830 IambWindow::MentionsList(_) => bold_spans("Unread Mentions"),
831 IambWindow::InvitesList(_) => bold_spans("Open Invites"),
832
833 IambWindow::Room(w) => w.get_title(store),
823 IambWindow::DirectList(_) => bold_spans("Direct Messages", style),
824 IambWindow::RoomList(_) => bold_spans("Rooms", style),
825 IambWindow::SpaceList(_) => bold_spans("Spaces", style),
826 IambWindow::VerifyList(_) => bold_spans("Verifications", style),
827 IambWindow::Welcome(_) => bold_spans("Welcome to iamb", style),
828 IambWindow::ChatList(_) => bold_spans("DMs & Rooms", style),
829 IambWindow::UnreadList(_) => bold_spans("Unread Messages", style),
830 IambWindow::MentionsList(_) => bold_spans("Unread Mentions", style),
831 IambWindow::InvitesList(_) => bold_spans("Open Invites", style),
832
833 IambWindow::Room(w) => w.get_title(store, style),
834834 IambWindow::MemberList(state, room_id, _) => {
835835 let title = store.application.get_room_title(room_id.as_ref());
836836 let n = state.len();
837837 let v = vec![
838 bold_span("Room Members "),
839 Span::styled(format!("({n}): "), bold_style()),
838 bold_span("Room Members ", style),
839 Span::styled(format!("({n}): "), style.bold()),
840840 title.into(),
841841 ];
842842 Line::from(v)
@@ -845,8 +845,8 @@ impl Window<IambInfo> for IambWindow {
845845 let title = store.application.get_room_title(room_id.as_ref());
846846 let n = state.len();
847847 let v = vec![
848 bold_span("Pinned Messages "),
849 Span::styled(format!("({n}): "), bold_style()),
848 bold_span("Pinned Messages ", style),
849 Span::styled(format!("({n}): "), style.bold()),
850850 title.into(),
851851 ];
852852 Line::from(v)
@@ -1084,9 +1084,15 @@ impl ListItem<IambInfo> for GenericRoomItem {
10841084 &self,
10851085 selected: bool,
10861086 _: &ViewportContext<ListCursor>,
1087 _: &mut ProgramStore,
1087 store: &mut ProgramStore,
10881088 ) -> Text<'_> {
1089 let style = selected_style(selected);
1089 let style = if self.unread.is_unread() {
1090 store.application.settings.theme.rooms.unread
1091 } else {
1092 store.application.settings.theme.rooms.default
1093 };
1094
1095 let style = selected_style(selected, style);
10901096 let (name, mut labels) = name_and_labels(&self.name, &self.unread, self.membership, style);
10911097 let mut spans = vec![name];
10921098
src/windows/room/mod.rs +7 −7
@@ -891,14 +891,14 @@ impl RoomState {
891891 }
892892 }
893893
894 pub fn get_title(&self, store: &mut ProgramStore) -> Line<'_> {
894 pub fn get_title(&self, store: &mut ProgramStore, style: Style) -> Line<'_> {
895895 let Some(room) = self.room() else {
896896 return Line::from("Unjoined Room");
897897 };
898898
899899 let room_id = room.room_id();
900900 let title = store.application.get_room_title(room_id);
901 let style = Style::default().add_modifier(StyleModifier::BOLD);
901 let bold_style = style.add_modifier(StyleModifier::BOLD);
902902 let mut spans = vec![];
903903
904904 let encryption_settings = &store.application.settings.tunables.encryption;
@@ -910,16 +910,16 @@ impl RoomState {
910910 if let RoomState::Chat(chat) = self &&
911911 chat.thread().is_some()
912912 {
913 spans.push("Thread in ".into());
913 spans.push(Span::styled("Thread in ", style));
914914 }
915915
916 spans.push(Span::styled(title, style));
916 spans.push(Span::styled(title, bold_style));
917917
918918 match room.topic() {
919919 Some(desc) if !desc.is_empty() => {
920 spans.push(" (".into());
921 spans.push(desc.into());
922 spans.push(")".into());
920 spans.push(Span::styled(" (", style));
921 spans.push(Span::styled(desc, style));
922 spans.push(Span::styled(")", style));
923923 },
924924 _ => {
925925 spans.push(" ".into());
src/windows/verify.rs +5 −6
@@ -140,9 +140,8 @@ impl ListItem<IambInfo> for VerifyItem {
140140 store: &mut ProgramStore,
141141 ) -> Text<'_> {
142142 let mut lines = vec![];
143 let bold = Style::default().add_modifier(StyleModifier::BOLD);
144 let selected_bold = super::selected_style(selected).add_modifier(StyleModifier::BOLD);
145 let selected = super::selected_style(selected);
143 let bold = Style::default().bold();
144 let selected = super::selected_style(selected, Default::default());
146145
147146 let mut other_device = None;
148147 let state = match self.request.state() {
@@ -277,13 +276,13 @@ impl ListItem<IambInfo> for VerifyItem {
277276 if let Some(display_name) = device.display_name() {
278277 vec![
279278 Span::styled("Device verification with ", selected),
280 Span::styled(display_name.to_owned(), selected_bold),
279 Span::styled(display_name.to_owned(), selected.bold()),
281280 Span::styled(format!(" ({state})"), selected),
282281 ]
283282 } else {
284283 vec![
285284 Span::styled("Device verification with ", selected),
286 Span::styled(device.device_id().to_string(), selected_bold),
285 Span::styled(device.device_id().to_string(), selected.bold()),
287286 Span::styled(format!(" ({state})"), selected),
288287 ]
289288 }
@@ -297,7 +296,7 @@ impl ListItem<IambInfo> for VerifyItem {
297296 let color = store.application.settings.get_user_color(self.request.other_user_id());
298297 vec![
299298 Span::styled("User verification with ", selected),
300 Span::styled(self.request.other_user_id().as_str(), selected_bold.patch(color)),
299 Span::styled(self.request.other_user_id().as_str(), selected.bold().patch(color)),
301300 Span::styled(format!(" ({state})"), selected),
302301 ]
303302 };