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