Commit a99b1160f6
Unregistered key
Layout: unified · split
config.example.toml +1
| @@ -92,5 +92,6 @@ downloads = "/home/user/Downloads/" | ||
| 92 | 92 | [theme] |
| 93 | 93 | timeline.state.color = "cyan" |
| 94 | 94 | timeline.redacted.color = "245" # light gray |
| 95 | timeline.redacted.modifiers = ["bold"] # make redacted messages bold | |
| 95 | 96 | # How to use truecolor for terminals that support it: |
| 96 | 97 | # rooms.unread.color = "#ff55bb" # pink |
docs/iamb.5 +82 −2
| @@ -687,11 +687,56 @@ Configure the background color for text. | ||
| 687 | 687 | See the |
| 688 | 688 | .Sx "COLORS" |
| 689 | 689 | section for the supported color format. |
| 690 | .It Sy modifiers | |
| 691 | An array of strings specifying modifiers to how the text is styled. | |
| 692 | Possible values are | |
| 693 | .Dq Sy "bold" , | |
| 694 | .Dq Sy "crossed-out" , | |
| 695 | .Dq Sy "dim" , | |
| 696 | .Dq Sy "hidden" , | |
| 697 | .Dq Sy "italic" , | |
| 698 | .Dq Sy "rapid-blink" , | |
| 699 | .Dq Sy "reversed" , | |
| 700 | .Dq Sy "slow-blink" , | |
| 701 | and | |
| 702 | .Dq Sy "underlined" . | |
| 703 | Modifier names prefixed with | |
| 704 | .Sy ~ | |
| 705 | will remove the modifier if it was inherited from another default, global config, etc. | |
| 690 | 706 | .El |
| 707 | .Pp | |
| 691 | 708 | Within |
| 692 | 709 | .Sy theme , |
| 693 | 710 | there are several subsections for specific UI areas: |
| 694 | 711 | .Bl -tag -width Ds |
| 712 | .It Sy default | |
| 713 | The base, default style that everything else should inherit. | |
| 714 | .It Sy cmdbar | |
| 715 | For controlling how the text in the command bar is styled. | |
| 716 | .Bl -tag -width Ds | |
| 717 | .It Sy default | |
| 718 | Configure the default styling for the command bar. | |
| 719 | .El | |
| 720 | .It Sy encryption | |
| 721 | For controlling how the encryption indicators are styled. | |
| 722 | UI elements you can set within this subsection are: | |
| 723 | .Bl -tag -width Ds | |
| 724 | .It Sy default | |
| 725 | Configure the default styling for the encryption status indicators. | |
| 726 | .It Sy icon_encrypted | |
| 727 | Configure the styling for the encrypted indicator. | |
| 728 | .It Sy icon_unencrypted | |
| 729 | Configure the styling for the unencrypted indicator. | |
| 730 | .It Sy icon_unknown | |
| 731 | Configure the styling for the unknown encryption status indicator. | |
| 732 | .El | |
| 733 | .It Sy msgbar | |
| 734 | For controlling how the text in the message bar is styled. | |
| 735 | UI elements you can set within this subsection are: | |
| 736 | .Bl -tag -width Ds | |
| 737 | .It Sy default | |
| 738 | Configure the default styling for the message bar. | |
| 739 | .El | |
| 695 | 740 | .It Sy messages |
| 696 | 741 | For controlling how the bodies of messages are styled. |
| 697 | 742 | UI elements you can set within this subsection are: |
| @@ -706,6 +751,29 @@ elements in formatted message bodies. | ||
| 706 | 751 | Configure the styling for |
| 707 | 752 | .Sy "<pre>" |
| 708 | 753 | elements in formatted message bodies. |
| 754 | .It Sy "emphasis" | |
| 755 | Configure the styling for | |
| 756 | .Sy "<em>" | |
| 757 | and | |
| 758 | .Sy "<i>" | |
| 759 | elements in formatted message bodies. | |
| 760 | .It Sy "strikethrough" | |
| 761 | Configure the styling for | |
| 762 | .Sy "<del>" , | |
| 763 | .Sy "<s>" , | |
| 764 | and | |
| 765 | .Sy "<strike>" | |
| 766 | elements in formatted message bodies. | |
| 767 | .It Sy "strong" | |
| 768 | Configure the styling for | |
| 769 | .Sy "<strong>" | |
| 770 | and | |
| 771 | .Sy "<b>" | |
| 772 | elements in formatted message bodies. | |
| 773 | .It Sy "underlined" | |
| 774 | Configure the styling for | |
| 775 | .Sy "<u>" | |
| 776 | elements in formatted message bodies. | |
| 709 | 777 | .El |
| 710 | 778 | .It Sy timeline |
| 711 | 779 | For controlling how other elements within the timeline are styled. |
| @@ -717,6 +785,8 @@ Configure the default styling for text in the timeline. | ||
| 717 | 785 | Configure the how the dates for messages are styled. |
| 718 | 786 | .It Sy time |
| 719 | 787 | Configure the how the time a message was sent is styled. |
| 788 | .It Sy unread_marker | |
| 789 | Configure the style of the bar for marking the start of unread messages. | |
| 720 | 790 | .It Sy state |
| 721 | 791 | Configure how the text shown for state events is styled. |
| 722 | 792 | .It Sy sticker |
| @@ -731,6 +801,8 @@ Configure how redacted events in the timeline is styled. | ||
| 731 | 801 | .It Sy windows |
| 732 | 802 | For controlling how the windows are styled. |
| 733 | 803 | .Bl -tag -width Ds |
| 804 | .It Sy default | |
| 805 | Configure the default style for characters that draw the window border or title. | |
| 734 | 806 | .It Sy border |
| 735 | 807 | Configure how the border characters are styled. |
| 736 | 808 | .It Sy border_focused |
| @@ -757,11 +829,13 @@ UI elements you can set within this subsection are: | ||
| 757 | 829 | .Bl -tag -width Ds |
| 758 | 830 | .It Sy default |
| 759 | 831 | Configure the default style for text in room lists. |
| 832 | .It Sy labels | |
| 833 | Configure the style for the labels following room names in lists. | |
| 760 | 834 | .It Sy unread |
| 761 | Configure the text for unread rooms in lists is styled. | |
| 835 | Configure the style for unread room names in lists. | |
| 762 | 836 | .El |
| 763 | 837 | .El |
| 764 | .Ss Example: Make code blocks a lighter gray background and state events red | |
| 838 | .Ss Example 1: Make code blocks a lighter gray background and state events red | |
| 765 | 839 | .Bd -literal -offset indent |
| 766 | 840 | [theme.messages] |
| 767 | 841 | code_block.background = "245" |
| @@ -769,6 +843,12 @@ code_block.background = "245" | ||
| 769 | 843 | [theme.timeline] |
| 770 | 844 | state.color = "cyan" |
| 771 | 845 | .Ed |
| 846 | .Ss Example 2: Replace default bold style in window and tab titles with italic | |
| 847 | .Bd -literal -offset indent | |
| 848 | [theme] | |
| 849 | tabs.title.modifiers = ["~bold", "italic"] | |
| 850 | windows.title.modifiers = ["~bold", "italic"] | |
| 851 | .Ed | |
| 772 | 852 | .Sh "USER OVERRIDES" |
| 773 | 853 | The |
| 774 | 854 | .Sy settings.users |
src/config/mod.rs +80 −27
| @@ -573,6 +573,7 @@ impl EncryptionValues { | ||
| 573 | 573 | &self, |
| 574 | 574 | location: EncryptionIndicatorLocation, |
| 575 | 575 | state: EncryptionState, |
| 576 | theme: &ThemeValues, | |
| 576 | 577 | ) -> Option<Span<'static>> { |
| 577 | 578 | if !self.indicator_location.contains(location) { |
| 578 | 579 | return None; |
| @@ -590,19 +591,19 @@ impl EncryptionValues { | ||
| 590 | 591 | EncryptionState::Encrypted, |
| 591 | 592 | ) => { |
| 592 | 593 | // Green encrypted icon: |
| 593 | Span::styled(self.icon_encrypted.clone(), Style::new().fg(Color::LightGreen)) | |
| 594 | Span::styled(self.icon_encrypted.clone(), theme.encryption.icon_encrypted) | |
| 594 | 595 | }, |
| 595 | 596 | ( |
| 596 | 597 | EncryptionIndicator::Enabled | EncryptionIndicator::OnlyUnencrypted, |
| 597 | 598 | EncryptionState::NotEncrypted, |
| 598 | 599 | ) => { |
| 599 | 600 | // Red unencrypted icon: |
| 600 | Span::styled(self.icon_unencrypted.clone(), Style::new().fg(Color::Red)) | |
| 601 | Span::styled(self.icon_unencrypted.clone(), theme.encryption.icon_unencrypted) | |
| 601 | 602 | }, |
| 602 | 603 | |
| 603 | 604 | (_, EncryptionState::Unknown) => { |
| 604 | 605 | // Yellow unknown icon: |
| 605 | Span::styled(self.icon_unknown.clone(), Style::new().fg(Color::Yellow)) | |
| 606 | Span::styled(self.icon_unknown.clone(), theme.encryption.icon_unknown) | |
| 606 | 607 | }, |
| 607 | 608 | }; |
| 608 | 609 | |
| @@ -1951,22 +1952,35 @@ mod tests { | ||
| 1951 | 1952 | ..Default::default() |
| 1952 | 1953 | }; |
| 1953 | 1954 | let enc = enc.values(); |
| 1955 | let theme = theme::ThemeValues::default(); | |
| 1954 | 1956 | |
| 1955 | 1957 | // Always shows in the title: |
| 1956 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted).is_some()); | |
| 1957 | 1958 | assert!( |
| 1958 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted) | |
| 1959 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted, &theme) | |
| 1960 | .is_some() | |
| 1961 | ); | |
| 1962 | assert!( | |
| 1963 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted, &theme) | |
| 1964 | .is_some() | |
| 1965 | ); | |
| 1966 | assert!( | |
| 1967 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, Unknown, &theme) | |
| 1959 | 1968 | .is_some() |
| 1960 | 1969 | ); |
| 1961 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Unknown).is_some()); | |
| 1962 | 1970 | |
| 1963 | 1971 | // Doesn't show in the prompt: |
| 1964 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Encrypted).is_none()); | |
| 1965 | 1972 | assert!( |
| 1966 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted) | |
| 1973 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Encrypted, &theme) | |
| 1974 | .is_none() | |
| 1975 | ); | |
| 1976 | assert!( | |
| 1977 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted, &theme) | |
| 1978 | .is_none() | |
| 1979 | ); | |
| 1980 | assert!( | |
| 1981 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown, &theme) | |
| 1967 | 1982 | .is_none() |
| 1968 | 1983 | ); |
| 1969 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown).is_none()); | |
| 1970 | 1984 | } |
| 1971 | 1985 | |
| 1972 | 1986 | #[test] |
| @@ -1979,20 +1993,33 @@ mod tests { | ||
| 1979 | 1993 | ..Default::default() |
| 1980 | 1994 | }; |
| 1981 | 1995 | let enc = enc.values(); |
| 1996 | let theme = theme::ThemeValues::default(); | |
| 1982 | 1997 | |
| 1983 | 1998 | // Never shows in the title or the prompt: |
| 1984 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted).is_none()); | |
| 1985 | 1999 | assert!( |
| 1986 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted) | |
| 2000 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted, &theme) | |
| 2001 | .is_none() | |
| 2002 | ); | |
| 2003 | assert!( | |
| 2004 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted, &theme) | |
| 2005 | .is_none() | |
| 2006 | ); | |
| 2007 | assert!( | |
| 2008 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, Unknown, &theme) | |
| 2009 | .is_none() | |
| 2010 | ); | |
| 2011 | assert!( | |
| 2012 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Encrypted, &theme) | |
| 2013 | .is_none() | |
| 2014 | ); | |
| 2015 | assert!( | |
| 2016 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted, &theme) | |
| 1987 | 2017 | .is_none() |
| 1988 | 2018 | ); |
| 1989 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Unknown).is_none()); | |
| 1990 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Encrypted).is_none()); | |
| 1991 | 2019 | assert!( |
| 1992 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted) | |
| 2020 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown, &theme) | |
| 1993 | 2021 | .is_none() |
| 1994 | 2022 | ); |
| 1995 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown).is_none()); | |
| 1996 | 2023 | } |
| 1997 | 2024 | |
| 1998 | 2025 | #[test] |
| @@ -2005,24 +2032,37 @@ mod tests { | ||
| 2005 | 2032 | ..Default::default() |
| 2006 | 2033 | }; |
| 2007 | 2034 | let enc = enc.values(); |
| 2035 | let theme = theme::ThemeValues::default(); | |
| 2008 | 2036 | |
| 2009 | 2037 | // Shows in the prompt when encrypted or unknown: |
| 2010 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Encrypted).is_some()); | |
| 2011 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown).is_some()); | |
| 2038 | assert!( | |
| 2039 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Encrypted, &theme) | |
| 2040 | .is_some() | |
| 2041 | ); | |
| 2042 | assert!( | |
| 2043 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown, &theme) | |
| 2044 | .is_some() | |
| 2045 | ); | |
| 2012 | 2046 | |
| 2013 | 2047 | // But is hidden when unencrypted: |
| 2014 | 2048 | assert!( |
| 2015 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted) | |
| 2049 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted, &theme) | |
| 2016 | 2050 | .is_none() |
| 2017 | 2051 | ); |
| 2018 | 2052 | |
| 2019 | 2053 | // Doesn't show in the title: |
| 2020 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted).is_none()); | |
| 2021 | 2054 | assert!( |
| 2022 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted) | |
| 2055 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted, &theme) | |
| 2056 | .is_none() | |
| 2057 | ); | |
| 2058 | assert!( | |
| 2059 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted, &theme) | |
| 2060 | .is_none() | |
| 2061 | ); | |
| 2062 | assert!( | |
| 2063 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, Unknown, &theme) | |
| 2023 | 2064 | .is_none() |
| 2024 | 2065 | ); |
| 2025 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Unknown).is_none()); | |
| 2026 | 2066 | } |
| 2027 | 2067 | #[test] |
| 2028 | 2068 | fn test_encryption_indicator_only_unencrypted() { |
| @@ -2034,21 +2074,34 @@ mod tests { | ||
| 2034 | 2074 | ..Default::default() |
| 2035 | 2075 | }; |
| 2036 | 2076 | let enc = enc.values(); |
| 2077 | let theme = theme::ThemeValues::default(); | |
| 2037 | 2078 | |
| 2038 | 2079 | // Shows in both the prompt and title when unencrypted or unknown: |
| 2039 | 2080 | assert!( |
| 2040 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted) | |
| 2081 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted, &theme) | |
| 2041 | 2082 | .is_some() |
| 2042 | 2083 | ); |
| 2043 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Unknown).is_some()); | |
| 2044 | 2084 | assert!( |
| 2045 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted) | |
| 2085 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, Unknown, &theme) | |
| 2086 | .is_some() | |
| 2087 | ); | |
| 2088 | assert!( | |
| 2089 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted, &theme) | |
| 2090 | .is_some() | |
| 2091 | ); | |
| 2092 | assert!( | |
| 2093 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown, &theme) | |
| 2046 | 2094 | .is_some() |
| 2047 | 2095 | ); |
| 2048 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown).is_some()); | |
| 2049 | 2096 | |
| 2050 | 2097 | // But is hidden when encrypted: |
| 2051 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted).is_none()); | |
| 2052 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Encrypted).is_none()); | |
| 2098 | assert!( | |
| 2099 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted, &theme) | |
| 2100 | .is_none() | |
| 2101 | ); | |
| 2102 | assert!( | |
| 2103 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Encrypted, &theme) | |
| 2104 | .is_none() | |
| 2105 | ); | |
| 2053 | 2106 | } |
| 2054 | 2107 | } |
src/config/theme.rs +380 −36
| @@ -1,29 +1,160 @@ | ||
| 1 | 1 | //! # Logic for parsing styling configuration into [Style]. |
| 2 | use serde::Deserialize; | |
| 2 | use serde::de::Error as SerdeError; | |
| 3 | use serde::de::Visitor; | |
| 4 | use serde::{Deserialize, Deserializer}; | |
| 3 | 5 | |
| 4 | 6 | use crate::prelude::*; |
| 5 | 7 | |
| 6 | 8 | pub fn default_theme() -> Theme { |
| 7 | 9 | Theme { |
| 8 | 10 | messages: ThemeMessages { |
| 9 | code: Stylable { color: None, background: Some(Color::Indexed(236)) }, | |
| 11 | code: Stylable::bg(Color::Indexed(236)), | |
| 12 | emphasis: Stylable::with_modifiers(StyleModifier::ITALIC), | |
| 13 | strikethrough: Stylable::with_modifiers(StyleModifier::CROSSED_OUT), | |
| 14 | strong: Stylable::with_modifiers(StyleModifier::BOLD), | |
| 15 | underlined: Stylable::with_modifiers(StyleModifier::UNDERLINED), | |
| 16 | ..Default::default() | |
| 17 | }, | |
| 18 | encryption: ThemeEncryption { | |
| 19 | icon_encrypted: Stylable::fg(Color::LightGreen), | |
| 20 | icon_unencrypted: Stylable::fg(Color::Red), | |
| 21 | icon_unknown: Stylable::fg(Color::Yellow), | |
| 22 | ..Default::default() | |
| 23 | }, | |
| 24 | tabs: ThemeTabs { | |
| 25 | title: Stylable::with_modifiers(StyleModifier::DIM | StyleModifier::BOLD), | |
| 26 | title_focused: Stylable::without_modifiers(StyleModifier::DIM), | |
| 27 | }, | |
| 28 | windows: ThemeWindows { | |
| 29 | border: Stylable::with_modifiers(StyleModifier::DIM), | |
| 30 | border_focused: Stylable::without_modifiers(StyleModifier::DIM), | |
| 31 | title: Stylable::with_modifiers(StyleModifier::BOLD), | |
| 32 | ..Default::default() | |
| 33 | }, | |
| 34 | timeline: ThemeTimeline { | |
| 35 | date: Stylable::with_modifiers(StyleModifier::BOLD), | |
| 36 | unread_marker: Stylable::with_modifiers(StyleModifier::DIM), | |
| 37 | ..Default::default() | |
| 38 | }, | |
| 39 | rooms: ThemeRooms { | |
| 40 | unread: Stylable::with_modifiers(StyleModifier::BOLD), | |
| 10 | 41 | ..Default::default() |
| 11 | 42 | }, |
| 12 | 43 | ..Default::default() |
| 13 | 44 | } |
| 14 | 45 | } |
| 15 | 46 | |
| 16 | #[derive(Clone, Copy, Debug, Default, Deserialize)] | |
| 17 | pub struct Stylable { | |
| 18 | pub background: Option<Color>, | |
| 19 | pub color: Option<Color>, | |
| 47 | #[derive(Clone, Copy, Debug)] | |
| 48 | enum ModifierChange { | |
| 49 | Insert(StyleModifier), | |
| 50 | Remove(StyleModifier), | |
| 51 | } | |
| 52 | ||
| 53 | impl ModifierChange { | |
| 54 | fn apply(self, style: &mut Style) { | |
| 55 | *style = match self { | |
| 56 | Self::Insert(m) => style.add_modifier(m), | |
| 57 | Self::Remove(m) => style.remove_modifier(m), | |
| 58 | }; | |
| 59 | } | |
| 60 | } | |
| 61 | ||
| 62 | struct ModifierChangeVisitor; | |
| 63 | ||
| 64 | impl<'de> Deserialize<'de> for ModifierChange { | |
| 65 | fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | |
| 66 | where | |
| 67 | D: Deserializer<'de>, | |
| 68 | { | |
| 69 | deserializer.deserialize_str(ModifierChangeVisitor) | |
| 70 | } | |
| 71 | } | |
| 72 | ||
| 73 | impl Visitor<'_> for ModifierChangeVisitor { | |
| 74 | type Value = ModifierChange; | |
| 75 | ||
| 76 | fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { | |
| 77 | formatter.write_str("a valid style modifier (e.g. \"bold\" or \"~reversed\")") | |
| 78 | } | |
| 79 | ||
| 80 | fn visit_str<E>(self, value: &str) -> Result<Self::Value, E> | |
| 81 | where | |
| 82 | E: SerdeError, | |
| 83 | { | |
| 84 | let name = value.strip_prefix("~"); | |
| 85 | let remove = name.is_some(); | |
| 86 | ||
| 87 | let modifier = match name.unwrap_or(value) { | |
| 88 | "bold" => StyleModifier::BOLD, | |
| 89 | "crossed-out" => StyleModifier::CROSSED_OUT, | |
| 90 | "dim" => StyleModifier::DIM, | |
| 91 | "hidden" => StyleModifier::HIDDEN, | |
| 92 | "italic" => StyleModifier::ITALIC, | |
| 93 | "rapid-blink" => StyleModifier::RAPID_BLINK, | |
| 94 | "reversed" => StyleModifier::REVERSED, | |
| 95 | "slow-blink" => StyleModifier::SLOW_BLINK, | |
| 96 | "underlined" => StyleModifier::UNDERLINED, | |
| 97 | other => { | |
| 98 | let msg = format!("{other:?} is not a valid style modifier"); | |
| 99 | let err = E::custom(msg); | |
| 100 | return Err(err); | |
| 101 | }, | |
| 102 | }; | |
| 103 | ||
| 104 | if remove { | |
| 105 | Ok(ModifierChange::Remove(modifier)) | |
| 106 | } else { | |
| 107 | Ok(ModifierChange::Insert(modifier)) | |
| 108 | } | |
| 109 | } | |
| 110 | } | |
| 111 | ||
| 112 | #[derive(Clone, Debug, Default, Deserialize)] | |
| 113 | struct Stylable { | |
| 114 | background: Option<Color>, | |
| 115 | color: Option<Color>, | |
| 116 | #[serde(default)] | |
| 117 | modifiers: Vec<ModifierChange>, | |
| 20 | 118 | } |
| 21 | 119 | |
| 22 | 120 | impl Stylable { |
| 121 | fn bg(c: Color) -> Self { | |
| 122 | Self { | |
| 123 | background: Some(c), | |
| 124 | color: None, | |
| 125 | modifiers: vec![], | |
| 126 | } | |
| 127 | } | |
| 128 | ||
| 129 | fn fg(c: Color) -> Self { | |
| 130 | Self { | |
| 131 | background: None, | |
| 132 | color: Some(c), | |
| 133 | modifiers: vec![], | |
| 134 | } | |
| 135 | } | |
| 136 | ||
| 137 | fn with_modifiers(m: StyleModifier) -> Self { | |
| 138 | Self { | |
| 139 | background: None, | |
| 140 | color: None, | |
| 141 | modifiers: vec![ModifierChange::Insert(m)], | |
| 142 | } | |
| 143 | } | |
| 144 | ||
| 145 | fn without_modifiers(m: StyleModifier) -> Self { | |
| 146 | Self { | |
| 147 | background: None, | |
| 148 | color: None, | |
| 149 | modifiers: vec![ModifierChange::Remove(m)], | |
| 150 | } | |
| 151 | } | |
| 152 | ||
| 23 | 153 | fn merge(self, other: Self) -> Self { |
| 24 | 154 | Self { |
| 25 | 155 | background: self.background.or(other.background), |
| 26 | 156 | color: self.color.or(other.color), |
| 157 | modifiers: other.modifiers.iter().chain(&self.modifiers).copied().collect(), | |
| 27 | 158 | } |
| 28 | 159 | } |
| 29 | 160 | } |
| @@ -40,12 +171,32 @@ impl From<Stylable> for Style { | ||
| 40 | 171 | style = style.fg(fg); |
| 41 | 172 | } |
| 42 | 173 | |
| 174 | for m in styled.modifiers.iter() { | |
| 175 | m.apply(&mut style); | |
| 176 | } | |
| 177 | ||
| 43 | 178 | style |
| 44 | 179 | } |
| 45 | 180 | } |
| 46 | 181 | |
| 47 | 182 | #[derive(Clone, Debug, Default, Deserialize)] |
| 48 | 183 | pub struct Theme { |
| 184 | /// Default styling when others aren't specified. | |
| 185 | #[serde(default)] | |
| 186 | default: Stylable, | |
| 187 | ||
| 188 | /// Configuration for styling the command bar. | |
| 189 | #[serde(default)] | |
| 190 | cmdbar: ThemeCommandBar, | |
| 191 | ||
| 192 | /// Configuration for styling the encryption indicators. | |
| 193 | #[serde(default)] | |
| 194 | encryption: ThemeEncryption, | |
| 195 | ||
| 196 | /// Configuration for styling the message bar. | |
| 197 | #[serde(default)] | |
| 198 | msgbar: ThemeMessageBar, | |
| 199 | ||
| 49 | 200 | /// Configuration specificaly for messages shown within a room's timeline. |
| 50 | 201 | #[serde(default)] |
| 51 | 202 | messages: ThemeMessages, |
| @@ -70,6 +221,10 @@ pub struct Theme { | ||
| 70 | 221 | impl Theme { |
| 71 | 222 | pub fn merge(self, other: Self) -> Self { |
| 72 | 223 | Self { |
| 224 | default: self.default.merge(other.default), | |
| 225 | cmdbar: self.cmdbar.merge(other.cmdbar), | |
| 226 | encryption: self.encryption.merge(other.encryption), | |
| 227 | msgbar: self.msgbar.merge(other.msgbar), | |
| 73 | 228 | messages: self.messages.merge(other.messages), |
| 74 | 229 | tabs: self.tabs.merge(other.tabs), |
| 75 | 230 | timeline: self.timeline.merge(other.timeline), |
| @@ -79,9 +234,13 @@ impl Theme { | ||
| 79 | 234 | } |
| 80 | 235 | |
| 81 | 236 | pub fn values(self) -> ThemeValues { |
| 82 | let base = Style::default(); | |
| 237 | let base = Style::from(self.default); | |
| 83 | 238 | |
| 84 | 239 | ThemeValues { |
| 240 | default: base, | |
| 241 | cmdbar: self.cmdbar.values(base), | |
| 242 | encryption: self.encryption.values(base), | |
| 243 | msgbar: self.msgbar.values(base), | |
| 85 | 244 | messages: self.messages.values(base), |
| 86 | 245 | timeline: self.timeline.values(base), |
| 87 | 246 | rooms: self.rooms.values(base), |
| @@ -93,6 +252,18 @@ impl Theme { | ||
| 93 | 252 | |
| 94 | 253 | #[derive(Clone, Debug, Default)] |
| 95 | 254 | pub struct ThemeValues { |
| 255 | /// Styling to use when nothing more specific applies. | |
| 256 | pub default: Style, | |
| 257 | ||
| 258 | /// Styling for the command bar. | |
| 259 | pub cmdbar: ThemeCommandBarValues, | |
| 260 | ||
| 261 | /// Styling for the encryption indicators. | |
| 262 | pub encryption: ThemeEncryptionValues, | |
| 263 | ||
| 264 | /// Styling for the message bar. | |
| 265 | pub msgbar: ThemeMessageBarValues, | |
| 266 | ||
| 96 | 267 | /// Styling specificaly for messages shown within a room's timeline. |
| 97 | 268 | pub messages: ThemeMessagesValues, |
| 98 | 269 | |
| @@ -119,6 +290,18 @@ struct ThemeMessages { | ||
| 119 | 290 | |
| 120 | 291 | #[serde(default)] |
| 121 | 292 | code_block: Stylable, |
| 293 | ||
| 294 | #[serde(default)] | |
| 295 | emphasis: Stylable, | |
| 296 | ||
| 297 | #[serde(default)] | |
| 298 | strikethrough: Stylable, | |
| 299 | ||
| 300 | #[serde(default)] | |
| 301 | strong: Stylable, | |
| 302 | ||
| 303 | #[serde(default)] | |
| 304 | underlined: Stylable, | |
| 122 | 305 | } |
| 123 | 306 | |
| 124 | 307 | impl ThemeMessages { |
| @@ -127,17 +310,30 @@ impl ThemeMessages { | ||
| 127 | 310 | default: self.default.merge(other.default), |
| 128 | 311 | code: self.code.merge(other.code), |
| 129 | 312 | code_block: self.code_block.merge(other.code_block), |
| 313 | emphasis: self.emphasis.merge(other.emphasis), | |
| 314 | strong: self.strong.merge(other.strong), | |
| 315 | strikethrough: self.strikethrough.merge(other.strikethrough), | |
| 316 | underlined: self.underlined.merge(other.underlined), | |
| 130 | 317 | } |
| 131 | 318 | } |
| 132 | 319 | |
| 133 | 320 | fn values(self, base: Style) -> ThemeMessagesValues { |
| 134 | let code = self.code.merge(self.default); | |
| 135 | let code_block = self.code_block.merge(code); | |
| 321 | let default = base.patch(self.default); | |
| 322 | let code = default.patch(self.code); | |
| 323 | let code_block = code.patch(self.code_block); | |
| 324 | let emphasis = default.patch(self.emphasis); | |
| 325 | let strong = default.patch(self.strong); | |
| 326 | let strikethrough = default.patch(self.strikethrough); | |
| 327 | let underlined = default.patch(self.underlined); | |
| 136 | 328 | |
| 137 | 329 | ThemeMessagesValues { |
| 138 | default: base.patch(self.default), | |
| 139 | code: base.patch(code), | |
| 140 | code_block: base.patch(code_block), | |
| 330 | default, | |
| 331 | code, | |
| 332 | code_block, | |
| 333 | emphasis, | |
| 334 | strong, | |
| 335 | strikethrough, | |
| 336 | underlined, | |
| 141 | 337 | } |
| 142 | 338 | } |
| 143 | 339 | } |
| @@ -147,6 +343,10 @@ pub struct ThemeMessagesValues { | ||
| 147 | 343 | pub default: Style, |
| 148 | 344 | pub code: Style, |
| 149 | 345 | pub code_block: Style, |
| 346 | pub emphasis: Style, | |
| 347 | pub strong: Style, | |
| 348 | pub strikethrough: Style, | |
| 349 | pub underlined: Style, | |
| 150 | 350 | } |
| 151 | 351 | |
| 152 | 352 | #[derive(Clone, Debug, Default, Deserialize)] |
| @@ -154,6 +354,10 @@ struct ThemeRooms { | ||
| 154 | 354 | #[serde(default)] |
| 155 | 355 | default: Stylable, |
| 156 | 356 | |
| 357 | #[serde(default)] | |
| 358 | labels: Stylable, | |
| 359 | ||
| 360 | // XXX: use different colors for "mention", "notification", "muted room" | |
| 157 | 361 | #[serde(default)] |
| 158 | 362 | unread: Stylable, |
| 159 | 363 | } |
| @@ -162,23 +366,24 @@ impl ThemeRooms { | ||
| 162 | 366 | fn merge(self, other: Self) -> Self { |
| 163 | 367 | Self { |
| 164 | 368 | default: self.default.merge(other.default), |
| 369 | labels: self.labels.merge(other.labels), | |
| 165 | 370 | unread: self.unread.merge(other.unread), |
| 166 | 371 | } |
| 167 | 372 | } |
| 168 | 373 | |
| 169 | 374 | fn values(self, base: Style) -> ThemeRoomsValues { |
| 170 | let unread = self.unread.merge(self.default); | |
| 375 | let default = base.patch(self.default); | |
| 376 | let labels = default.patch(self.labels); | |
| 377 | let unread = default.patch(self.unread); | |
| 171 | 378 | |
| 172 | ThemeRoomsValues { | |
| 173 | default: base.patch(self.default), | |
| 174 | unread: base.patch(unread), | |
| 175 | } | |
| 379 | ThemeRoomsValues { default, labels, unread } | |
| 176 | 380 | } |
| 177 | 381 | } |
| 178 | 382 | |
| 179 | 383 | #[derive(Clone, Debug, Default)] |
| 180 | 384 | pub struct ThemeRoomsValues { |
| 181 | 385 | pub default: Style, |
| 386 | pub labels: Style, | |
| 182 | 387 | pub unread: Style, |
| 183 | 388 | } |
| 184 | 389 | |
| @@ -200,12 +405,10 @@ impl ThemeTabs { | ||
| 200 | 405 | } |
| 201 | 406 | |
| 202 | 407 | fn values(self, base: Style) -> ThemeTabsValues { |
| 203 | let title_focused = self.title_focused.merge(self.title); | |
| 408 | let title = base.patch(self.title); | |
| 409 | let title_focused = title.patch(self.title_focused); | |
| 204 | 410 | |
| 205 | ThemeTabsValues { | |
| 206 | title: base.patch(self.title), | |
| 207 | title_focused: base.patch(title_focused), | |
| 208 | } | |
| 411 | ThemeTabsValues { title, title_focused } | |
| 209 | 412 | } |
| 210 | 413 | } |
| 211 | 414 | |
| @@ -215,6 +418,99 @@ pub struct ThemeTabsValues { | ||
| 215 | 418 | pub title_focused: Style, |
| 216 | 419 | } |
| 217 | 420 | |
| 421 | #[derive(Clone, Debug, Default, Deserialize)] | |
| 422 | struct ThemeEncryption { | |
| 423 | #[serde(default)] | |
| 424 | default: Stylable, | |
| 425 | ||
| 426 | #[serde(default)] | |
| 427 | icon_encrypted: Stylable, | |
| 428 | ||
| 429 | #[serde(default)] | |
| 430 | icon_unencrypted: Stylable, | |
| 431 | ||
| 432 | #[serde(default)] | |
| 433 | icon_unknown: Stylable, | |
| 434 | } | |
| 435 | ||
| 436 | impl ThemeEncryption { | |
| 437 | fn merge(self, other: Self) -> Self { | |
| 438 | Self { | |
| 439 | default: self.default.merge(other.default), | |
| 440 | icon_encrypted: self.icon_encrypted.merge(other.icon_encrypted), | |
| 441 | icon_unencrypted: self.icon_unencrypted.merge(other.icon_unencrypted), | |
| 442 | icon_unknown: self.icon_unknown.merge(other.icon_unknown), | |
| 443 | } | |
| 444 | } | |
| 445 | ||
| 446 | fn values(self, base: Style) -> ThemeEncryptionValues { | |
| 447 | let default = base.patch(self.default); | |
| 448 | let icon_encrypted = default.patch(self.icon_encrypted); | |
| 449 | let icon_unencrypted = default.patch(self.icon_unencrypted); | |
| 450 | let icon_unknown = default.patch(self.icon_unknown); | |
| 451 | ||
| 452 | ThemeEncryptionValues { | |
| 453 | default, | |
| 454 | icon_encrypted, | |
| 455 | icon_unencrypted, | |
| 456 | icon_unknown, | |
| 457 | } | |
| 458 | } | |
| 459 | } | |
| 460 | ||
| 461 | #[derive(Clone, Debug, Default)] | |
| 462 | pub struct ThemeEncryptionValues { | |
| 463 | pub default: Style, | |
| 464 | pub icon_encrypted: Style, | |
| 465 | pub icon_unencrypted: Style, | |
| 466 | pub icon_unknown: Style, | |
| 467 | } | |
| 468 | ||
| 469 | #[derive(Clone, Debug, Default, Deserialize)] | |
| 470 | struct ThemeMessageBar { | |
| 471 | #[serde(default)] | |
| 472 | default: Stylable, | |
| 473 | } | |
| 474 | ||
| 475 | impl ThemeMessageBar { | |
| 476 | fn merge(self, other: Self) -> Self { | |
| 477 | Self { default: self.default.merge(other.default) } | |
| 478 | } | |
| 479 | ||
| 480 | fn values(self, base: Style) -> ThemeMessageBarValues { | |
| 481 | let default = base.patch(self.default); | |
| 482 | ||
| 483 | ThemeMessageBarValues { default } | |
| 484 | } | |
| 485 | } | |
| 486 | ||
| 487 | #[derive(Clone, Debug, Default)] | |
| 488 | pub struct ThemeMessageBarValues { | |
| 489 | pub default: Style, | |
| 490 | } | |
| 491 | ||
| 492 | #[derive(Clone, Debug, Default, Deserialize)] | |
| 493 | struct ThemeCommandBar { | |
| 494 | #[serde(default)] | |
| 495 | default: Stylable, | |
| 496 | } | |
| 497 | ||
| 498 | impl ThemeCommandBar { | |
| 499 | fn merge(self, other: Self) -> Self { | |
| 500 | Self { default: self.default.merge(other.default) } | |
| 501 | } | |
| 502 | ||
| 503 | fn values(self, base: Style) -> ThemeCommandBarValues { | |
| 504 | let default = base.patch(self.default); | |
| 505 | ThemeCommandBarValues { default } | |
| 506 | } | |
| 507 | } | |
| 508 | ||
| 509 | #[derive(Clone, Debug, Default)] | |
| 510 | pub struct ThemeCommandBarValues { | |
| 511 | pub default: Style, | |
| 512 | } | |
| 513 | ||
| 218 | 514 | #[derive(Clone, Debug, Default, Deserialize)] |
| 219 | 515 | struct ThemeTimeline { |
| 220 | 516 | #[serde(default)] |
| @@ -240,6 +536,9 @@ struct ThemeTimeline { | ||
| 240 | 536 | |
| 241 | 537 | #[serde(default)] |
| 242 | 538 | redacted: Stylable, |
| 539 | ||
| 540 | #[serde(default)] | |
| 541 | unread_marker: Stylable, | |
| 243 | 542 | } |
| 244 | 543 | |
| 245 | 544 | impl ThemeTimeline { |
| @@ -253,21 +552,31 @@ impl ThemeTimeline { | ||
| 253 | 552 | poll: self.poll.merge(other.poll), |
| 254 | 553 | notice: self.notice.merge(other.notice), |
| 255 | 554 | redacted: self.redacted.merge(other.redacted), |
| 555 | unread_marker: self.unread_marker.merge(other.unread_marker), | |
| 256 | 556 | } |
| 257 | 557 | } |
| 258 | 558 | |
| 259 | 559 | fn values(self, base: Style) -> ThemeTimelineValues { |
| 260 | let base = base.patch(self.default); | |
| 560 | let default = base.patch(self.default); | |
| 561 | let date = default.patch(self.date); | |
| 562 | let time = default.patch(self.time); | |
| 563 | let state = default.patch(self.state); | |
| 564 | let sticker = default.patch(self.sticker); | |
| 565 | let poll = default.patch(self.poll); | |
| 566 | let notice = default.patch(self.notice); | |
| 567 | let redacted = default.patch(self.redacted); | |
| 568 | let unread_marker = default.patch(self.unread_marker); | |
| 261 | 569 | |
| 262 | 570 | 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), | |
| 571 | default, | |
| 572 | date, | |
| 573 | time, | |
| 574 | state, | |
| 575 | sticker, | |
| 576 | poll, | |
| 577 | notice, | |
| 578 | redacted, | |
| 579 | unread_marker, | |
| 271 | 580 | } |
| 272 | 581 | } |
| 273 | 582 | } |
| @@ -282,10 +591,14 @@ pub struct ThemeTimelineValues { | ||
| 282 | 591 | pub poll: Style, |
| 283 | 592 | pub notice: Style, |
| 284 | 593 | pub redacted: Style, |
| 594 | pub unread_marker: Style, | |
| 285 | 595 | } |
| 286 | 596 | |
| 287 | 597 | #[derive(Clone, Debug, Default, Deserialize)] |
| 288 | 598 | struct ThemeWindows { |
| 599 | #[serde(default)] | |
| 600 | default: Stylable, | |
| 601 | ||
| 289 | 602 | #[serde(default)] |
| 290 | 603 | border: Stylable, |
| 291 | 604 | |
| @@ -299,6 +612,7 @@ struct ThemeWindows { | ||
| 299 | 612 | impl ThemeWindows { |
| 300 | 613 | fn merge(self, other: Self) -> Self { |
| 301 | 614 | Self { |
| 615 | default: self.default.merge(other.default), | |
| 302 | 616 | border: self.border.merge(other.border), |
| 303 | 617 | border_focused: self.border_focused.merge(other.border_focused), |
| 304 | 618 | title: self.title.merge(other.title), |
| @@ -306,17 +620,47 @@ impl ThemeWindows { | ||
| 306 | 620 | } |
| 307 | 621 | |
| 308 | 622 | 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 | } | |
| 623 | let default = base.patch(self.default); | |
| 624 | let border = default.patch(self.border); | |
| 625 | let border_focused = border.patch(self.border_focused); | |
| 626 | let title = default.patch(self.title); | |
| 627 | ||
| 628 | ThemeWindowsValues { default, border, border_focused, title } | |
| 314 | 629 | } |
| 315 | 630 | } |
| 316 | 631 | |
| 317 | 632 | #[derive(Clone, Debug, Default)] |
| 318 | 633 | pub struct ThemeWindowsValues { |
| 634 | pub default: Style, | |
| 319 | 635 | pub border: Style, |
| 320 | 636 | pub border_focused: Style, |
| 321 | 637 | pub title: Style, |
| 322 | 638 | } |
| 639 | ||
| 640 | #[cfg(test)] | |
| 641 | mod tests { | |
| 642 | use super::*; | |
| 643 | ||
| 644 | #[test] | |
| 645 | fn test_remove_modifier() { | |
| 646 | let res: Theme = serde_json::from_str( | |
| 647 | r#" | |
| 648 | { | |
| 649 | "default": { | |
| 650 | "color":"red", | |
| 651 | "modifiers":["bold"] | |
| 652 | }, | |
| 653 | "windows":{ | |
| 654 | "border": {"color":"green"}, | |
| 655 | "border_focused": {"modifiers":["~bold"]} | |
| 656 | } | |
| 657 | }"#, | |
| 658 | ) | |
| 659 | .unwrap(); | |
| 660 | let values = res.values(); | |
| 661 | assert_eq!(values.default, Style::default().fg(Color::Red).bold()); | |
| 662 | assert_eq!(values.windows.border, Style::default().fg(Color::Green).bold()); | |
| 663 | assert_eq!(values.windows.border_focused, Style::default().fg(Color::Green).not_bold()); | |
| 664 | assert_eq!(values.windows.title, Style::default().fg(Color::Red).bold()); | |
| 665 | } | |
| 666 | } | |
src/main.rs +5 −6
| @@ -349,12 +349,11 @@ impl Application { | ||
| 349 | 349 | .show_dialog(dialogstr) |
| 350 | 350 | .show_mode(modestr) |
| 351 | 351 | .borders(true) |
| 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)) | |
| 352 | .border_style(theme.windows.border) | |
| 353 | .border_style_focused(theme.windows.border_focused) | |
| 354 | .cmdbar_style(theme.cmdbar.default) | |
| 355 | .tab_style(theme.tabs.title) | |
| 356 | .tab_style_focused(theme.tabs.title_focused) | |
| 358 | 357 | .focus(focused); |
| 359 | 358 | f.render_stateful_widget(screen, area, sstate); |
| 360 | 359 | |
src/message/html.rs +32 −15
| @@ -253,6 +253,25 @@ impl Table { | ||
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | #[derive(Debug, Clone)] | |
| 257 | pub enum ThemeSelector { | |
| 258 | Strong, | |
| 259 | Emphasis, | |
| 260 | Strikethrough, | |
| 261 | Underlined, | |
| 262 | } | |
| 263 | ||
| 264 | impl ThemeSelector { | |
| 265 | fn style(&self, settings: &ApplicationSettings) -> Style { | |
| 266 | match self { | |
| 267 | Self::Strong => settings.theme.messages.strong, | |
| 268 | Self::Emphasis => settings.theme.messages.emphasis, | |
| 269 | Self::Strikethrough => settings.theme.messages.strikethrough, | |
| 270 | Self::Underlined => settings.theme.messages.underlined, | |
| 271 | } | |
| 272 | } | |
| 273 | } | |
| 274 | ||
| 256 | 275 | /// A processed HTML element that we can render to the terminal. |
| 257 | 276 | #[derive(Debug, Clone)] |
| 258 | 277 | pub enum StyleTreeNode { |
| @@ -267,6 +286,7 @@ pub enum StyleTreeNode { | ||
| 267 | 286 | Paragraph(Box<StyleTreeNode>), |
| 268 | 287 | Pre(Box<StyleTreeNode>), |
| 269 | 288 | Ruler, |
| 289 | Themed(Box<StyleTreeNode>, ThemeSelector), | |
| 270 | 290 | Style(Box<StyleTreeNode>, Style), |
| 271 | 291 | Table(Table), |
| 272 | 292 | Text(Cow<'static, str>), |
| @@ -301,7 +321,8 @@ impl StyleTreeNode { | ||
| 301 | 321 | StyleTreeNode::Header(child, _) | |
| 302 | 322 | StyleTreeNode::Paragraph(child) | |
| 303 | 323 | StyleTreeNode::Pre(child) | |
| 304 | StyleTreeNode::Style(child, _) => { | |
| 324 | StyleTreeNode::Style(child, _) | | |
| 325 | StyleTreeNode::Themed(child, _) => { | |
| 305 | 326 | child.gather_links(urls); |
| 306 | 327 | }, |
| 307 | 328 | |
| @@ -389,8 +410,8 @@ impl StyleTreeNode { | ||
| 389 | 410 | StyleTreeNode::Image(None) => {}, |
| 390 | 411 | StyleTreeNode::Image(Some(alt)) => { |
| 391 | 412 | printer.commit(); |
| 392 | printer.push_str("Image Alt: ", Style::default()); | |
| 393 | printer.push_str(alt, Style::default()); | |
| 413 | printer.push_str("Image Alt: ", style); | |
| 414 | printer.push_str(alt, style); | |
| 394 | 415 | printer.commit(); |
| 395 | 416 | }, |
| 396 | 417 | StyleTreeNode::List(children, lt) => { |
| @@ -470,6 +491,10 @@ impl StyleTreeNode { | ||
| 470 | 491 | printer.push_str(s.as_ref(), style); |
| 471 | 492 | }, |
| 472 | 493 | |
| 494 | StyleTreeNode::Themed(child, patch) => { | |
| 495 | let patch = patch.style(printer.settings()); | |
| 496 | child.print(printer, style.patch(patch)) | |
| 497 | }, | |
| 473 | 498 | StyleTreeNode::Style(child, patch) => child.print(printer, style.patch(*patch)), |
| 474 | 499 | StyleTreeNode::Sequence(children) => { |
| 475 | 500 | for child in children { |
| @@ -773,9 +798,7 @@ fn h2t(hdl: &Handle, state: &mut TreeGenState) -> StyleTreeChildren { | ||
| 773 | 798 | // Style change |
| 774 | 799 | "b" | "strong" => { |
| 775 | 800 | let c = c2t(&node.children.borrow(), state); |
| 776 | let s = Style::default().add_modifier(StyleModifier::BOLD); | |
| 777 | ||
| 778 | StyleTreeNode::Style(c, s) | |
| 801 | StyleTreeNode::Themed(c, ThemeSelector::Strong) | |
| 779 | 802 | }, |
| 780 | 803 | "font" => { |
| 781 | 804 | let c = c2t(&node.children.borrow(), state); |
| @@ -785,9 +808,7 @@ fn h2t(hdl: &Handle, state: &mut TreeGenState) -> StyleTreeChildren { | ||
| 785 | 808 | }, |
| 786 | 809 | "em" | "i" => { |
| 787 | 810 | let c = c2t(&node.children.borrow(), state); |
| 788 | let s = Style::default().add_modifier(StyleModifier::ITALIC); | |
| 789 | ||
| 790 | StyleTreeNode::Style(c, s) | |
| 811 | StyleTreeNode::Themed(c, ThemeSelector::Emphasis) | |
| 791 | 812 | }, |
| 792 | 813 | "span" => { |
| 793 | 814 | let c = c2t(&node.children.borrow(), state); |
| @@ -797,15 +818,11 @@ fn h2t(hdl: &Handle, state: &mut TreeGenState) -> StyleTreeChildren { | ||
| 797 | 818 | }, |
| 798 | 819 | "del" | "s" | "strike" => { |
| 799 | 820 | let c = c2t(&node.children.borrow(), state); |
| 800 | let s = Style::default().add_modifier(StyleModifier::CROSSED_OUT); | |
| 801 | ||
| 802 | StyleTreeNode::Style(c, s) | |
| 821 | StyleTreeNode::Themed(c, ThemeSelector::Strikethrough) | |
| 803 | 822 | }, |
| 804 | 823 | "u" => { |
| 805 | 824 | let c = c2t(&node.children.borrow(), state); |
| 806 | let s = Style::default().add_modifier(StyleModifier::UNDERLINED); | |
| 807 | ||
| 808 | StyleTreeNode::Style(c, s) | |
| 825 | StyleTreeNode::Themed(c, ThemeSelector::Underlined) | |
| 809 | 826 | }, |
| 810 | 827 | |
| 811 | 828 | // Lists |
src/message/mod.rs +2 −2
| @@ -223,7 +223,7 @@ impl MessageTimeStamp { | ||
| 223 | 223 | fn show_date(self, settings: &ApplicationSettings) -> Span<'static> { |
| 224 | 224 | let time = self.as_datetime().format("%A, %B %d %Y").to_string(); |
| 225 | 225 | |
| 226 | Span::styled(time, settings.theme.timeline.date.add_modifier(StyleModifier::BOLD)) | |
| 226 | Span::styled(time, settings.theme.timeline.date) | |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /// A compact date and time, for places without a date separator line. |
| @@ -745,7 +745,7 @@ impl<'a> MessageFormatter<'a> { | ||
| 745 | 745 | #[inline] |
| 746 | 746 | fn push_spans(&mut self, prev_line: Line<'a>, style: Style, text: &mut Text<'a>) { |
| 747 | 747 | if std::mem::take(&mut self.trackbar) { |
| 748 | let trackbar_style = Style::default().add_modifier(StyleModifier::DIM); | |
| 748 | let trackbar_style = self.settings.theme.timeline.unread_marker; | |
| 749 | 749 | text.lines |
| 750 | 750 | .push(Line::from(Span::styled(HORIZONTAL.repeat(self.orig), trackbar_style))); |
| 751 | 751 | } |
src/prelude.rs +1
| @@ -89,6 +89,7 @@ pub use crate::base::{ | ||
| 89 | 89 | SpaceAction, |
| 90 | 90 | TimelineAction, |
| 91 | 91 | }; |
| 92 | pub use crate::config::theme::ThemeValues; | |
| 92 | 93 | pub use crate::config::{Aliases, ApplicationSettings}; |
| 93 | 94 | pub use crate::message::{Message, MessageEvent, MessageKey, MessageTimeStamp, Messages}; |
| 94 | 95 | pub use crate::preview::{PreviewKind, PreviewManager}; |
src/windows/mod.rs +59 −68
| @@ -30,16 +30,6 @@ pub mod welcome; | ||
| 30 | 30 | |
| 31 | 31 | const MEMBER_FETCH_DEBOUNCE: Duration = Duration::from_secs(5); |
| 32 | 32 | |
| 33 | #[inline] | |
| 34 | fn bold_span(s: &str, style: Style) -> Span<'_> { | |
| 35 | Span::styled(s, style.bold()) | |
| 36 | } | |
| 37 | ||
| 38 | #[inline] | |
| 39 | fn bold_spans(s: &str, style: Style) -> Line<'_> { | |
| 40 | bold_span(s, style).into() | |
| 41 | } | |
| 42 | ||
| 43 | 33 | #[inline] |
| 44 | 34 | pub fn selected_style(selected: bool, style: Style) -> Style { |
| 45 | 35 | if selected { |
| @@ -53,31 +43,25 @@ fn name_and_labels<'a>( | ||
| 53 | 43 | name: &'a str, |
| 54 | 44 | unread: &UnreadInfo, |
| 55 | 45 | room_membership: MatrixRoomState, |
| 56 | style: Style, | |
| 46 | name_style: Style, | |
| 47 | tags_style: Style, | |
| 57 | 48 | ) -> (Span<'a>, Vec<Vec<Span<'static>>>) { |
| 58 | // XXX: use different colors for "mention", "notification", "muted room" | |
| 59 | let name_style = if unread.is_unread() { | |
| 60 | style.add_modifier(StyleModifier::BOLD) | |
| 61 | } else { | |
| 62 | style | |
| 63 | }; | |
| 64 | ||
| 65 | 49 | let name = Span::styled(name, name_style); |
| 66 | 50 | |
| 67 | 51 | let mut labels = vec![]; |
| 68 | 52 | |
| 69 | 53 | match room_membership { |
| 70 | 54 | MatrixRoomState::Joined => {}, |
| 71 | MatrixRoomState::Left => labels.push(vec![Span::styled("Left", style)]), | |
| 72 | MatrixRoomState::Banned => labels.push(vec![Span::styled("Banned", style)]), | |
| 73 | MatrixRoomState::Knocked => labels.push(vec![Span::styled("Knocked", style)]), | |
| 74 | MatrixRoomState::Invited => labels.push(vec![Span::styled("Invited", style)]), | |
| 55 | MatrixRoomState::Left => labels.push(vec![Span::styled("Left", tags_style)]), | |
| 56 | MatrixRoomState::Banned => labels.push(vec![Span::styled("Banned", tags_style)]), | |
| 57 | MatrixRoomState::Knocked => labels.push(vec![Span::styled("Knocked", tags_style)]), | |
| 58 | MatrixRoomState::Invited => labels.push(vec![Span::styled("Invited", tags_style)]), | |
| 75 | 59 | } |
| 76 | 60 | |
| 77 | 61 | if unread.unread_mentions > 0 { |
| 78 | labels.push(vec![Span::styled("Unread Mention", style)]); | |
| 62 | labels.push(vec![Span::styled("Unread Mention", tags_style)]); | |
| 79 | 63 | } else if unread.is_unread() { |
| 80 | labels.push(vec![Span::styled("Unread", style)]); | |
| 64 | labels.push(vec![Span::styled("Unread", tags_style)]); | |
| 81 | 65 | } |
| 82 | 66 | |
| 83 | 67 | (name, labels) |
| @@ -781,25 +765,24 @@ impl Window<IambInfo> for IambWindow { | ||
| 781 | 765 | } |
| 782 | 766 | |
| 783 | 767 | fn get_tab_title(&self, store: &mut ProgramStore) -> Line<'_> { |
| 784 | let style = Default::default(); | |
| 785 | 768 | match self { |
| 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), | |
| 769 | IambWindow::DirectList(_) => Line::from("Direct Messages"), | |
| 770 | IambWindow::RoomList(_) => Line::from("Rooms"), | |
| 771 | IambWindow::SpaceList(_) => Line::from("Spaces"), | |
| 772 | IambWindow::VerifyList(_) => Line::from("Verifications"), | |
| 773 | IambWindow::Welcome(_) => Line::from("Welcome to iamb"), | |
| 774 | IambWindow::ChatList(_) => Line::from("DMs & Rooms"), | |
| 775 | IambWindow::UnreadList(_) => Line::from("Unread Messages"), | |
| 776 | IambWindow::MentionsList(_) => Line::from("Unread Mentions"), | |
| 777 | IambWindow::InvitesList(_) => Line::from("Open Invites"), | |
| 795 | 778 | |
| 796 | 779 | IambWindow::Room(w) => w.get_tab_title(store), |
| 797 | 780 | IambWindow::MemberList(state, room_id, _) => { |
| 798 | 781 | let title = store.application.get_room_title(room_id.as_ref()); |
| 799 | 782 | let n = state.len(); |
| 800 | 783 | let v = vec![ |
| 801 | bold_span("Room Members ", style), | |
| 802 | Span::styled(format!("({n}): "), style.bold()), | |
| 784 | Span::raw("Room Members "), | |
| 785 | Span::raw(format!("({n}): ")), | |
| 803 | 786 | title.into(), |
| 804 | 787 | ]; |
| 805 | 788 | Line::from(v) |
| @@ -808,9 +791,9 @@ impl Window<IambInfo> for IambWindow { | ||
| 808 | 791 | let title = store.application.get_room_title(room_id.as_ref()); |
| 809 | 792 | let n = state.len(); |
| 810 | 793 | let v = vec![ |
| 811 | bold_span("Pinned Messages ", style), | |
| 812 | Span::styled(format!("({n}): "), style.bold()), | |
| 813 | title.into(), | |
| 794 | Span::raw("Pinned Messages "), | |
| 795 | Span::raw(format!("({n}): ")), | |
| 796 | Span::raw(title), | |
| 814 | 797 | ]; |
| 815 | 798 | Line::from(v) |
| 816 | 799 | }, |
| @@ -819,25 +802,27 @@ impl Window<IambInfo> for IambWindow { | ||
| 819 | 802 | |
| 820 | 803 | fn get_win_title(&self, store: &mut ProgramStore) -> Line<'_> { |
| 821 | 804 | let style = store.application.settings.theme.windows.title; |
| 805 | let default_style = store.application.settings.theme.windows.default; | |
| 806 | ||
| 822 | 807 | match self { |
| 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), | |
| 808 | IambWindow::DirectList(_) => Line::styled("Direct Messages", style), | |
| 809 | IambWindow::RoomList(_) => Line::styled("Rooms", style), | |
| 810 | IambWindow::SpaceList(_) => Line::styled("Spaces", style), | |
| 811 | IambWindow::VerifyList(_) => Line::styled("Verifications", style), | |
| 812 | IambWindow::Welcome(_) => Line::styled("Welcome to iamb", style), | |
| 813 | IambWindow::ChatList(_) => Line::styled("DMs & Rooms", style), | |
| 814 | IambWindow::UnreadList(_) => Line::styled("Unread Messages", style), | |
| 815 | IambWindow::MentionsList(_) => Line::styled("Unread Mentions", style), | |
| 816 | IambWindow::InvitesList(_) => Line::styled("Open Invites", style), | |
| 817 | ||
| 818 | IambWindow::Room(w) => w.get_title(store), | |
| 834 | 819 | IambWindow::MemberList(state, room_id, _) => { |
| 835 | 820 | let title = store.application.get_room_title(room_id.as_ref()); |
| 836 | 821 | let n = state.len(); |
| 837 | 822 | let v = vec![ |
| 838 | bold_span("Room Members ", style), | |
| 839 | Span::styled(format!("({n}): "), style.bold()), | |
| 840 | title.into(), | |
| 823 | Span::styled("Room Members ", style), | |
| 824 | Span::styled(format!("({n}): "), style), | |
| 825 | Span::styled(title, default_style), | |
| 841 | 826 | ]; |
| 842 | 827 | Line::from(v) |
| 843 | 828 | }, |
| @@ -845,9 +830,9 @@ impl Window<IambInfo> for IambWindow { | ||
| 845 | 830 | let title = store.application.get_room_title(room_id.as_ref()); |
| 846 | 831 | let n = state.len(); |
| 847 | 832 | let v = vec![ |
| 848 | bold_span("Pinned Messages ", style), | |
| 849 | Span::styled(format!("({n}): "), style.bold()), | |
| 850 | title.into(), | |
| 833 | Span::styled("Pinned Messages ", style), | |
| 834 | Span::styled(format!("({n}): "), style), | |
| 835 | Span::styled(title, default_style), | |
| 851 | 836 | ]; |
| 852 | 837 | Line::from(v) |
| 853 | 838 | }, |
| @@ -1086,25 +1071,29 @@ impl ListItem<IambInfo> for GenericRoomItem { | ||
| 1086 | 1071 | _: &ViewportContext<ListCursor>, |
| 1087 | 1072 | store: &mut ProgramStore, |
| 1088 | 1073 | ) -> Text<'_> { |
| 1089 | let style = if self.unread.is_unread() { | |
| 1090 | store.application.settings.theme.rooms.unread | |
| 1074 | let theme = &store.application.settings.theme; | |
| 1075 | ||
| 1076 | let name_style = if self.unread.is_unread() { | |
| 1077 | theme.rooms.unread | |
| 1091 | 1078 | } else { |
| 1092 | store.application.settings.theme.rooms.default | |
| 1079 | theme.rooms.default | |
| 1093 | 1080 | }; |
| 1094 | 1081 | |
| 1095 | let style = selected_style(selected, style); | |
| 1096 | let (name, mut labels) = name_and_labels(&self.name, &self.unread, self.membership, style); | |
| 1082 | let name_style = selected_style(selected, name_style); | |
| 1083 | let tags_style = selected_style(selected, theme.rooms.labels); | |
| 1084 | let (name, mut labels) = | |
| 1085 | name_and_labels(&self.name, &self.unread, self.membership, name_style, tags_style); | |
| 1097 | 1086 | let mut spans = vec![name]; |
| 1098 | 1087 | |
| 1099 | 1088 | if let Some(label) = self.room_type.text() { |
| 1100 | labels.push(vec![Span::styled(label, style)]); | |
| 1089 | labels.push(vec![Span::styled(label, tags_style)]); | |
| 1101 | 1090 | } |
| 1102 | 1091 | |
| 1103 | 1092 | if let Some(tags) = &self.tags { |
| 1104 | labels.extend(tags.keys().map(|t| tag_to_span(t, style))); | |
| 1093 | labels.extend(tags.keys().map(|t| tag_to_span(t, tags_style))); | |
| 1105 | 1094 | } |
| 1106 | 1095 | |
| 1107 | append_tags(labels, &mut spans, style); | |
| 1096 | append_tags(labels, &mut spans, tags_style); | |
| 1108 | 1097 | Text::from(Line::from(spans)) |
| 1109 | 1098 | } |
| 1110 | 1099 | |
| @@ -1166,11 +1155,12 @@ impl ListItem<IambInfo> for MemberItem { | ||
| 1166 | 1155 | let (color, name) = store.application.settings.get_user_overrides(self.member.user_id()); |
| 1167 | 1156 | let color = color.unwrap_or_else(|| super::config::user_color(user_id.as_str())); |
| 1168 | 1157 | |
| 1158 | let style = store.application.settings.theme.default; | |
| 1169 | 1159 | let style = if selected { |
| 1170 | 1160 | // Ensure the whole item has the same color when it's selected: |
| 1171 | Style::default().fg(color).add_modifier(StyleModifier::REVERSED) | |
| 1161 | style.fg(color).add_modifier(StyleModifier::REVERSED) | |
| 1172 | 1162 | } else { |
| 1173 | Style::default() | |
| 1163 | style | |
| 1174 | 1164 | }; |
| 1175 | 1165 | let user_style = style.patch(super::config::user_style_from_color(color)); |
| 1176 | 1166 | let role_style = style.add_modifier(StyleModifier::BOLD); |
| @@ -1297,10 +1287,11 @@ impl ListItem<IambInfo> for PinnedItem { | ||
| 1297 | 1287 | let info = store.application.rooms.get_or_default(self.room_id.clone()); |
| 1298 | 1288 | let settings = &store.application.settings; |
| 1299 | 1289 | |
| 1290 | let style = store.application.settings.theme.default; | |
| 1300 | 1291 | let style = if selected { |
| 1301 | Style::default().add_modifier(StyleModifier::REVERSED) | |
| 1292 | style.add_modifier(StyleModifier::REVERSED) | |
| 1302 | 1293 | } else { |
| 1303 | Style::default() | |
| 1294 | style | |
| 1304 | 1295 | }; |
| 1305 | 1296 | |
| 1306 | 1297 | let Some(msg) = info.get_pinned(&self.event_id) else { |
src/windows/room/chat.rs +7 −3
| @@ -1248,6 +1248,7 @@ impl StatefulWidget for Chat<'_> { | ||
| 1248 | 1248 | state.complete_pending_jump(self.store); |
| 1249 | 1249 | |
| 1250 | 1250 | let settings = &self.store.application.settings; |
| 1251 | let theme = &settings.theme; | |
| 1251 | 1252 | |
| 1252 | 1253 | // Determine whether we have a description to show for the message bar. |
| 1253 | 1254 | let desc_spans = match (&state.editing, &state.reply_to, state.thread()) { |
| @@ -1308,8 +1309,11 @@ impl StatefulWidget for Chat<'_> { | ||
| 1308 | 1309 | } |
| 1309 | 1310 | |
| 1310 | 1311 | let encryption_settings = &settings.tunables.encryption; |
| 1311 | let encryption_indicator = encryption_settings | |
| 1312 | .get_indicator(EncryptionIndicatorLocation::PROMPT, state.room().encryption_state()); | |
| 1312 | let encryption_indicator = encryption_settings.get_indicator( | |
| 1313 | EncryptionIndicatorLocation::PROMPT, | |
| 1314 | state.room().encryption_state(), | |
| 1315 | theme, | |
| 1316 | ); | |
| 1313 | 1317 | let input_prompt = settings.tunables.input_prompt.as_deref(); |
| 1314 | 1318 | let prompt = match (self.focused, encryption_indicator, input_prompt) { |
| 1315 | 1319 | // User has both encryption indicator and custom prompt, combine them: |
| @@ -1329,7 +1333,7 @@ impl StatefulWidget for Chat<'_> { | ||
| 1329 | 1333 | (true, None, None) => Line::from("> "), |
| 1330 | 1334 | }; |
| 1331 | 1335 | |
| 1332 | let tbox = TextBox::new().prompt(prompt); | |
| 1336 | let tbox = TextBox::new().style(theme.msgbar.default).prompt(prompt); | |
| 1333 | 1337 | state |
| 1334 | 1338 | .tbox |
| 1335 | 1339 | .set_ignorecase(self.store.application.settings.tunables.ignorecase); |
src/windows/room/mod.rs +18 −12
| @@ -891,38 +891,44 @@ impl RoomState { | ||
| 891 | 891 | } |
| 892 | 892 | } |
| 893 | 893 | |
| 894 | pub fn get_title(&self, store: &mut ProgramStore, style: Style) -> Line<'_> { | |
| 894 | pub fn get_title(&self, store: &mut ProgramStore) -> Line<'_> { | |
| 895 | let theme = &store.application.settings.theme; | |
| 896 | let default_style = theme.windows.default; | |
| 897 | let title_style = theme.windows.title; | |
| 898 | ||
| 895 | 899 | let Some(room) = self.room() else { |
| 896 | return Line::from("Unjoined Room"); | |
| 900 | return Line::styled("Unjoined Room", title_style); | |
| 897 | 901 | }; |
| 898 | 902 | |
| 899 | 903 | let room_id = room.room_id(); |
| 900 | 904 | let title = store.application.get_room_title(room_id); |
| 901 | let bold_style = style.add_modifier(StyleModifier::BOLD); | |
| 902 | 905 | let mut spans = vec![]; |
| 903 | 906 | |
| 904 | 907 | let encryption_settings = &store.application.settings.tunables.encryption; |
| 905 | let encryption_indicator = encryption_settings | |
| 906 | .get_indicator(EncryptionIndicatorLocation::TITLE, room.encryption_state()); | |
| 908 | let encryption_indicator = encryption_settings.get_indicator( | |
| 909 | EncryptionIndicatorLocation::TITLE, | |
| 910 | room.encryption_state(), | |
| 911 | theme, | |
| 912 | ); | |
| 907 | 913 | spans.extend(encryption_indicator); |
| 908 | spans.push(Span::raw(" ")); | |
| 914 | spans.push(Span::styled(" ", default_style)); | |
| 909 | 915 | |
| 910 | 916 | if let RoomState::Chat(chat) = self && |
| 911 | 917 | chat.thread().is_some() |
| 912 | 918 | { |
| 913 | spans.push(Span::styled("Thread in ", style)); | |
| 919 | spans.push(Span::styled("Thread in ", default_style)); | |
| 914 | 920 | } |
| 915 | 921 | |
| 916 | spans.push(Span::styled(title, bold_style)); | |
| 922 | spans.push(Span::styled(title, title_style)); | |
| 917 | 923 | |
| 918 | 924 | match room.topic() { |
| 919 | 925 | Some(desc) if !desc.is_empty() => { |
| 920 | spans.push(Span::styled(" (", style)); | |
| 921 | spans.push(Span::styled(desc, style)); | |
| 922 | spans.push(Span::styled(")", style)); | |
| 926 | spans.push(Span::styled(" (", default_style)); | |
| 927 | spans.push(Span::styled(desc, default_style)); | |
| 928 | spans.push(Span::styled(")", default_style)); | |
| 923 | 929 | }, |
| 924 | 930 | _ => { |
| 925 | spans.push(" ".into()); | |
| 931 | spans.push(Span::styled(" ", default_style)); | |
| 926 | 932 | }, |
| 927 | 933 | } |
| 928 | 934 | |
src/windows/verify.rs +49 −36
| @@ -140,8 +140,9 @@ impl ListItem<IambInfo> for VerifyItem { | ||
| 140 | 140 | store: &mut ProgramStore, |
| 141 | 141 | ) -> Text<'_> { |
| 142 | 142 | let mut lines = vec![]; |
| 143 | let bold = Style::default().bold(); | |
| 144 | let selected = super::selected_style(selected, Default::default()); | |
| 143 | let style = store.application.settings.theme.default; | |
| 144 | let bold = style.bold(); | |
| 145 | let selected = super::selected_style(selected, style); | |
| 145 | 146 | |
| 146 | 147 | let mut other_device = None; |
| 147 | 148 | let state = match self.request.state() { |
| @@ -151,7 +152,7 @@ impl ListItem<IambInfo> for VerifyItem { | ||
| 151 | 152 | other_device = Some(other_device_data); |
| 152 | 153 | |
| 153 | 154 | if their_methods.contains(&VerificationMethod::SasV1) { |
| 154 | lines.push(Line::from(" To accept this request, run:")); | |
| 155 | lines.push(Line::styled(" To accept this request, run:", style)); | |
| 155 | 156 | "requested" |
| 156 | 157 | } else { |
| 157 | 158 | "no methods in common" |
| @@ -164,7 +165,7 @@ impl ListItem<IambInfo> for VerifyItem { | ||
| 164 | 165 | other_device = Some(other_device_data); |
| 165 | 166 | |
| 166 | 167 | if their_methods.contains(&VerificationMethod::SasV1) { |
| 167 | lines.push(Line::from(" To start interactive verification, run:")); | |
| 168 | lines.push(Line::styled(" To start interactive verification, run:", style)); | |
| 168 | 169 | } |
| 169 | 170 | |
| 170 | 171 | "ready" |
| @@ -177,25 +178,27 @@ impl ListItem<IambInfo> for VerifyItem { | ||
| 177 | 178 | SasState::Started { .. } | |
| 178 | 179 | SasState::Accepted { .. } => "starting", |
| 179 | 180 | SasState::KeysExchanged { emojis: Some(emojis), .. } => { |
| 180 | lines.push(Line::from( | |
| 181 | " Both devices should see the following Emoji sequence:".to_string(), | |
| 181 | lines.push(Line::styled( | |
| 182 | " Both devices should see the following Emoji sequence:", | |
| 183 | style, | |
| 182 | 184 | )); |
| 183 | lines.push(Line::from("")); | |
| 185 | lines.push(Line::styled("", style)); | |
| 184 | 186 | |
| 185 | 187 | for line in format_emojis(emojis.emojis).lines() { |
| 186 | lines.push(Line::from(format!(" {line}"))); | |
| 188 | lines.push(Line::styled(format!(" {line}"), style)); | |
| 187 | 189 | } |
| 188 | 190 | |
| 189 | lines.push(Line::from("")); | |
| 190 | lines.push(Line::from(" If they don't match, run:")); | |
| 191 | lines.push(Line::from("")); | |
| 192 | lines.push(Line::from(Span::styled( | |
| 191 | lines.push(Line::styled("", style)); | |
| 192 | lines.push(Line::styled(" If they don't match, run:", style)); | |
| 193 | lines.push(Line::styled("", style)); | |
| 194 | lines.push(Line::styled( | |
| 193 | 195 | format!(" :verify mismatch {:?}", self.request.flow_id()), |
| 194 | 196 | bold, |
| 195 | ))); | |
| 196 | lines.push(Line::from("")); | |
| 197 | lines.push(Line::from( | |
| 197 | )); | |
| 198 | lines.push(Line::styled("", style)); | |
| 199 | lines.push(Line::styled( | |
| 198 | 200 | " If everything looks right, you can confirm with:", |
| 201 | style, | |
| 199 | 202 | )); |
| 200 | 203 | "running" |
| 201 | 204 | }, |
| @@ -203,7 +206,8 @@ impl ListItem<IambInfo> for VerifyItem { | ||
| 203 | 206 | SasState::Confirmed => "waiting for response", |
| 204 | 207 | SasState::Done { .. } => "done", |
| 205 | 208 | SasState::Cancelled(info) => { |
| 206 | lines.push(Line::from(format!(" Cancelled: {}", info.reason()))); | |
| 209 | lines | |
| 210 | .push(Line::styled(format!(" Cancelled: {}", info.reason()), style)); | |
| 207 | 211 | "cancelled" |
| 208 | 212 | }, |
| 209 | 213 | } |
| @@ -221,31 +225,39 @@ impl ListItem<IambInfo> for VerifyItem { | ||
| 221 | 225 | .map(|line| Line::styled(line.to_owned(), BLACK_ON_WHITE)), |
| 222 | 226 | ); |
| 223 | 227 | |
| 224 | lines.push(Line::from(" Scan this QR code with the other device.")); | |
| 225 | lines.push(Line::from( | |
| 228 | lines.push(Line::styled( | |
| 229 | " Scan this QR code with the other device.", | |
| 230 | style, | |
| 231 | )); | |
| 232 | lines.push(Line::styled( | |
| 226 | 233 | " To alternativly start interactive verification, run:", |
| 234 | style, | |
| 227 | 235 | )); |
| 228 | 236 | } else { |
| 229 | lines.push(Line::from(" To start interactive verification, run:")); | |
| 237 | lines.push(Line::styled( | |
| 238 | " To start interactive verification, run:", | |
| 239 | style, | |
| 240 | )); | |
| 230 | 241 | } |
| 231 | 242 | |
| 232 | 243 | "ready" |
| 233 | 244 | }, |
| 234 | 245 | QrVerificationState::Scanned => { |
| 235 | lines.push(Line::from( | |
| 236 | " Check whether the other device shows a successful verification." | |
| 237 | .to_string(), | |
| 246 | lines.push(Line::styled( | |
| 247 | " Check whether the other device shows a successful verification.", | |
| 248 | style, | |
| 238 | 249 | )); |
| 239 | lines.push(Line::from("")); | |
| 240 | lines.push(Line::from(" If it shows an error, run:")); | |
| 241 | lines.push(Line::from("")); | |
| 242 | lines.push(Line::from(Span::styled( | |
| 250 | lines.push(Line::styled("", style)); | |
| 251 | lines.push(Line::styled(" If it shows an error, run:", style)); | |
| 252 | lines.push(Line::styled("", style)); | |
| 253 | lines.push(Line::styled( | |
| 243 | 254 | format!(" :verify mismatch {:?}", self.request.flow_id()), |
| 244 | 255 | bold, |
| 245 | ))); | |
| 246 | lines.push(Line::from("")); | |
| 247 | lines.push(Line::from( | |
| 256 | )); | |
| 257 | lines.push(Line::styled("", style)); | |
| 258 | lines.push(Line::styled( | |
| 248 | 259 | " If everything looks right, you can confirm with:", |
| 260 | style, | |
| 249 | 261 | )); |
| 250 | 262 | "running" |
| 251 | 263 | }, |
| @@ -258,7 +270,8 @@ impl ListItem<IambInfo> for VerifyItem { | ||
| 258 | 270 | }, |
| 259 | 271 | QrVerificationState::Done { .. } => "done", |
| 260 | 272 | QrVerificationState::Cancelled(info) => { |
| 261 | lines.push(Line::from(format!(" Cancelled: {}", info.reason()))); | |
| 273 | lines | |
| 274 | .push(Line::styled(format!(" Cancelled: {}", info.reason()), style)); | |
| 262 | 275 | "cancelled" |
| 263 | 276 | }, |
| 264 | 277 | } |
| @@ -266,7 +279,7 @@ impl ListItem<IambInfo> for VerifyItem { | ||
| 266 | 279 | VerificationRequestState::Transitioned { .. } => "unsupported method", |
| 267 | 280 | VerificationRequestState::Done => "done", |
| 268 | 281 | VerificationRequestState::Cancelled(info) => { |
| 269 | lines.push(Line::from(format!(" Cancelled: {}", info.reason()))); | |
| 282 | lines.push(Line::styled(format!(" Cancelled: {}", info.reason()), style)); | |
| 270 | 283 | "cancelled" |
| 271 | 284 | }, |
| 272 | 285 | }; |
| @@ -305,14 +318,14 @@ impl ListItem<IambInfo> for VerifyItem { | ||
| 305 | 318 | let cmd = self.to_string(); |
| 306 | 319 | |
| 307 | 320 | if !cmd.is_empty() { |
| 308 | lines.push(Line::from("")); | |
| 309 | lines.push(Line::from(vec![Span::from(" "), Span::styled(cmd, bold)])); | |
| 321 | lines.push(Line::styled("", style)); | |
| 322 | lines.push(Line::from(vec![Span::styled(" ", style), Span::styled(cmd, bold)])); | |
| 310 | 323 | if self.show_help { |
| 311 | lines.push(Line::from("")); | |
| 324 | lines.push(Line::styled("", style)); | |
| 312 | 325 | lines.push(Line::from(vec![ |
| 313 | Span::from("You can copy the above command with "), | |
| 326 | Span::styled("You can copy the above command with ", style), | |
| 314 | 327 | Span::styled("yy", bold), |
| 315 | Span::from(" and then execute it with "), | |
| 328 | Span::styled(" and then execute it with ", style), | |
| 316 | 329 | Span::styled("@\"", bold), |
| 317 | 330 | ])); |
| 318 | 331 | } |