Commit a1022c8642

a1022c86422bd9a6d0bcd7f1d9a7292711b2ee71

parent: 1799941957

Unregistered key

Ulyssa <git@ulyssa.dev> · 2026-09-12 03:04 UTC
committer: <noreply@github.com>

Use ASCII characters for encryption status indicators (#684)

Layout: unified · split

docs/iamb.5 +12
@@ -316,6 +316,18 @@ subsection allows controlling how encrypted rooms are presented.
316.Pp 316.Pp
317The available fields in this subsection are: 317The available fields in this subsection are:
318.Bl -tag -width Ds 318.Bl -tag -width Ds
319.It Sy icon_encrypted
320Override the encrypted room icon used in the message bar prompt or title.
321Defaults to a green
322.Sy [E] .
323.It Sy icon_unencrypted
324Override the unencrypted room icon used in the message bar prompt or title.
325Defaults to a red
326.Sy [U] .
327.It Sy icon_unknown
328Override the unknown encryption status icon used in the message bar prompt or title.
329Defaults to a yellow
330.Sy [?] .
319.It Sy indicator 331.It Sy indicator
320Defines when an encryption status indicator is shown. 332Defines when an encryption status indicator is shown.
321Possible values are: 333Possible values are:
src/config.rs +43 −19
@@ -49,9 +49,13 @@ const DEFAULT_ROOM_SORT: [SortColumn<SortFieldRoom>; 5] = [
49]; 49];
50 50
51const DEFAULT_ENABLE_TITLE: bool = true; 51const DEFAULT_ENABLE_TITLE: bool = true;
52const DEFAULT_ENC_INDICATOR_LOC: EncryptionIndicatorLocation = EncryptionIndicatorLocation::PROMPT;
53const DEFAULT_REQ_TIMEOUT: u64 = 120; 52const DEFAULT_REQ_TIMEOUT: u64 = 120;
54 53
54const DEFAULT_ENC_INDICATOR_LOC: EncryptionIndicatorLocation = EncryptionIndicatorLocation::PROMPT;
55const DEFAULT_ICON_ENC: Cow<'static, str> = Cow::Borrowed("[E] ");
56const DEFAULT_ICON_UNENC: Cow<'static, str> = Cow::Borrowed("[U] ");
57const DEFAULT_ICON_UNKNOWN: Cow<'static, str> = Cow::Borrowed("[?] ");
58
55const DEFAULT_LOG_LEVEL: &str = if cfg!(feature = "max_level_error") { 59const 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 {
558pub struct Encryption { 562pub 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
563impl Encryption { 570impl 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 {
580pub struct EncryptionValues { 593pub 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
585impl EncryptionValues { 601impl 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!(
src/windows/room/chat.rs +15 −4
@@ -1111,10 +1111,21 @@ impl StatefulWidget for Chat<'_> {
1111 .get_indicator(EncryptionIndicatorLocation::PROMPT, state.room().encryption_state()); 1111 .get_indicator(EncryptionIndicatorLocation::PROMPT, state.room().encryption_state());
1112 let input_prompt = settings.tunables.input_prompt.as_deref(); 1112 let input_prompt = settings.tunables.input_prompt.as_deref();
1113 let prompt = match (self.focused, encryption_indicator, input_prompt) { 1113 let prompt = match (self.focused, encryption_indicator, input_prompt) {
1114 (false, _, _) => Span::raw(" "), 1114 // User has both encryption indicator and custom prompt, combine them:
1115 (true, Some(i), _) => i, 1115 (false, Some(i), Some(p)) => Line::from(crate::util::space(i.width() + p.width())),
1116 (true, None, None) => Span::raw("> "), 1116 (true, Some(i), Some(p)) => Line::from(vec![i, Span::from(p)]),
1117 (true, None, Some(s)) => Span::raw(s), 1117
1118 // User has custom prompt, use that:
1119 (false, None, Some(p)) => Line::from(crate::util::space(p.width())),
1120 (true, None, Some(p)) => Line::from(p),
1121
1122 // User has encryption indicator, use that as prompt:
1123 (false, Some(i), None) => Line::from(crate::util::space(i.width())),
1124 (true, Some(i), None) => Line::from(i),
1125
1126 // User has no encryption indicator, no custom prompt, so show "> ":
1127 (false, None, None) => Line::from(crate::util::space(2)),
1128 (true, None, None) => Line::from("> "),
1118 }; 1129 };
1119 1130
1120 let tbox = TextBox::new().prompt(prompt); 1131 let tbox = TextBox::new().prompt(prompt);
src/windows/room/mod.rs +8 −7
@@ -808,6 +808,14 @@ impl RoomState {
808 let style = Style::default().add_modifier(StyleModifier::BOLD); 808 let style = Style::default().add_modifier(StyleModifier::BOLD);
809 let mut spans = vec![]; 809 let mut spans = vec![];
810 810
811 if let Some(room) = room {
812 let encryption_settings = &store.application.settings.tunables.encryption;
813 let encryption_indicator = encryption_settings
814 .get_indicator(EncryptionIndicatorLocation::TITLE, room.encryption_state());
815 spans.extend(encryption_indicator);
816 spans.push(Span::raw(" "));
817 }
818
811 if let RoomState::Chat(chat) = self && 819 if let RoomState::Chat(chat) = self &&
812 chat.thread().is_some() 820 chat.thread().is_some()
813 { 821 {
@@ -816,13 +824,6 @@ impl RoomState {
816 824
817 spans.push(Span::styled(title, style)); 825 spans.push(Span::styled(title, style));
818 826
819 if let Some(room) = room {
820 let encryption_settings = &store.application.settings.tunables.encryption;
821 let encryption_indicator = encryption_settings
822 .get_indicator(EncryptionIndicatorLocation::TITLE, room.encryption_state());
823 spans.extend(encryption_indicator);
824 }
825
826 match self.room().topic() { 827 match self.room().topic() {
827 Some(desc) if !desc.is_empty() => { 828 Some(desc) if !desc.is_empty() => {
828 spans.push(" (".into()); 829 spans.push(" (".into());