Commit 172d66adb3

172d66adb37a4dab0c9f7c990e007aa96124328b

parent: 97dafa4629

Unregistered key

Ulyssa <git@ulyssa.dev> · 2026-10-13 02:44 UTC
committer: <noreply@github.com>

Allow styling selected items in lists and timelines (#811)

Layout: unified · split

docs/iamb.5 +2
@@ -821,6 +821,8 @@ there are several subsections for specific UI areas:
821821.Bl -tag -width Ds
822822.It Sy default
823823The base, default style that everything else should inherit.
824.It Sy selected
825Additional options for how to style selected items in lists and timelines.
824826.It Sy cmdbar
825827For controlling how the text in the command bar is styled.
826828.Bl -tag -width Ds
src/config/theme.rs +20
@@ -12,6 +12,7 @@ use crate::prelude::*;
1212
1313pub fn default_theme() -> Theme {
1414 Theme {
15 selected: Stylable::with_modifiers(StyleModifier::REVERSED),
1516 messages: ThemeMessages {
1617 blockquote: LineStylable {
1718 line: Some(LineName::Thick),
@@ -384,6 +385,10 @@ pub struct Theme {
384385 #[serde(default)]
385386 default: Stylable,
386387
388 /// Default styling to layer on top of selected list items.
389 #[serde(default)]
390 selected: Stylable,
391
387392 /// Configuration for styling the command bar.
388393 #[serde(default)]
389394 cmdbar: ThemeCommandBar,
@@ -429,6 +434,7 @@ impl Theme {
429434 pub fn merge(self, other: Self) -> Self {
430435 Self {
431436 default: self.default.merge(other.default),
437 selected: self.selected.merge(other.selected),
432438 cmdbar: self.cmdbar.merge(other.cmdbar),
433439 encryption: self.encryption.merge(other.encryption),
434440 msgbar: self.msgbar.merge(other.msgbar),
@@ -447,6 +453,7 @@ impl Theme {
447453
448454 ThemeValues {
449455 default: base,
456 selected: Style::from(self.selected),
450457 cmdbar: self.cmdbar.values(base),
451458 encryption: self.encryption.values(base),
452459 msgbar: self.msgbar.values(base),
@@ -466,6 +473,9 @@ pub struct ThemeValues {
466473 /// Styling to use when nothing more specific applies.
467474 pub default: Style,
468475
476 /// Styling to patch on top of selected list items.
477 pub selected: Style,
478
469479 /// Styling for the command bar.
470480 pub cmdbar: ThemeCommandBarValues,
471481
@@ -497,6 +507,16 @@ pub struct ThemeValues {
497507 pub completion: ThemeCompletionValues,
498508}
499509
510impl ThemeValues {
511 pub fn selected(&self, style: Style, selected: bool) -> Style {
512 if selected {
513 style.patch(self.selected)
514 } else {
515 style
516 }
517 }
518}
519
500520#[derive(Clone, Debug, Default, Deserialize)]
501521struct ThemeMessages {
502522 #[serde(default)]
src/message/mod.rs +6 −4
@@ -1103,10 +1103,6 @@ impl Message {
11031103 fn get_render_style(&self, selected: bool, settings: &ApplicationSettings) -> Style {
11041104 let mut style = self.event.message_style(settings);
11051105
1106 if selected {
1107 style = style.add_modifier(StyleModifier::REVERSED)
1108 }
1109
11101106 if matches!(self.event, MessageEvent::Local(..)) {
11111107 style = style.add_modifier(StyleModifier::ITALIC);
11121108 }
@@ -1116,6 +1112,12 @@ impl Message {
11161112 style = style.fg(color);
11171113 }
11181114
1115 if selected {
1116 // Apply last, so that if the user or theme specified selected colors
1117 // for selected messages then it will get put on top of the user color:
1118 style = style.patch(settings.theme.selected);
1119 }
1120
11191121 return style;
11201122 }
11211123
src/windows/mod.rs +4 −17
@@ -48,15 +48,6 @@ pub mod welcome;
4848const MEMBER_FETCH_DEBOUNCE: Duration = Duration::from_secs(5);
4949const ROOM_PREVIEW_DEBOUNCE: Duration = Duration::from_secs(15);
5050
51#[inline]
52pub fn selected_style(selected: bool, style: Style) -> Style {
53 if selected {
54 style.add_modifier(StyleModifier::REVERSED)
55 } else {
56 style
57 }
58}
59
6051/// Returns the number span with width 4 and the style for name and tags.
6152fn unreads_and_style(
6253 unread: &UnreadInfo,
@@ -1599,7 +1590,7 @@ impl ListItem<IambInfo> for GenericRoomItem {
15991590 let order = store.application.settings.tunables.room_labels.as_slice();
16001591
16011592 let (unreads, name_style, tags_style) = unreads_and_style(&self.unread, &theme.rooms);
1602 let name_style = selected_style(selected, name_style);
1593 let name_style = theme.selected(name_style, selected);
16031594 let tags_style = if selected { name_style } else { tags_style };
16041595
16051596 let (name, labels) = self.name_and_labels(name_style, tags_style, order);
@@ -1678,12 +1669,12 @@ impl ListItem<IambInfo> for MemberItem {
16781669 let theme = &store.application.settings.theme;
16791670
16801671 let (color, name) = store.application.settings.get_user_overrides(self.member.user_id());
1681 let user_style = theme.users.style(user_id.as_str(), color);
1672 let user_style = theme.selected(theme.users.style(user_id.as_str(), color), selected);
16821673 let color = user_style.fg.unwrap_or(Color::Reset);
16831674
16841675 let style = if selected {
16851676 // Ensure the whole item has the same color as `user_style` when it's selected:
1686 theme.default.fg(color).add_modifier(StyleModifier::REVERSED)
1677 theme.default.fg(color).patch(theme.selected)
16871678 } else {
16881679 theme.default
16891680 };
@@ -1818,11 +1809,7 @@ impl ListItem<IambInfo> for PinnedItem {
18181809 ) -> Text<'a> {
18191810 let settings = &store.application.settings;
18201811 let style = store.application.settings.theme.default;
1821 let style = if selected {
1822 style.add_modifier(StyleModifier::REVERSED)
1823 } else {
1824 style
1825 };
1812 let style = store.application.settings.theme.selected(style, selected);
18261813
18271814 let Some(info) = store.application.rooms.get(&self.room_id) else {
18281815 return Text::styled("Unable to load room information", style);
src/windows/room/message.rs +8 −6
@@ -6,7 +6,6 @@ use crate::prelude::*;
66use crate::preview::ImageStatus;
77use crate::util::space;
88use crate::windows::room::chat;
9use crate::windows::selected_style;
109
1110/// State needed for rendering [MessageWidget].
1211pub(crate) struct MessageState {
@@ -472,8 +471,10 @@ impl ListItem<IambInfo> for MessageInfoItem {
472471 viewctx: &ViewportContext<ListCursor>,
473472 store: &'a ProgramStore,
474473 ) -> Text<'a> {
475 let style = store.application.settings.theme.timeline.default;
476 let style = selected_style(selected, style);
474 let theme = &store.application.settings.theme;
475 let style = theme.timeline.default;
476 let style = theme.selected(style, selected);
477
477478 match self {
478479 MessageInfoItem::Header(room_id, user_id, timestamp) => {
479480 let info = store.application.rooms.get(room_id);
@@ -502,9 +503,9 @@ impl ListItem<IambInfo> for MessageInfoItem {
502503 }
503504
504505 let padding = width - user.len() - date.len();
505 let date_style = store.application.settings.theme.timeline.date;
506 let date_style = theme.timeline.date;
506507
507 let line = Span::styled(user, style.patch(user_style)) +
508 let line = Span::styled(user, theme.selected(user_style, selected)) +
508509 Span::raw(space(padding)) +
509510 Span::styled(date, date_style);
510511 line.into()
@@ -531,7 +532,8 @@ impl ListItem<IambInfo> for MessageInfoItem {
531532 MessageInfoItem::User(_, room_id, user_id) => {
532533 let info = store.application.rooms.get(room_id);
533534 let user = store.application.settings.get_user_span_maybe(user_id, info);
534 let user_span = Span::styled(user.content.into_owned(), style.patch(user.style));
535 let user_span =
536 Span::styled(user.content.into_owned(), theme.selected(user.style, selected));
535537
536538 Text::from(Span::raw("- ") + user_span)
537539 },
src/windows/verify.rs +1 −1
@@ -144,7 +144,7 @@ impl ListItem<IambInfo> for VerifyItem {
144144 let mut lines = vec![];
145145 let style = store.application.settings.theme.default;
146146 let bold = style.bold();
147 let selected = super::selected_style(selected, style);
147 let selected = store.application.settings.theme.selected(style, selected);
148148
149149 let mut other_device = None;
150150 let state = match self.request.state() {