Commit a99b1160f6
Unregistered key
Layout: unified · split
config.example.toml +1
| @@ -92,5 +92,6 @@ downloads = "/home/user/Downloads/" | |||
| 92 | [theme] | 92 | [theme] |
| 93 | timeline.state.color = "cyan" | 93 | timeline.state.color = "cyan" |
| 94 | timeline.redacted.color = "245" # light gray | 94 | timeline.redacted.color = "245" # light gray |
| 95 | timeline.redacted.modifiers = ["bold"] # make redacted messages bold | ||
| 95 | # How to use truecolor for terminals that support it: | 96 | # How to use truecolor for terminals that support it: |
| 96 | # rooms.unread.color = "#ff55bb" # pink | 97 | # rooms.unread.color = "#ff55bb" # pink |
docs/iamb.5 +82 −2
| @@ -687,11 +687,56 @@ Configure the background color for text. | |||
| 687 | See the | 687 | See the |
| 688 | .Sx "COLORS" | 688 | .Sx "COLORS" |
| 689 | section for the supported color format. | 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 | .El | 706 | .El |
| 707 | .Pp | ||
| 691 | Within | 708 | Within |
| 692 | .Sy theme , | 709 | .Sy theme , |
| 693 | there are several subsections for specific UI areas: | 710 | there are several subsections for specific UI areas: |
| 694 | .Bl -tag -width Ds | 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 | .It Sy messages | 740 | .It Sy messages |
| 696 | For controlling how the bodies of messages are styled. | 741 | For controlling how the bodies of messages are styled. |
| 697 | UI elements you can set within this subsection are: | 742 | UI elements you can set within this subsection are: |
| @@ -706,6 +751,29 @@ elements in formatted message bodies. | |||
| 706 | Configure the styling for | 751 | Configure the styling for |
| 707 | .Sy "<pre>" | 752 | .Sy "<pre>" |
| 708 | elements in formatted message bodies. | 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 | .El | 777 | .El |
| 710 | .It Sy timeline | 778 | .It Sy timeline |
| 711 | For controlling how other elements within the timeline are styled. | 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 | Configure the how the dates for messages are styled. | 785 | Configure the how the dates for messages are styled. |
| 718 | .It Sy time | 786 | .It Sy time |
| 719 | Configure the how the time a message was sent is styled. | 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 | .It Sy state | 790 | .It Sy state |
| 721 | Configure how the text shown for state events is styled. | 791 | Configure how the text shown for state events is styled. |
| 722 | .It Sy sticker | 792 | .It Sy sticker |
| @@ -731,6 +801,8 @@ Configure how redacted events in the timeline is styled. | |||
| 731 | .It Sy windows | 801 | .It Sy windows |
| 732 | For controlling how the windows are styled. | 802 | For controlling how the windows are styled. |
| 733 | .Bl -tag -width Ds | 803 | .Bl -tag -width Ds |
| 804 | .It Sy default | ||
| 805 | Configure the default style for characters that draw the window border or title. | ||
| 734 | .It Sy border | 806 | .It Sy border |
| 735 | Configure how the border characters are styled. | 807 | Configure how the border characters are styled. |
| 736 | .It Sy border_focused | 808 | .It Sy border_focused |
| @@ -757,11 +829,13 @@ UI elements you can set within this subsection are: | |||
| 757 | .Bl -tag -width Ds | 829 | .Bl -tag -width Ds |
| 758 | .It Sy default | 830 | .It Sy default |
| 759 | Configure the default style for text in room lists. | 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 | .It Sy unread | 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 | .El | 836 | .El |
| 763 | .El | 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 | .Bd -literal -offset indent | 839 | .Bd -literal -offset indent |
| 766 | [theme.messages] | 840 | [theme.messages] |
| 767 | code_block.background = "245" | 841 | code_block.background = "245" |
| @@ -769,6 +843,12 @@ code_block.background = "245" | |||
| 769 | [theme.timeline] | 843 | [theme.timeline] |
| 770 | state.color = "cyan" | 844 | state.color = "cyan" |
| 771 | .Ed | 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 | .Sh "USER OVERRIDES" | 852 | .Sh "USER OVERRIDES" |
| 773 | The | 853 | The |
| 774 | .Sy settings.users | 854 | .Sy settings.users |
src/config/mod.rs +80 −27
| @@ -573,6 +573,7 @@ impl EncryptionValues { | |||
| 573 | &self, | 573 | &self, |
| 574 | location: EncryptionIndicatorLocation, | 574 | location: EncryptionIndicatorLocation, |
| 575 | state: EncryptionState, | 575 | state: EncryptionState, |
| 576 | theme: &ThemeValues, | ||
| 576 | ) -> Option<Span<'static>> { | 577 | ) -> Option<Span<'static>> { |
| 577 | if !self.indicator_location.contains(location) { | 578 | if !self.indicator_location.contains(location) { |
| 578 | return None; | 579 | return None; |
| @@ -590,19 +591,19 @@ impl EncryptionValues { | |||
| 590 | EncryptionState::Encrypted, | 591 | EncryptionState::Encrypted, |
| 591 | ) => { | 592 | ) => { |
| 592 | // Green encrypted icon: | 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 | EncryptionIndicator::Enabled | EncryptionIndicator::OnlyUnencrypted, | 597 | EncryptionIndicator::Enabled | EncryptionIndicator::OnlyUnencrypted, |
| 597 | EncryptionState::NotEncrypted, | 598 | EncryptionState::NotEncrypted, |
| 598 | ) => { | 599 | ) => { |
| 599 | // Red unencrypted icon: | 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 | (_, EncryptionState::Unknown) => { | 604 | (_, EncryptionState::Unknown) => { |
| 604 | // Yellow unknown icon: | 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 | ..Default::default() | 1952 | ..Default::default() |
| 1952 | }; | 1953 | }; |
| 1953 | let enc = enc.values(); | 1954 | let enc = enc.values(); |
| 1955 | let theme = theme::ThemeValues::default(); | ||
| 1954 | 1956 | ||
| 1955 | // Always shows in the title: | 1957 | // Always shows in the title: |
| 1956 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted).is_some()); | ||
| 1957 | assert!( | 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 | .is_some() | 1968 | .is_some() |
| 1960 | ); | 1969 | ); |
| 1961 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Unknown).is_some()); | ||
| 1962 | 1970 | ||
| 1963 | // Doesn't show in the prompt: | 1971 | // Doesn't show in the prompt: |
| 1964 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Encrypted).is_none()); | ||
| 1965 | assert!( | 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 | .is_none() | 1982 | .is_none() |
| 1968 | ); | 1983 | ); |
| 1969 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown).is_none()); | ||
| 1970 | } | 1984 | } |
| 1971 | 1985 | ||
| 1972 | #[test] | 1986 | #[test] |
| @@ -1979,20 +1993,33 @@ mod tests { | |||
| 1979 | ..Default::default() | 1993 | ..Default::default() |
| 1980 | }; | 1994 | }; |
| 1981 | let enc = enc.values(); | 1995 | let enc = enc.values(); |
| 1996 | let theme = theme::ThemeValues::default(); | ||
| 1982 | 1997 | ||
| 1983 | // Never shows in the title or the prompt: | 1998 | // Never shows in the title or the prompt: |
| 1984 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted).is_none()); | ||
| 1985 | assert!( | 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 | .is_none() | 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 | assert!( | 2019 | assert!( |
| 1992 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted) | 2020 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown, &theme) |
| 1993 | .is_none() | 2021 | .is_none() |
| 1994 | ); | 2022 | ); |
| 1995 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown).is_none()); | ||
| 1996 | } | 2023 | } |
| 1997 | 2024 | ||
| 1998 | #[test] | 2025 | #[test] |
| @@ -2005,24 +2032,37 @@ mod tests { | |||
| 2005 | ..Default::default() | 2032 | ..Default::default() |
| 2006 | }; | 2033 | }; |
| 2007 | let enc = enc.values(); | 2034 | let enc = enc.values(); |
| 2035 | let theme = theme::ThemeValues::default(); | ||
| 2008 | 2036 | ||
| 2009 | // Shows in the prompt when encrypted or unknown: | 2037 | // Shows in the prompt when encrypted or unknown: |
| 2010 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Encrypted).is_some()); | 2038 | assert!( |
| 2011 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown).is_some()); | 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 | // But is hidden when unencrypted: | 2047 | // But is hidden when unencrypted: |
| 2014 | assert!( | 2048 | assert!( |
| 2015 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted) | 2049 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted, &theme) |
| 2016 | .is_none() | 2050 | .is_none() |
| 2017 | ); | 2051 | ); |
| 2018 | 2052 | ||
| 2019 | // Doesn't show in the title: | 2053 | // Doesn't show in the title: |
| 2020 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted).is_none()); | ||
| 2021 | assert!( | 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 | .is_none() | 2064 | .is_none() |
| 2024 | ); | 2065 | ); |
| 2025 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Unknown).is_none()); | ||
| 2026 | } | 2066 | } |
| 2027 | #[test] | 2067 | #[test] |
| 2028 | fn test_encryption_indicator_only_unencrypted() { | 2068 | fn test_encryption_indicator_only_unencrypted() { |
| @@ -2034,21 +2074,34 @@ mod tests { | |||
| 2034 | ..Default::default() | 2074 | ..Default::default() |
| 2035 | }; | 2075 | }; |
| 2036 | let enc = enc.values(); | 2076 | let enc = enc.values(); |
| 2077 | let theme = theme::ThemeValues::default(); | ||
| 2037 | 2078 | ||
| 2038 | // Shows in both the prompt and title when unencrypted or unknown: | 2079 | // Shows in both the prompt and title when unencrypted or unknown: |
| 2039 | assert!( | 2080 | assert!( |
| 2040 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted) | 2081 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted, &theme) |
| 2041 | .is_some() | 2082 | .is_some() |
| 2042 | ); | 2083 | ); |
| 2043 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Unknown).is_some()); | ||
| 2044 | assert!( | 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 | .is_some() | 2094 | .is_some() |
| 2047 | ); | 2095 | ); |
| 2048 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown).is_some()); | ||
| 2049 | 2096 | ||
| 2050 | // But is hidden when encrypted: | 2097 | // But is hidden when encrypted: |
| 2051 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted).is_none()); | 2098 | assert!( |
| 2052 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Encrypted).is_none()); | 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 | //! # Logic for parsing styling configuration into [Style]. | 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 | use crate::prelude::*; | 6 | use crate::prelude::*; |
| 5 | 7 | ||
| 6 | pub fn default_theme() -> Theme { | 8 | pub fn default_theme() -> Theme { |
| 7 | Theme { | 9 | Theme { |
| 8 | messages: ThemeMessages { | 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 | ..Default::default() | 41 | ..Default::default() |
| 11 | }, | 42 | }, |
| 12 | ..Default::default() | 43 | ..Default::default() |
| 13 | } | 44 | } |
| 14 | } | 45 | } |
| 15 | 46 | ||
| 16 | #[derive(Clone, Copy, Debug, Default, Deserialize)] | 47 | #[derive(Clone, Copy, Debug)] |
| 17 | pub struct Stylable { | 48 | enum ModifierChange { |
| 18 | pub background: Option<Color>, | 49 | Insert(StyleModifier), |
| 19 | pub color: Option<Color>, | 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 | impl Stylable { | 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 | fn merge(self, other: Self) -> Self { | 153 | fn merge(self, other: Self) -> Self { |
| 24 | Self { | 154 | Self { |
| 25 | background: self.background.or(other.background), | 155 | background: self.background.or(other.background), |
| 26 | color: self.color.or(other.color), | 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 | style = style.fg(fg); | 171 | style = style.fg(fg); |
| 41 | } | 172 | } |
| 42 | 173 | ||
| 174 | for m in styled.modifiers.iter() { | ||
| 175 | m.apply(&mut style); | ||
| 176 | } | ||
| 177 | |||
| 43 | style | 178 | style |
| 44 | } | 179 | } |
| 45 | } | 180 | } |
| 46 | 181 | ||
| 47 | #[derive(Clone, Debug, Default, Deserialize)] | 182 | #[derive(Clone, Debug, Default, Deserialize)] |
| 48 | pub struct Theme { | 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 | /// Configuration specificaly for messages shown within a room's timeline. | 200 | /// Configuration specificaly for messages shown within a room's timeline. |
| 50 | #[serde(default)] | 201 | #[serde(default)] |
| 51 | messages: ThemeMessages, | 202 | messages: ThemeMessages, |
| @@ -70,6 +221,10 @@ pub struct Theme { | |||
| 70 | impl Theme { | 221 | impl Theme { |
| 71 | pub fn merge(self, other: Self) -> Self { | 222 | pub fn merge(self, other: Self) -> Self { |
| 72 | Self { | 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 | messages: self.messages.merge(other.messages), | 228 | messages: self.messages.merge(other.messages), |
| 74 | tabs: self.tabs.merge(other.tabs), | 229 | tabs: self.tabs.merge(other.tabs), |
| 75 | timeline: self.timeline.merge(other.timeline), | 230 | timeline: self.timeline.merge(other.timeline), |
| @@ -79,9 +234,13 @@ impl Theme { | |||
| 79 | } | 234 | } |
| 80 | 235 | ||
| 81 | pub fn values(self) -> ThemeValues { | 236 | pub fn values(self) -> ThemeValues { |
| 82 | let base = Style::default(); | 237 | let base = Style::from(self.default); |
| 83 | 238 | ||
| 84 | ThemeValues { | 239 | ThemeValues { |
| 240 | default: base, | ||
| 241 | cmdbar: self.cmdbar.values(base), | ||
| 242 | encryption: self.encryption.values(base), | ||
| 243 | msgbar: self.msgbar.values(base), | ||
| 85 | messages: self.messages.values(base), | 244 | messages: self.messages.values(base), |
| 86 | timeline: self.timeline.values(base), | 245 | timeline: self.timeline.values(base), |
| 87 | rooms: self.rooms.values(base), | 246 | rooms: self.rooms.values(base), |
| @@ -93,6 +252,18 @@ impl Theme { | |||
| 93 | 252 | ||
| 94 | #[derive(Clone, Debug, Default)] | 253 | #[derive(Clone, Debug, Default)] |
| 95 | pub struct ThemeValues { | 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 | /// Styling specificaly for messages shown within a room's timeline. | 267 | /// Styling specificaly for messages shown within a room's timeline. |
| 97 | pub messages: ThemeMessagesValues, | 268 | pub messages: ThemeMessagesValues, |
| 98 | 269 | ||
| @@ -119,6 +290,18 @@ struct ThemeMessages { | |||
| 119 | 290 | ||
| 120 | #[serde(default)] | 291 | #[serde(default)] |
| 121 | code_block: Stylable, | 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 | impl ThemeMessages { | 307 | impl ThemeMessages { |
| @@ -127,17 +310,30 @@ impl ThemeMessages { | |||
| 127 | default: self.default.merge(other.default), | 310 | default: self.default.merge(other.default), |
| 128 | code: self.code.merge(other.code), | 311 | code: self.code.merge(other.code), |
| 129 | code_block: self.code_block.merge(other.code_block), | 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 | fn values(self, base: Style) -> ThemeMessagesValues { | 320 | fn values(self, base: Style) -> ThemeMessagesValues { |
| 134 | let code = self.code.merge(self.default); | 321 | let default = base.patch(self.default); |
| 135 | let code_block = self.code_block.merge(code); | 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 | ThemeMessagesValues { | 329 | ThemeMessagesValues { |
| 138 | default: base.patch(self.default), | 330 | default, |
| 139 | code: base.patch(code), | 331 | code, |
| 140 | code_block: base.patch(code_block), | 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 | pub default: Style, | 343 | pub default: Style, |
| 148 | pub code: Style, | 344 | pub code: Style, |
| 149 | pub code_block: Style, | 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 | #[derive(Clone, Debug, Default, Deserialize)] | 352 | #[derive(Clone, Debug, Default, Deserialize)] |
| @@ -154,6 +354,10 @@ struct ThemeRooms { | |||
| 154 | #[serde(default)] | 354 | #[serde(default)] |
| 155 | default: Stylable, | 355 | default: Stylable, |
| 156 | 356 | ||
| 357 | #[serde(default)] | ||
| 358 | labels: Stylable, | ||
| 359 | |||
| 360 | // XXX: use different colors for "mention", "notification", "muted room" | ||
| 157 | #[serde(default)] | 361 | #[serde(default)] |
| 158 | unread: Stylable, | 362 | unread: Stylable, |
| 159 | } | 363 | } |
| @@ -162,23 +366,24 @@ impl ThemeRooms { | |||
| 162 | fn merge(self, other: Self) -> Self { | 366 | fn merge(self, other: Self) -> Self { |
| 163 | Self { | 367 | Self { |
| 164 | default: self.default.merge(other.default), | 368 | default: self.default.merge(other.default), |
| 369 | labels: self.labels.merge(other.labels), | ||
| 165 | unread: self.unread.merge(other.unread), | 370 | unread: self.unread.merge(other.unread), |
| 166 | } | 371 | } |
| 167 | } | 372 | } |
| 168 | 373 | ||
| 169 | fn values(self, base: Style) -> ThemeRoomsValues { | 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 { | 379 | ThemeRoomsValues { default, labels, unread } |
| 173 | default: base.patch(self.default), | ||
| 174 | unread: base.patch(unread), | ||
| 175 | } | ||
| 176 | } | 380 | } |
| 177 | } | 381 | } |
| 178 | 382 | ||
| 179 | #[derive(Clone, Debug, Default)] | 383 | #[derive(Clone, Debug, Default)] |
| 180 | pub struct ThemeRoomsValues { | 384 | pub struct ThemeRoomsValues { |
| 181 | pub default: Style, | 385 | pub default: Style, |
| 386 | pub labels: Style, | ||
| 182 | pub unread: Style, | 387 | pub unread: Style, |
| 183 | } | 388 | } |
| 184 | 389 | ||
| @@ -200,12 +405,10 @@ impl ThemeTabs { | |||
| 200 | } | 405 | } |
| 201 | 406 | ||
| 202 | fn values(self, base: Style) -> ThemeTabsValues { | 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 { | 411 | ThemeTabsValues { title, title_focused } |
| 206 | title: base.patch(self.title), | ||
| 207 | title_focused: base.patch(title_focused), | ||
| 208 | } | ||
| 209 | } | 412 | } |
| 210 | } | 413 | } |
| 211 | 414 | ||
| @@ -215,6 +418,99 @@ pub struct ThemeTabsValues { | |||
| 215 | pub title_focused: Style, | 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 | #[derive(Clone, Debug, Default, Deserialize)] | 514 | #[derive(Clone, Debug, Default, Deserialize)] |
| 219 | struct ThemeTimeline { | 515 | struct ThemeTimeline { |
| 220 | #[serde(default)] | 516 | #[serde(default)] |
| @@ -240,6 +536,9 @@ struct ThemeTimeline { | |||
| 240 | 536 | ||
| 241 | #[serde(default)] | 537 | #[serde(default)] |
| 242 | redacted: Stylable, | 538 | redacted: Stylable, |
| 539 | |||
| 540 | #[serde(default)] | ||
| 541 | unread_marker: Stylable, | ||
| 243 | } | 542 | } |
| 244 | 543 | ||
| 245 | impl ThemeTimeline { | 544 | impl ThemeTimeline { |
| @@ -253,21 +552,31 @@ impl ThemeTimeline { | |||
| 253 | poll: self.poll.merge(other.poll), | 552 | poll: self.poll.merge(other.poll), |
| 254 | notice: self.notice.merge(other.notice), | 553 | notice: self.notice.merge(other.notice), |
| 255 | redacted: self.redacted.merge(other.redacted), | 554 | redacted: self.redacted.merge(other.redacted), |
| 555 | unread_marker: self.unread_marker.merge(other.unread_marker), | ||
| 256 | } | 556 | } |
| 257 | } | 557 | } |
| 258 | 558 | ||
| 259 | fn values(self, base: Style) -> ThemeTimelineValues { | 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 | ThemeTimelineValues { | 570 | ThemeTimelineValues { |
| 263 | default: base, | 571 | default, |
| 264 | date: base.patch(self.date), | 572 | date, |
| 265 | time: base.patch(self.time), | 573 | time, |
| 266 | state: base.patch(self.state), | 574 | state, |
| 267 | sticker: base.patch(self.sticker), | 575 | sticker, |
| 268 | poll: base.patch(self.poll), | 576 | poll, |
| 269 | notice: base.patch(self.notice), | 577 | notice, |
| 270 | redacted: base.patch(self.redacted), | 578 | redacted, |
| 579 | unread_marker, | ||
| 271 | } | 580 | } |
| 272 | } | 581 | } |
| 273 | } | 582 | } |
| @@ -282,10 +591,14 @@ pub struct ThemeTimelineValues { | |||
| 282 | pub poll: Style, | 591 | pub poll: Style, |
| 283 | pub notice: Style, | 592 | pub notice: Style, |
| 284 | pub redacted: Style, | 593 | pub redacted: Style, |
| 594 | pub unread_marker: Style, | ||
| 285 | } | 595 | } |
| 286 | 596 | ||
| 287 | #[derive(Clone, Debug, Default, Deserialize)] | 597 | #[derive(Clone, Debug, Default, Deserialize)] |
| 288 | struct ThemeWindows { | 598 | struct ThemeWindows { |
| 599 | #[serde(default)] | ||
| 600 | default: Stylable, | ||
| 601 | |||
| 289 | #[serde(default)] | 602 | #[serde(default)] |
| 290 | border: Stylable, | 603 | border: Stylable, |
| 291 | 604 | ||
| @@ -299,6 +612,7 @@ struct ThemeWindows { | |||
| 299 | impl ThemeWindows { | 612 | impl ThemeWindows { |
| 300 | fn merge(self, other: Self) -> Self { | 613 | fn merge(self, other: Self) -> Self { |
| 301 | Self { | 614 | Self { |
| 615 | default: self.default.merge(other.default), | ||
| 302 | border: self.border.merge(other.border), | 616 | border: self.border.merge(other.border), |
| 303 | border_focused: self.border_focused.merge(other.border_focused), | 617 | border_focused: self.border_focused.merge(other.border_focused), |
| 304 | title: self.title.merge(other.title), | 618 | title: self.title.merge(other.title), |
| @@ -306,17 +620,47 @@ impl ThemeWindows { | |||
| 306 | } | 620 | } |
| 307 | 621 | ||
| 308 | fn values(self, base: Style) -> ThemeWindowsValues { | 622 | fn values(self, base: Style) -> ThemeWindowsValues { |
| 309 | ThemeWindowsValues { | 623 | let default = base.patch(self.default); |
| 310 | border: base.patch(self.border), | 624 | let border = default.patch(self.border); |
| 311 | border_focused: base.patch(self.border_focused.merge(self.border)), | 625 | let border_focused = border.patch(self.border_focused); |
| 312 | title: base.patch(self.title), | 626 | let title = default.patch(self.title); |
| 313 | } | 627 | |
| 628 | ThemeWindowsValues { default, border, border_focused, title } | ||
| 314 | } | 629 | } |
| 315 | } | 630 | } |
| 316 | 631 | ||
| 317 | #[derive(Clone, Debug, Default)] | 632 | #[derive(Clone, Debug, Default)] |
| 318 | pub struct ThemeWindowsValues { | 633 | pub struct ThemeWindowsValues { |
| 634 | pub default: Style, | ||
| 319 | pub border: Style, | 635 | pub border: Style, |
| 320 | pub border_focused: Style, | 636 | pub border_focused: Style, |
| 321 | pub title: Style, | 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 | .show_dialog(dialogstr) | 349 | .show_dialog(dialogstr) |
| 350 | .show_mode(modestr) | 350 | .show_mode(modestr) |
| 351 | .borders(true) | 351 | .borders(true) |
| 352 | .border_style(theme.windows.border.add_modifier(StyleModifier::DIM)) | 352 | .border_style(theme.windows.border) |
| 353 | .border_style_focused( | 353 | .border_style_focused(theme.windows.border_focused) |
| 354 | theme.windows.border_focused.remove_modifier(StyleModifier::DIM), | 354 | .cmdbar_style(theme.cmdbar.default) |
| 355 | ) | 355 | .tab_style(theme.tabs.title) |
| 356 | .tab_style(theme.tabs.title.add_modifier(StyleModifier::DIM)) | 356 | .tab_style_focused(theme.tabs.title_focused) |
| 357 | .tab_style_focused(theme.tabs.title_focused.remove_modifier(StyleModifier::DIM)) | ||
| 358 | .focus(focused); | 357 | .focus(focused); |
| 359 | f.render_stateful_widget(screen, area, sstate); | 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 | /// A processed HTML element that we can render to the terminal. | 275 | /// A processed HTML element that we can render to the terminal. |
| 257 | #[derive(Debug, Clone)] | 276 | #[derive(Debug, Clone)] |
| 258 | pub enum StyleTreeNode { | 277 | pub enum StyleTreeNode { |
| @@ -267,6 +286,7 @@ pub enum StyleTreeNode { | |||
| 267 | Paragraph(Box<StyleTreeNode>), | 286 | Paragraph(Box<StyleTreeNode>), |
| 268 | Pre(Box<StyleTreeNode>), | 287 | Pre(Box<StyleTreeNode>), |
| 269 | Ruler, | 288 | Ruler, |
| 289 | Themed(Box<StyleTreeNode>, ThemeSelector), | ||
| 270 | Style(Box<StyleTreeNode>, Style), | 290 | Style(Box<StyleTreeNode>, Style), |
| 271 | Table(Table), | 291 | Table(Table), |
| 272 | Text(Cow<'static, str>), | 292 | Text(Cow<'static, str>), |
| @@ -301,7 +321,8 @@ impl StyleTreeNode { | |||
| 301 | StyleTreeNode::Header(child, _) | | 321 | StyleTreeNode::Header(child, _) | |
| 302 | StyleTreeNode::Paragraph(child) | | 322 | StyleTreeNode::Paragraph(child) | |
| 303 | StyleTreeNode::Pre(child) | | 323 | StyleTreeNode::Pre(child) | |
| 304 | StyleTreeNode::Style(child, _) => { | 324 | StyleTreeNode::Style(child, _) | |
| 325 | StyleTreeNode::Themed(child, _) => { | ||
| 305 | child.gather_links(urls); | 326 | child.gather_links(urls); |
| 306 | }, | 327 | }, |
| 307 | 328 | ||
| @@ -389,8 +410,8 @@ impl StyleTreeNode { | |||
| 389 | StyleTreeNode::Image(None) => {}, | 410 | StyleTreeNode::Image(None) => {}, |
| 390 | StyleTreeNode::Image(Some(alt)) => { | 411 | StyleTreeNode::Image(Some(alt)) => { |
| 391 | printer.commit(); | 412 | printer.commit(); |
| 392 | printer.push_str("Image Alt: ", Style::default()); | 413 | printer.push_str("Image Alt: ", style); |
| 393 | printer.push_str(alt, Style::default()); | 414 | printer.push_str(alt, style); |
| 394 | printer.commit(); | 415 | printer.commit(); |
| 395 | }, | 416 | }, |
| 396 | StyleTreeNode::List(children, lt) => { | 417 | StyleTreeNode::List(children, lt) => { |
| @@ -470,6 +491,10 @@ impl StyleTreeNode { | |||
| 470 | printer.push_str(s.as_ref(), style); | 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 | StyleTreeNode::Style(child, patch) => child.print(printer, style.patch(*patch)), | 498 | StyleTreeNode::Style(child, patch) => child.print(printer, style.patch(*patch)), |
| 474 | StyleTreeNode::Sequence(children) => { | 499 | StyleTreeNode::Sequence(children) => { |
| 475 | for child in children { | 500 | for child in children { |
| @@ -773,9 +798,7 @@ fn h2t(hdl: &Handle, state: &mut TreeGenState) -> StyleTreeChildren { | |||
| 773 | // Style change | 798 | // Style change |
| 774 | "b" | "strong" => { | 799 | "b" | "strong" => { |
| 775 | let c = c2t(&node.children.borrow(), state); | 800 | let c = c2t(&node.children.borrow(), state); |
| 776 | let s = Style::default().add_modifier(StyleModifier::BOLD); | 801 | StyleTreeNode::Themed(c, ThemeSelector::Strong) |
| 777 | |||
| 778 | StyleTreeNode::Style(c, s) | ||
| 779 | }, | 802 | }, |
| 780 | "font" => { | 803 | "font" => { |
| 781 | let c = c2t(&node.children.borrow(), state); | 804 | let c = c2t(&node.children.borrow(), state); |
| @@ -785,9 +808,7 @@ fn h2t(hdl: &Handle, state: &mut TreeGenState) -> StyleTreeChildren { | |||
| 785 | }, | 808 | }, |
| 786 | "em" | "i" => { | 809 | "em" | "i" => { |
| 787 | let c = c2t(&node.children.borrow(), state); | 810 | let c = c2t(&node.children.borrow(), state); |
| 788 | let s = Style::default().add_modifier(StyleModifier::ITALIC); | 811 | StyleTreeNode::Themed(c, ThemeSelector::Emphasis) |
| 789 | |||
| 790 | StyleTreeNode::Style(c, s) | ||
| 791 | }, | 812 | }, |
| 792 | "span" => { | 813 | "span" => { |
| 793 | let c = c2t(&node.children.borrow(), state); | 814 | let c = c2t(&node.children.borrow(), state); |
| @@ -797,15 +818,11 @@ fn h2t(hdl: &Handle, state: &mut TreeGenState) -> StyleTreeChildren { | |||
| 797 | }, | 818 | }, |
| 798 | "del" | "s" | "strike" => { | 819 | "del" | "s" | "strike" => { |
| 799 | let c = c2t(&node.children.borrow(), state); | 820 | let c = c2t(&node.children.borrow(), state); |
| 800 | let s = Style::default().add_modifier(StyleModifier::CROSSED_OUT); | 821 | StyleTreeNode::Themed(c, ThemeSelector::Strikethrough) |
| 801 | |||
| 802 | StyleTreeNode::Style(c, s) | ||
| 803 | }, | 822 | }, |
| 804 | "u" => { | 823 | "u" => { |
| 805 | let c = c2t(&node.children.borrow(), state); | 824 | let c = c2t(&node.children.borrow(), state); |
| 806 | let s = Style::default().add_modifier(StyleModifier::UNDERLINED); | 825 | StyleTreeNode::Themed(c, ThemeSelector::Underlined) |
| 807 | |||
| 808 | StyleTreeNode::Style(c, s) | ||
| 809 | }, | 826 | }, |
| 810 | 827 | ||
| 811 | // Lists | 828 | // Lists |
src/message/mod.rs +2 −2
| @@ -223,7 +223,7 @@ impl MessageTimeStamp { | |||
| 223 | fn show_date(self, settings: &ApplicationSettings) -> Span<'static> { | 223 | fn show_date(self, settings: &ApplicationSettings) -> Span<'static> { |
| 224 | let time = self.as_datetime().format("%A, %B %d %Y").to_string(); | 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 | /// A compact date and time, for places without a date separator line. | 229 | /// A compact date and time, for places without a date separator line. |
| @@ -745,7 +745,7 @@ impl<'a> MessageFormatter<'a> { | |||
| 745 | #[inline] | 745 | #[inline] |
| 746 | fn push_spans(&mut self, prev_line: Line<'a>, style: Style, text: &mut Text<'a>) { | 746 | fn push_spans(&mut self, prev_line: Line<'a>, style: Style, text: &mut Text<'a>) { |
| 747 | if std::mem::take(&mut self.trackbar) { | 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 | text.lines | 749 | text.lines |
| 750 | .push(Line::from(Span::styled(HORIZONTAL.repeat(self.orig), trackbar_style))); | 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 | SpaceAction, | 89 | SpaceAction, |
| 90 | TimelineAction, | 90 | TimelineAction, |
| 91 | }; | 91 | }; |
| 92 | pub use crate::config::theme::ThemeValues; | ||
| 92 | pub use crate::config::{Aliases, ApplicationSettings}; | 93 | pub use crate::config::{Aliases, ApplicationSettings}; |
| 93 | pub use crate::message::{Message, MessageEvent, MessageKey, MessageTimeStamp, Messages}; | 94 | pub use crate::message::{Message, MessageEvent, MessageKey, MessageTimeStamp, Messages}; |
| 94 | pub use crate::preview::{PreviewKind, PreviewManager}; | 95 | pub use crate::preview::{PreviewKind, PreviewManager}; |
src/windows/mod.rs +59 −68
| @@ -30,16 +30,6 @@ pub mod welcome; | |||
| 30 | 30 | ||
| 31 | const MEMBER_FETCH_DEBOUNCE: Duration = Duration::from_secs(5); | 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 | #[inline] | 33 | #[inline] |
| 44 | pub fn selected_style(selected: bool, style: Style) -> Style { | 34 | pub fn selected_style(selected: bool, style: Style) -> Style { |
| 45 | if selected { | 35 | if selected { |
| @@ -53,31 +43,25 @@ fn name_and_labels<'a>( | |||
| 53 | name: &'a str, | 43 | name: &'a str, |
| 54 | unread: &UnreadInfo, | 44 | unread: &UnreadInfo, |
| 55 | room_membership: MatrixRoomState, | 45 | room_membership: MatrixRoomState, |
| 56 | style: Style, | 46 | name_style: Style, |
| 47 | tags_style: Style, | ||
| 57 | ) -> (Span<'a>, Vec<Vec<Span<'static>>>) { | 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 | let name = Span::styled(name, name_style); | 49 | let name = Span::styled(name, name_style); |
| 66 | 50 | ||
| 67 | let mut labels = vec![]; | 51 | let mut labels = vec![]; |
| 68 | 52 | ||
| 69 | match room_membership { | 53 | match room_membership { |
| 70 | MatrixRoomState::Joined => {}, | 54 | MatrixRoomState::Joined => {}, |
| 71 | MatrixRoomState::Left => labels.push(vec![Span::styled("Left", style)]), | 55 | MatrixRoomState::Left => labels.push(vec![Span::styled("Left", tags_style)]), |
| 72 | MatrixRoomState::Banned => labels.push(vec![Span::styled("Banned", style)]), | 56 | MatrixRoomState::Banned => labels.push(vec![Span::styled("Banned", tags_style)]), |
| 73 | MatrixRoomState::Knocked => labels.push(vec![Span::styled("Knocked", style)]), | 57 | MatrixRoomState::Knocked => labels.push(vec![Span::styled("Knocked", tags_style)]), |
| 74 | MatrixRoomState::Invited => labels.push(vec![Span::styled("Invited", style)]), | 58 | MatrixRoomState::Invited => labels.push(vec![Span::styled("Invited", tags_style)]), |
| 75 | } | 59 | } |
| 76 | 60 | ||
| 77 | if unread.unread_mentions > 0 { | 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 | } else if unread.is_unread() { | 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 | (name, labels) | 67 | (name, labels) |
| @@ -781,25 +765,24 @@ impl Window<IambInfo> for IambWindow { | |||
| 781 | } | 765 | } |
| 782 | 766 | ||
| 783 | fn get_tab_title(&self, store: &mut ProgramStore) -> Line<'_> { | 767 | fn get_tab_title(&self, store: &mut ProgramStore) -> Line<'_> { |
| 784 | let style = Default::default(); | ||
| 785 | match self { | 768 | match self { |
| 786 | IambWindow::DirectList(_) => bold_spans("Direct Messages", style), | 769 | IambWindow::DirectList(_) => Line::from("Direct Messages"), |
| 787 | IambWindow::RoomList(_) => bold_spans("Rooms", style), | 770 | IambWindow::RoomList(_) => Line::from("Rooms"), |
| 788 | IambWindow::SpaceList(_) => bold_spans("Spaces", style), | 771 | IambWindow::SpaceList(_) => Line::from("Spaces"), |
| 789 | IambWindow::VerifyList(_) => bold_spans("Verifications", style), | 772 | IambWindow::VerifyList(_) => Line::from("Verifications"), |
| 790 | IambWindow::Welcome(_) => bold_spans("Welcome to iamb", style), | 773 | IambWindow::Welcome(_) => Line::from("Welcome to iamb"), |
| 791 | IambWindow::ChatList(_) => bold_spans("DMs & Rooms", style), | 774 | IambWindow::ChatList(_) => Line::from("DMs & Rooms"), |
| 792 | IambWindow::UnreadList(_) => bold_spans("Unread Messages", style), | 775 | IambWindow::UnreadList(_) => Line::from("Unread Messages"), |
| 793 | IambWindow::MentionsList(_) => bold_spans("Unread Mentions", style), | 776 | IambWindow::MentionsList(_) => Line::from("Unread Mentions"), |
| 794 | IambWindow::InvitesList(_) => bold_spans("Open Invites", style), | 777 | IambWindow::InvitesList(_) => Line::from("Open Invites"), |
| 795 | 778 | ||
| 796 | IambWindow::Room(w) => w.get_tab_title(store), | 779 | IambWindow::Room(w) => w.get_tab_title(store), |
| 797 | IambWindow::MemberList(state, room_id, _) => { | 780 | IambWindow::MemberList(state, room_id, _) => { |
| 798 | let title = store.application.get_room_title(room_id.as_ref()); | 781 | let title = store.application.get_room_title(room_id.as_ref()); |
| 799 | let n = state.len(); | 782 | let n = state.len(); |
| 800 | let v = vec![ | 783 | let v = vec![ |
| 801 | bold_span("Room Members ", style), | 784 | Span::raw("Room Members "), |
| 802 | Span::styled(format!("({n}): "), style.bold()), | 785 | Span::raw(format!("({n}): ")), |
| 803 | title.into(), | 786 | title.into(), |
| 804 | ]; | 787 | ]; |
| 805 | Line::from(v) | 788 | Line::from(v) |
| @@ -808,9 +791,9 @@ impl Window<IambInfo> for IambWindow { | |||
| 808 | let title = store.application.get_room_title(room_id.as_ref()); | 791 | let title = store.application.get_room_title(room_id.as_ref()); |
| 809 | let n = state.len(); | 792 | let n = state.len(); |
| 810 | let v = vec![ | 793 | let v = vec![ |
| 811 | bold_span("Pinned Messages ", style), | 794 | Span::raw("Pinned Messages "), |
| 812 | Span::styled(format!("({n}): "), style.bold()), | 795 | Span::raw(format!("({n}): ")), |
| 813 | title.into(), | 796 | Span::raw(title), |
| 814 | ]; | 797 | ]; |
| 815 | Line::from(v) | 798 | Line::from(v) |
| 816 | }, | 799 | }, |
| @@ -819,25 +802,27 @@ impl Window<IambInfo> for IambWindow { | |||
| 819 | 802 | ||
| 820 | fn get_win_title(&self, store: &mut ProgramStore) -> Line<'_> { | 803 | fn get_win_title(&self, store: &mut ProgramStore) -> Line<'_> { |
| 821 | let style = store.application.settings.theme.windows.title; | 804 | let style = store.application.settings.theme.windows.title; |
| 805 | let default_style = store.application.settings.theme.windows.default; | ||
| 806 | |||
| 822 | match self { | 807 | match self { |
| 823 | IambWindow::DirectList(_) => bold_spans("Direct Messages", style), | 808 | IambWindow::DirectList(_) => Line::styled("Direct Messages", style), |
| 824 | IambWindow::RoomList(_) => bold_spans("Rooms", style), | 809 | IambWindow::RoomList(_) => Line::styled("Rooms", style), |
| 825 | IambWindow::SpaceList(_) => bold_spans("Spaces", style), | 810 | IambWindow::SpaceList(_) => Line::styled("Spaces", style), |
| 826 | IambWindow::VerifyList(_) => bold_spans("Verifications", style), | 811 | IambWindow::VerifyList(_) => Line::styled("Verifications", style), |
| 827 | IambWindow::Welcome(_) => bold_spans("Welcome to iamb", style), | 812 | IambWindow::Welcome(_) => Line::styled("Welcome to iamb", style), |
| 828 | IambWindow::ChatList(_) => bold_spans("DMs & Rooms", style), | 813 | IambWindow::ChatList(_) => Line::styled("DMs & Rooms", style), |
| 829 | IambWindow::UnreadList(_) => bold_spans("Unread Messages", style), | 814 | IambWindow::UnreadList(_) => Line::styled("Unread Messages", style), |
| 830 | IambWindow::MentionsList(_) => bold_spans("Unread Mentions", style), | 815 | IambWindow::MentionsList(_) => Line::styled("Unread Mentions", style), |
| 831 | IambWindow::InvitesList(_) => bold_spans("Open Invites", style), | 816 | IambWindow::InvitesList(_) => Line::styled("Open Invites", style), |
| 832 | 817 | ||
| 833 | IambWindow::Room(w) => w.get_title(store, style), | 818 | IambWindow::Room(w) => w.get_title(store), |
| 834 | IambWindow::MemberList(state, room_id, _) => { | 819 | IambWindow::MemberList(state, room_id, _) => { |
| 835 | let title = store.application.get_room_title(room_id.as_ref()); | 820 | let title = store.application.get_room_title(room_id.as_ref()); |
| 836 | let n = state.len(); | 821 | let n = state.len(); |
| 837 | let v = vec![ | 822 | let v = vec![ |
| 838 | bold_span("Room Members ", style), | 823 | Span::styled("Room Members ", style), |
| 839 | Span::styled(format!("({n}): "), style.bold()), | 824 | Span::styled(format!("({n}): "), style), |
| 840 | title.into(), | 825 | Span::styled(title, default_style), |
| 841 | ]; | 826 | ]; |
| 842 | Line::from(v) | 827 | Line::from(v) |
| 843 | }, | 828 | }, |
| @@ -845,9 +830,9 @@ impl Window<IambInfo> for IambWindow { | |||
| 845 | let title = store.application.get_room_title(room_id.as_ref()); | 830 | let title = store.application.get_room_title(room_id.as_ref()); |
| 846 | let n = state.len(); | 831 | let n = state.len(); |
| 847 | let v = vec![ | 832 | let v = vec![ |
| 848 | bold_span("Pinned Messages ", style), | 833 | Span::styled("Pinned Messages ", style), |
| 849 | Span::styled(format!("({n}): "), style.bold()), | 834 | Span::styled(format!("({n}): "), style), |
| 850 | title.into(), | 835 | Span::styled(title, default_style), |
| 851 | ]; | 836 | ]; |
| 852 | Line::from(v) | 837 | Line::from(v) |
| 853 | }, | 838 | }, |
| @@ -1086,25 +1071,29 @@ impl ListItem<IambInfo> for GenericRoomItem { | |||
| 1086 | _: &ViewportContext<ListCursor>, | 1071 | _: &ViewportContext<ListCursor>, |
| 1087 | store: &mut ProgramStore, | 1072 | store: &mut ProgramStore, |
| 1088 | ) -> Text<'_> { | 1073 | ) -> Text<'_> { |
| 1089 | let style = if self.unread.is_unread() { | 1074 | let theme = &store.application.settings.theme; |
| 1090 | store.application.settings.theme.rooms.unread | 1075 | |
| 1076 | let name_style = if self.unread.is_unread() { | ||
| 1077 | theme.rooms.unread | ||
| 1091 | } else { | 1078 | } else { |
| 1092 | store.application.settings.theme.rooms.default | 1079 | theme.rooms.default |
| 1093 | }; | 1080 | }; |
| 1094 | 1081 | ||
| 1095 | let style = selected_style(selected, style); | 1082 | let name_style = selected_style(selected, name_style); |
| 1096 | let (name, mut labels) = name_and_labels(&self.name, &self.unread, self.membership, 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 | let mut spans = vec![name]; | 1086 | let mut spans = vec![name]; |
| 1098 | 1087 | ||
| 1099 | if let Some(label) = self.room_type.text() { | 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 | if let Some(tags) = &self.tags { | 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 | Text::from(Line::from(spans)) | 1097 | Text::from(Line::from(spans)) |
| 1109 | } | 1098 | } |
| 1110 | 1099 | ||
| @@ -1166,11 +1155,12 @@ impl ListItem<IambInfo> for MemberItem { | |||
| 1166 | let (color, name) = store.application.settings.get_user_overrides(self.member.user_id()); | 1155 | let (color, name) = store.application.settings.get_user_overrides(self.member.user_id()); |
| 1167 | let color = color.unwrap_or_else(|| super::config::user_color(user_id.as_str())); | 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 | let style = if selected { | 1159 | let style = if selected { |
| 1170 | // Ensure the whole item has the same color when it's selected: | 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 | } else { | 1162 | } else { |
| 1173 | Style::default() | 1163 | style |
| 1174 | }; | 1164 | }; |
| 1175 | let user_style = style.patch(super::config::user_style_from_color(color)); | 1165 | let user_style = style.patch(super::config::user_style_from_color(color)); |
| 1176 | let role_style = style.add_modifier(StyleModifier::BOLD); | 1166 | let role_style = style.add_modifier(StyleModifier::BOLD); |
| @@ -1297,10 +1287,11 @@ impl ListItem<IambInfo> for PinnedItem { | |||
| 1297 | let info = store.application.rooms.get_or_default(self.room_id.clone()); | 1287 | let info = store.application.rooms.get_or_default(self.room_id.clone()); |
| 1298 | let settings = &store.application.settings; | 1288 | let settings = &store.application.settings; |
| 1299 | 1289 | ||
| 1290 | let style = store.application.settings.theme.default; | ||
| 1300 | let style = if selected { | 1291 | let style = if selected { |
| 1301 | Style::default().add_modifier(StyleModifier::REVERSED) | 1292 | style.add_modifier(StyleModifier::REVERSED) |
| 1302 | } else { | 1293 | } else { |
| 1303 | Style::default() | 1294 | style |
| 1304 | }; | 1295 | }; |
| 1305 | 1296 | ||
| 1306 | let Some(msg) = info.get_pinned(&self.event_id) else { | 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 | state.complete_pending_jump(self.store); | 1248 | state.complete_pending_jump(self.store); |
| 1249 | 1249 | ||
| 1250 | let settings = &self.store.application.settings; | 1250 | let settings = &self.store.application.settings; |
| 1251 | let theme = &settings.theme; | ||
| 1251 | 1252 | ||
| 1252 | // Determine whether we have a description to show for the message bar. | 1253 | // Determine whether we have a description to show for the message bar. |
| 1253 | let desc_spans = match (&state.editing, &state.reply_to, state.thread()) { | 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 | let encryption_settings = &settings.tunables.encryption; | 1311 | let encryption_settings = &settings.tunables.encryption; |
| 1311 | let encryption_indicator = encryption_settings | 1312 | let encryption_indicator = encryption_settings.get_indicator( |
| 1312 | .get_indicator(EncryptionIndicatorLocation::PROMPT, state.room().encryption_state()); | 1313 | EncryptionIndicatorLocation::PROMPT, |
| 1314 | state.room().encryption_state(), | ||
| 1315 | theme, | ||
| 1316 | ); | ||
| 1313 | let input_prompt = settings.tunables.input_prompt.as_deref(); | 1317 | let input_prompt = settings.tunables.input_prompt.as_deref(); |
| 1314 | let prompt = match (self.focused, encryption_indicator, input_prompt) { | 1318 | let prompt = match (self.focused, encryption_indicator, input_prompt) { |
| 1315 | // User has both encryption indicator and custom prompt, combine them: | 1319 | // User has both encryption indicator and custom prompt, combine them: |
| @@ -1329,7 +1333,7 @@ impl StatefulWidget for Chat<'_> { | |||
| 1329 | (true, None, None) => Line::from("> "), | 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 | state | 1337 | state |
| 1334 | .tbox | 1338 | .tbox |
| 1335 | .set_ignorecase(self.store.application.settings.tunables.ignorecase); | 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 | let Some(room) = self.room() else { | 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 | let room_id = room.room_id(); | 903 | let room_id = room.room_id(); |
| 900 | let title = store.application.get_room_title(room_id); | 904 | let title = store.application.get_room_title(room_id); |
| 901 | let bold_style = style.add_modifier(StyleModifier::BOLD); | ||
| 902 | let mut spans = vec![]; | 905 | let mut spans = vec![]; |
| 903 | 906 | ||
| 904 | let encryption_settings = &store.application.settings.tunables.encryption; | 907 | let encryption_settings = &store.application.settings.tunables.encryption; |
| 905 | let encryption_indicator = encryption_settings | 908 | let encryption_indicator = encryption_settings.get_indicator( |
| 906 | .get_indicator(EncryptionIndicatorLocation::TITLE, room.encryption_state()); | 909 | EncryptionIndicatorLocation::TITLE, |
| 910 | room.encryption_state(), | ||
| 911 | theme, | ||
| 912 | ); | ||
| 907 | spans.extend(encryption_indicator); | 913 | spans.extend(encryption_indicator); |
| 908 | spans.push(Span::raw(" ")); | 914 | spans.push(Span::styled(" ", default_style)); |
| 909 | 915 | ||
| 910 | if let RoomState::Chat(chat) = self && | 916 | if let RoomState::Chat(chat) = self && |
| 911 | chat.thread().is_some() | 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 | match room.topic() { | 924 | match room.topic() { |
| 919 | Some(desc) if !desc.is_empty() => { | 925 | Some(desc) if !desc.is_empty() => { |
| 920 | spans.push(Span::styled(" (", style)); | 926 | spans.push(Span::styled(" (", default_style)); |
| 921 | spans.push(Span::styled(desc, style)); | 927 | spans.push(Span::styled(desc, default_style)); |
| 922 | spans.push(Span::styled(")", 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 | store: &mut ProgramStore, | 140 | store: &mut ProgramStore, |
| 141 | ) -> Text<'_> { | 141 | ) -> Text<'_> { |
| 142 | let mut lines = vec![]; | 142 | let mut lines = vec![]; |
| 143 | let bold = Style::default().bold(); | 143 | let style = store.application.settings.theme.default; |
| 144 | let selected = super::selected_style(selected, Default::default()); | 144 | let bold = style.bold(); |
| 145 | let selected = super::selected_style(selected, style); | ||
| 145 | 146 | ||
| 146 | let mut other_device = None; | 147 | let mut other_device = None; |
| 147 | let state = match self.request.state() { | 148 | let state = match self.request.state() { |
| @@ -151,7 +152,7 @@ impl ListItem<IambInfo> for VerifyItem { | |||
| 151 | other_device = Some(other_device_data); | 152 | other_device = Some(other_device_data); |
| 152 | 153 | ||
| 153 | if their_methods.contains(&VerificationMethod::SasV1) { | 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 | "requested" | 156 | "requested" |
| 156 | } else { | 157 | } else { |
| 157 | "no methods in common" | 158 | "no methods in common" |
| @@ -164,7 +165,7 @@ impl ListItem<IambInfo> for VerifyItem { | |||
| 164 | other_device = Some(other_device_data); | 165 | other_device = Some(other_device_data); |
| 165 | 166 | ||
| 166 | if their_methods.contains(&VerificationMethod::SasV1) { | 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 | "ready" | 171 | "ready" |
| @@ -177,25 +178,27 @@ impl ListItem<IambInfo> for VerifyItem { | |||
| 177 | SasState::Started { .. } | | 178 | SasState::Started { .. } | |
| 178 | SasState::Accepted { .. } => "starting", | 179 | SasState::Accepted { .. } => "starting", |
| 179 | SasState::KeysExchanged { emojis: Some(emojis), .. } => { | 180 | SasState::KeysExchanged { emojis: Some(emojis), .. } => { |
| 180 | lines.push(Line::from( | 181 | lines.push(Line::styled( |
| 181 | " Both devices should see the following Emoji sequence:".to_string(), | 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 | for line in format_emojis(emojis.emojis).lines() { | 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("")); | 191 | lines.push(Line::styled("", style)); |
| 190 | lines.push(Line::from(" If they don't match, run:")); | 192 | lines.push(Line::styled(" If they don't match, run:", style)); |
| 191 | lines.push(Line::from("")); | 193 | lines.push(Line::styled("", style)); |
| 192 | lines.push(Line::from(Span::styled( | 194 | lines.push(Line::styled( |
| 193 | format!(" :verify mismatch {:?}", self.request.flow_id()), | 195 | format!(" :verify mismatch {:?}", self.request.flow_id()), |
| 194 | bold, | 196 | bold, |
| 195 | ))); | 197 | )); |
| 196 | lines.push(Line::from("")); | 198 | lines.push(Line::styled("", style)); |
| 197 | lines.push(Line::from( | 199 | lines.push(Line::styled( |
| 198 | " If everything looks right, you can confirm with:", | 200 | " If everything looks right, you can confirm with:", |
| 201 | style, | ||
| 199 | )); | 202 | )); |
| 200 | "running" | 203 | "running" |
| 201 | }, | 204 | }, |
| @@ -203,7 +206,8 @@ impl ListItem<IambInfo> for VerifyItem { | |||
| 203 | SasState::Confirmed => "waiting for response", | 206 | SasState::Confirmed => "waiting for response", |
| 204 | SasState::Done { .. } => "done", | 207 | SasState::Done { .. } => "done", |
| 205 | SasState::Cancelled(info) => { | 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 | "cancelled" | 211 | "cancelled" |
| 208 | }, | 212 | }, |
| 209 | } | 213 | } |
| @@ -221,31 +225,39 @@ impl ListItem<IambInfo> for VerifyItem { | |||
| 221 | .map(|line| Line::styled(line.to_owned(), BLACK_ON_WHITE)), | 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.")); | 228 | lines.push(Line::styled( |
| 225 | lines.push(Line::from( | 229 | " Scan this QR code with the other device.", |
| 230 | style, | ||
| 231 | )); | ||
| 232 | lines.push(Line::styled( | ||
| 226 | " To alternativly start interactive verification, run:", | 233 | " To alternativly start interactive verification, run:", |
| 234 | style, | ||
| 227 | )); | 235 | )); |
| 228 | } else { | 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 | "ready" | 243 | "ready" |
| 233 | }, | 244 | }, |
| 234 | QrVerificationState::Scanned => { | 245 | QrVerificationState::Scanned => { |
| 235 | lines.push(Line::from( | 246 | lines.push(Line::styled( |
| 236 | " Check whether the other device shows a successful verification." | 247 | " Check whether the other device shows a successful verification.", |
| 237 | .to_string(), | 248 | style, |
| 238 | )); | 249 | )); |
| 239 | lines.push(Line::from("")); | 250 | lines.push(Line::styled("", style)); |
| 240 | lines.push(Line::from(" If it shows an error, run:")); | 251 | lines.push(Line::styled(" If it shows an error, run:", style)); |
| 241 | lines.push(Line::from("")); | 252 | lines.push(Line::styled("", style)); |
| 242 | lines.push(Line::from(Span::styled( | 253 | lines.push(Line::styled( |
| 243 | format!(" :verify mismatch {:?}", self.request.flow_id()), | 254 | format!(" :verify mismatch {:?}", self.request.flow_id()), |
| 244 | bold, | 255 | bold, |
| 245 | ))); | 256 | )); |
| 246 | lines.push(Line::from("")); | 257 | lines.push(Line::styled("", style)); |
| 247 | lines.push(Line::from( | 258 | lines.push(Line::styled( |
| 248 | " If everything looks right, you can confirm with:", | 259 | " If everything looks right, you can confirm with:", |
| 260 | style, | ||
| 249 | )); | 261 | )); |
| 250 | "running" | 262 | "running" |
| 251 | }, | 263 | }, |
| @@ -258,7 +270,8 @@ impl ListItem<IambInfo> for VerifyItem { | |||
| 258 | }, | 270 | }, |
| 259 | QrVerificationState::Done { .. } => "done", | 271 | QrVerificationState::Done { .. } => "done", |
| 260 | QrVerificationState::Cancelled(info) => { | 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 | "cancelled" | 275 | "cancelled" |
| 263 | }, | 276 | }, |
| 264 | } | 277 | } |
| @@ -266,7 +279,7 @@ impl ListItem<IambInfo> for VerifyItem { | |||
| 266 | VerificationRequestState::Transitioned { .. } => "unsupported method", | 279 | VerificationRequestState::Transitioned { .. } => "unsupported method", |
| 267 | VerificationRequestState::Done => "done", | 280 | VerificationRequestState::Done => "done", |
| 268 | VerificationRequestState::Cancelled(info) => { | 281 | VerificationRequestState::Cancelled(info) => { |
| 269 | lines.push(Line::from(format!(" Cancelled: {}", info.reason()))); | 282 | lines.push(Line::styled(format!(" Cancelled: {}", info.reason()), style)); |
| 270 | "cancelled" | 283 | "cancelled" |
| 271 | }, | 284 | }, |
| 272 | }; | 285 | }; |
| @@ -305,14 +318,14 @@ impl ListItem<IambInfo> for VerifyItem { | |||
| 305 | let cmd = self.to_string(); | 318 | let cmd = self.to_string(); |
| 306 | 319 | ||
| 307 | if !cmd.is_empty() { | 320 | if !cmd.is_empty() { |
| 308 | lines.push(Line::from("")); | 321 | lines.push(Line::styled("", style)); |
| 309 | lines.push(Line::from(vec![Span::from(" "), Span::styled(cmd, bold)])); | 322 | lines.push(Line::from(vec![Span::styled(" ", style), Span::styled(cmd, bold)])); |
| 310 | if self.show_help { | 323 | if self.show_help { |
| 311 | lines.push(Line::from("")); | 324 | lines.push(Line::styled("", style)); |
| 312 | lines.push(Line::from(vec![ | 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 | Span::styled("yy", bold), | 327 | Span::styled("yy", bold), |
| 315 | Span::from(" and then execute it with "), | 328 | Span::styled(" and then execute it with ", style), |
| 316 | Span::styled("@\"", bold), | 329 | Span::styled("@\"", bold), |
| 317 | ])); | 330 | ])); |
| 318 | } | 331 | } |