| @@ -49,9 +49,13 @@ const DEFAULT_ROOM_SORT: [SortColumn<SortFieldRoom>; 5] = [ |
| 49 | 49 | ]; |
| 50 | 50 | |
| 51 | 51 | const DEFAULT_ENABLE_TITLE: bool = true; |
| 52 | | const DEFAULT_ENC_INDICATOR_LOC: EncryptionIndicatorLocation = EncryptionIndicatorLocation::PROMPT; |
| 53 | 52 | const DEFAULT_REQ_TIMEOUT: u64 = 120; |
| 54 | 53 | |
| 54 | const DEFAULT_ENC_INDICATOR_LOC: EncryptionIndicatorLocation = EncryptionIndicatorLocation::PROMPT; |
| 55 | const DEFAULT_ICON_ENC: Cow<'static, str> = Cow::Borrowed("[E] "); |
| 56 | const DEFAULT_ICON_UNENC: Cow<'static, str> = Cow::Borrowed("[U] "); |
| 57 | const DEFAULT_ICON_UNKNOWN: Cow<'static, str> = Cow::Borrowed("[?] "); |
| 58 | |
| 55 | 59 | const DEFAULT_LOG_LEVEL: &str = if cfg!(feature = "max_level_error") { |
| 56 | 60 | "error" |
| 57 | 61 | } else { |
| @@ -558,6 +562,9 @@ impl Visitor<'_> for NotifyViaVisitor { |
| 558 | 562 | pub struct Encryption { |
| 559 | 563 | indicator: Option<EncryptionIndicator>, |
| 560 | 564 | indicator_location: Option<EncryptionIndicatorLocation>, |
| 565 | icon_encrypted: Option<String>, |
| 566 | icon_unencrypted: Option<String>, |
| 567 | icon_unknown: Option<String>, |
| 561 | 568 | } |
| 562 | 569 | |
| 563 | 570 | impl Encryption { |
| @@ -565,6 +572,9 @@ impl Encryption { |
| 565 | 572 | Encryption { |
| 566 | 573 | indicator: profile.indicator.or(global.indicator), |
| 567 | 574 | indicator_location: profile.indicator_location.or(global.indicator_location), |
| 575 | icon_encrypted: profile.icon_encrypted.or(global.icon_encrypted), |
| 576 | icon_unencrypted: profile.icon_unencrypted.or(global.icon_unencrypted), |
| 577 | icon_unknown: profile.icon_unknown.or(global.icon_unknown), |
| 568 | 578 | } |
| 569 | 579 | } |
| 570 | 580 | |
| @@ -572,6 +582,9 @@ impl Encryption { |
| 572 | 582 | EncryptionValues { |
| 573 | 583 | indicator: self.indicator.unwrap_or_default(), |
| 574 | 584 | indicator_location: self.indicator_location.unwrap_or(DEFAULT_ENC_INDICATOR_LOC), |
| 585 | icon_encrypted: self.icon_encrypted.map(Cow::Owned).unwrap_or(DEFAULT_ICON_ENC), |
| 586 | icon_unencrypted: self.icon_unencrypted.map(Cow::Owned).unwrap_or(DEFAULT_ICON_UNENC), |
| 587 | icon_unknown: self.icon_unknown.map(Cow::Owned).unwrap_or(DEFAULT_ICON_UNKNOWN), |
| 575 | 588 | } |
| 576 | 589 | } |
| 577 | 590 | } |
| @@ -580,6 +593,9 @@ impl Encryption { |
| 580 | 593 | pub struct EncryptionValues { |
| 581 | 594 | pub indicator: EncryptionIndicator, |
| 582 | 595 | pub indicator_location: EncryptionIndicatorLocation, |
| 596 | pub icon_encrypted: Cow<'static, str>, |
| 597 | pub icon_unencrypted: Cow<'static, str>, |
| 598 | pub icon_unknown: Cow<'static, str>, |
| 583 | 599 | } |
| 584 | 600 | |
| 585 | 601 | impl EncryptionValues { |
| @@ -603,20 +619,20 @@ impl EncryptionValues { |
| 603 | 619 | EncryptionIndicator::Enabled | EncryptionIndicator::OnlyEncrypted, |
| 604 | 620 | EncryptionState::Encrypted, |
| 605 | 621 | ) => { |
| 606 | | // Green lock: |
| 607 | | Span::styled("\u{1F512}\u{FE0E} ", Style::new().fg(Color::LightGreen)) |
| 622 | // Green encrypted icon: |
| 623 | Span::styled(self.icon_encrypted.clone(), Style::new().fg(Color::LightGreen)) |
| 608 | 624 | }, |
| 609 | 625 | ( |
| 610 | 626 | EncryptionIndicator::Enabled | EncryptionIndicator::OnlyUnencrypted, |
| 611 | 627 | EncryptionState::NotEncrypted, |
| 612 | 628 | ) => { |
| 613 | | // Red unlocked lock: |
| 614 | | Span::styled("\u{1F513}\u{FE0E} ", Style::new().fg(Color::Red)) |
| 629 | // Red unencrypted icon: |
| 630 | Span::styled(self.icon_unencrypted.clone(), Style::new().fg(Color::Red)) |
| 615 | 631 | }, |
| 616 | 632 | |
| 617 | 633 | (_, EncryptionState::Unknown) => { |
| 618 | | // Yellow question mark: |
| 619 | | Span::styled("? ", Style::new().fg(Color::Yellow)) |
| 634 | // Yellow unknown icon: |
| 635 | Span::styled(self.icon_unknown.clone(), Style::new().fg(Color::Yellow)) |
| 620 | 636 | }, |
| 621 | 637 | }; |
| 622 | 638 | |
| @@ -1832,10 +1848,12 @@ mod tests { |
| 1832 | 1848 | fn test_encryption_indicator_enabled() { |
| 1833 | 1849 | use EncryptionState::*; |
| 1834 | 1850 | |
| 1835 | | let enc = EncryptionValues { |
| 1836 | | indicator: EncryptionIndicator::Enabled, |
| 1837 | | indicator_location: EncryptionIndicatorLocation::TITLE, |
| 1851 | let enc = Encryption { |
| 1852 | indicator: Some(EncryptionIndicator::Enabled), |
| 1853 | indicator_location: Some(EncryptionIndicatorLocation::TITLE), |
| 1854 | ..Default::default() |
| 1838 | 1855 | }; |
| 1856 | let enc = enc.values(); |
| 1839 | 1857 | |
| 1840 | 1858 | // Always shows in the title: |
| 1841 | 1859 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted).is_some()); |
| @@ -1858,10 +1876,12 @@ mod tests { |
| 1858 | 1876 | fn test_encryption_indicator_disabled() { |
| 1859 | 1877 | use EncryptionState::*; |
| 1860 | 1878 | |
| 1861 | | let enc = EncryptionValues { |
| 1862 | | indicator: EncryptionIndicator::Disabled, |
| 1863 | | indicator_location: EncryptionIndicatorLocation::TITLE, |
| 1879 | let enc = Encryption { |
| 1880 | indicator: Some(EncryptionIndicator::Disabled), |
| 1881 | indicator_location: Some(EncryptionIndicatorLocation::TITLE), |
| 1882 | ..Default::default() |
| 1864 | 1883 | }; |
| 1884 | let enc = enc.values(); |
| 1865 | 1885 | |
| 1866 | 1886 | // Never shows in the title or the prompt: |
| 1867 | 1887 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted).is_none()); |
| @@ -1882,10 +1902,12 @@ mod tests { |
| 1882 | 1902 | fn test_encryption_indicator_only_encrypted() { |
| 1883 | 1903 | use EncryptionState::*; |
| 1884 | 1904 | |
| 1885 | | let enc = EncryptionValues { |
| 1886 | | indicator: EncryptionIndicator::OnlyEncrypted, |
| 1887 | | indicator_location: EncryptionIndicatorLocation::PROMPT, |
| 1905 | let enc = Encryption { |
| 1906 | indicator: Some(EncryptionIndicator::OnlyEncrypted), |
| 1907 | indicator_location: Some(EncryptionIndicatorLocation::PROMPT), |
| 1908 | ..Default::default() |
| 1888 | 1909 | }; |
| 1910 | let enc = enc.values(); |
| 1889 | 1911 | |
| 1890 | 1912 | // Shows in the prompt when encrypted or unknown: |
| 1891 | 1913 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Encrypted).is_some()); |
| @@ -1909,10 +1931,12 @@ mod tests { |
| 1909 | 1931 | fn test_encryption_indicator_only_unencrypted() { |
| 1910 | 1932 | use EncryptionState::*; |
| 1911 | 1933 | |
| 1912 | | let enc = EncryptionValues { |
| 1913 | | indicator: EncryptionIndicator::OnlyUnencrypted, |
| 1914 | | indicator_location: EncryptionIndicatorLocation::all(), |
| 1934 | let enc = Encryption { |
| 1935 | indicator: Some(EncryptionIndicator::OnlyUnencrypted), |
| 1936 | indicator_location: Some(EncryptionIndicatorLocation::all()), |
| 1937 | ..Default::default() |
| 1915 | 1938 | }; |
| 1939 | let enc = enc.values(); |
| 1916 | 1940 | |
| 1917 | 1941 | // Shows in both the prompt and title when unencrypted or unknown: |
| 1918 | 1942 | assert!( |