Commit 71c1efcd37

71c1efcd37792bca8d034f30df44307a1a1df4b9

parent: ec9bd32a8d

Unregistered key

Ulyssa <git@ulyssa.dev> · 2026-07-26 16:04 UTC
committer: <noreply@github.com>

Allow explicitly controlling when extended keypresses are enabled (#632)

Layout: unified · split

docs/iamb.5 +22
@@ -221,6 +221,11 @@ See
221for more details. 221for more details.
222.It Sy state_event_display 222.It Sy state_event_display
223Defines whether the state events like joined or left are shown. 223Defines whether the state events like joined or left are shown.
224.It Sy terminal
225Subsection for configuring how specific terminal features are used (or not used).
226See
227.Sx TERMINAL
228for more details.
224.It Sy typing_notice_send 229.It Sy typing_notice_send
225Defines whether or not the typing state is sent. 230Defines whether or not the typing state is sent.
226.It Sy typing_notice_display 231.It Sy typing_notice_display
@@ -289,6 +294,7 @@ and
289(the default). 294(the default).
290Both can be used via 295Both can be used via
291.Dq Sy title|prompt . 296.Dq Sy title|prompt .
297.El
292.Sh MOUSE 298.Sh MOUSE
293The 299The
294.Sy settings.mouse 300.Sy settings.mouse
@@ -424,6 +430,22 @@ in front of any value to flip the order.
424[settings.sort] 430[settings.sort]
425members = ["server", "~localpart"] 431members = ["server", "~localpart"]
426.Ed 432.Ed
433.Sh TERMINAL
434The
435.Sy settings.terminal
436subsection allows overriding how
437.Sy iamb
438interacts with your terminal.
439.Pp
440The available fields in this subsection are:
441.Bl -tag -width Ds
442.It Sy enable_extended_keys
443Defines whether to explicitly enable or disable requesting extended keypresses from your terminal.
444By default, when unset,
445.Sy iamb
446will attempt to auto-detect support in your terminal and request extended keypresses from the terminal if supported.
447.El
448.It Sy indicator
427.Sh "USER OVERRIDES" 449.Sh "USER OVERRIDES"
428The 450The
429.Sy settings.users 451.Sy settings.users
src/config.rs +62 −25
@@ -317,23 +317,6 @@ pub struct UserDisplayTunables {
317 317
318pub type UserOverrides = HashMap<OwnedUserId, UserDisplayTunables>; 318pub type UserOverrides = HashMap<OwnedUserId, UserDisplayTunables>;
319 319
320fn merge_encryption(profile: Encryption, global: Encryption) -> Encryption {
321 Encryption {
322 indicator: profile.indicator.or(global.indicator),
323 indicator_location: profile.indicator_location.or(global.indicator_location),
324 }
325}
326
327fn merge_sorts(profile: SortOverrides, global: SortOverrides) -> SortOverrides {
328 SortOverrides {
329 chats: profile.chats.or(global.chats),
330 dms: profile.dms.or(global.dms),
331 rooms: profile.rooms.or(global.rooms),
332 spaces: profile.spaces.or(global.spaces),
333 members: profile.members.or(global.members),
334 }
335}
336
337fn merge_maps<K, V>( 320fn merge_maps<K, V>(
338 profile: Option<HashMap<K, V>>, 321 profile: Option<HashMap<K, V>>,
339 global: Option<HashMap<K, V>>, 322 global: Option<HashMap<K, V>>,
@@ -509,6 +492,13 @@ pub struct Encryption {
509} 492}
510 493
511impl Encryption { 494impl Encryption {
495 fn merge(profile: Self, global: Self) -> Self {
496 Encryption {
497 indicator: profile.indicator.or(global.indicator),
498 indicator_location: profile.indicator_location.or(global.indicator_location),
499 }
500 }
501
512 pub fn values(self) -> EncryptionValues { 502 pub fn values(self) -> EncryptionValues {
513 EncryptionValues { 503 EncryptionValues {
514 indicator: self.indicator.unwrap_or_default(), 504 indicator: self.indicator.unwrap_or_default(),
@@ -641,6 +631,16 @@ pub struct SortOverrides {
641} 631}
642 632
643impl SortOverrides { 633impl SortOverrides {
634 fn merge(profile: Self, global: Self) -> Self {
635 Self {
636 chats: profile.chats.or(global.chats),
637 dms: profile.dms.or(global.dms),
638 rooms: profile.rooms.or(global.rooms),
639 spaces: profile.spaces.or(global.spaces),
640 members: profile.members.or(global.members),
641 }
642 }
643
644 pub fn values(self) -> SortValues { 644 pub fn values(self) -> SortValues {
645 let rooms = self.rooms.unwrap_or_else(|| Vec::from(DEFAULT_ROOM_SORT)); 645 let rooms = self.rooms.unwrap_or_else(|| Vec::from(DEFAULT_ROOM_SORT));
646 let chats = self.chats.unwrap_or_else(|| rooms.clone()); 646 let chats = self.chats.unwrap_or_else(|| rooms.clone());
@@ -652,6 +652,28 @@ impl SortOverrides {
652 } 652 }
653} 653}
654 654
655#[derive(Clone, Debug, Default, Deserialize)]
656pub struct Terminal {
657 pub enable_extended_keys: Option<bool>,
658}
659
660impl Terminal {
661 fn merge(profile: Self, global: Self) -> Self {
662 Self {
663 enable_extended_keys: profile.enable_extended_keys.or(global.enable_extended_keys),
664 }
665 }
666
667 pub fn values(self) -> TerminalValues {
668 TerminalValues { enable_extended_keys: self.enable_extended_keys }
669 }
670}
671
672#[derive(Clone, Debug)]
673pub struct TerminalValues {
674 pub enable_extended_keys: Option<bool>,
675}
676
655#[derive(Clone)] 677#[derive(Clone)]
656pub struct TunableValues { 678pub struct TunableValues {
657 pub encryption: EncryptionValues, 679 pub encryption: EncryptionValues,
@@ -675,6 +697,7 @@ pub struct TunableValues {
675 pub open_command: Option<Vec<String>>, 697 pub open_command: Option<Vec<String>>,
676 pub mouse: Mouse, 698 pub mouse: Mouse,
677 pub notifications: Notifications, 699 pub notifications: Notifications,
700 pub terminal: TerminalValues,
678 pub image_preview: Option<ImagePreviewValues>, 701 pub image_preview: Option<ImagePreviewValues>,
679 pub user_gutter_width: usize, 702 pub user_gutter_width: usize,
680 pub external_edit_file_suffix: String, 703 pub external_edit_file_suffix: String,
@@ -684,8 +707,21 @@ pub struct TunableValues {
684 707
685#[derive(Clone, Default, Deserialize)] 708#[derive(Clone, Default, Deserialize)]
686pub struct Tunables { 709pub struct Tunables {
710 /// Subsection for overriding encryption-related settings.
687 #[serde(default)] 711 #[serde(default)]
688 pub encryption: Encryption, 712 pub encryption: Encryption,
713
714 /// Subsection for overriding sort orders in UI lists.
715 #[serde(default)]
716 pub sort: SortOverrides,
717
718 /// Subsection for overriding terminal settings.
719 #[serde(default)]
720 pub terminal: Terminal,
721
722 /// Subsection for overriding how specific Matrix users are rendered.
723 pub users: Option<UserOverrides>,
724
689 pub log_level: Option<String>, 725 pub log_level: Option<String>,
690 pub max_log_files: Option<usize>, 726 pub max_log_files: Option<usize>,
691 pub message_shortcode_display: Option<bool>, 727 pub message_shortcode_display: Option<bool>,
@@ -695,12 +731,9 @@ pub struct Tunables {
695 pub read_receipt_send: Option<bool>, 731 pub read_receipt_send: Option<bool>,
696 pub read_receipt_display: Option<bool>, 732 pub read_receipt_display: Option<bool>,
697 pub request_timeout: Option<u64>, 733 pub request_timeout: Option<u64>,
698 #[serde(default)]
699 pub sort: SortOverrides,
700 pub state_event_display: Option<bool>, 734 pub state_event_display: Option<bool>,
701 pub typing_notice_send: Option<bool>, 735 pub typing_notice_send: Option<bool>,
702 pub typing_notice_display: Option<bool>, 736 pub typing_notice_display: Option<bool>,
703 pub users: Option<UserOverrides>,
704 pub username_display: Option<UserDisplayStyle>, 737 pub username_display: Option<UserDisplayStyle>,
705 pub message_user_color: Option<bool>, 738 pub message_user_color: Option<bool>,
706 pub default_room: Option<String>, 739 pub default_room: Option<String>,
@@ -717,7 +750,11 @@ pub struct Tunables {
717impl Tunables { 750impl Tunables {
718 fn merge(self, other: Self) -> Self { 751 fn merge(self, other: Self) -> Self {
719 Tunables { 752 Tunables {
720 encryption: merge_encryption(self.encryption, other.encryption), 753 encryption: Encryption::merge(self.encryption, other.encryption),
754 sort: SortOverrides::merge(self.sort, other.sort),
755 terminal: Terminal::merge(self.terminal, other.terminal),
756 users: merge_maps(self.users, other.users),
757
721 log_level: self.log_level.or(other.log_level), 758 log_level: self.log_level.or(other.log_level),
722 max_log_files: self.max_log_files.or(other.max_log_files), 759 max_log_files: self.max_log_files.or(other.max_log_files),
723 message_shortcode_display: self 760 message_shortcode_display: self
@@ -731,11 +768,9 @@ impl Tunables {
731 read_receipt_send: self.read_receipt_send.or(other.read_receipt_send), 768 read_receipt_send: self.read_receipt_send.or(other.read_receipt_send),
732 read_receipt_display: self.read_receipt_display.or(other.read_receipt_display), 769 read_receipt_display: self.read_receipt_display.or(other.read_receipt_display),
733 request_timeout: self.request_timeout.or(other.request_timeout), 770 request_timeout: self.request_timeout.or(other.request_timeout),
734 sort: merge_sorts(self.sort, other.sort),
735 state_event_display: self.state_event_display.or(other.state_event_display), 771 state_event_display: self.state_event_display.or(other.state_event_display),
736 typing_notice_send: self.typing_notice_send.or(other.typing_notice_send), 772 typing_notice_send: self.typing_notice_send.or(other.typing_notice_send),
737 typing_notice_display: self.typing_notice_display.or(other.typing_notice_display), 773 typing_notice_display: self.typing_notice_display.or(other.typing_notice_display),
738 users: merge_maps(self.users, other.users),
739 username_display: self.username_display.or(other.username_display), 774 username_display: self.username_display.or(other.username_display),
740 message_user_color: self.message_user_color.or(other.message_user_color), 775 message_user_color: self.message_user_color.or(other.message_user_color),
741 default_room: self.default_room.or(other.default_room), 776 default_room: self.default_room.or(other.default_room),
@@ -754,8 +789,11 @@ impl Tunables {
754 789
755 fn values(self) -> TunableValues { 790 fn values(self) -> TunableValues {
756 TunableValues { 791 TunableValues {
757 log_level: self.log_level.unwrap_or_else(|| "warn".to_string()),
758 encryption: self.encryption.values(), 792 encryption: self.encryption.values(),
793 sort: self.sort.values(),
794 terminal: self.terminal.values(),
795
796 log_level: self.log_level.unwrap_or_else(|| "warn".to_string()),
759 max_log_files: self.max_log_files.unwrap_or(7), 797 max_log_files: self.max_log_files.unwrap_or(7),
760 message_shortcode_display: self.message_shortcode_display.unwrap_or(false), 798 message_shortcode_display: self.message_shortcode_display.unwrap_or(false),
761 normal_after_send: self.normal_after_send.unwrap_or(false), 799 normal_after_send: self.normal_after_send.unwrap_or(false),
@@ -764,7 +802,6 @@ impl Tunables {
764 read_receipt_send: self.read_receipt_send.unwrap_or(true), 802 read_receipt_send: self.read_receipt_send.unwrap_or(true),
765 read_receipt_display: self.read_receipt_display.unwrap_or(true), 803 read_receipt_display: self.read_receipt_display.unwrap_or(true),
766 request_timeout: self.request_timeout.unwrap_or(DEFAULT_REQ_TIMEOUT), 804 request_timeout: self.request_timeout.unwrap_or(DEFAULT_REQ_TIMEOUT),
767 sort: self.sort.values(),
768 state_event_display: self.state_event_display.unwrap_or(true), 805 state_event_display: self.state_event_display.unwrap_or(true),
769 typing_notice_send: self.typing_notice_send.unwrap_or(true), 806 typing_notice_send: self.typing_notice_send.unwrap_or(true),
770 typing_notice_display: self.typing_notice_display.unwrap_or(true), 807 typing_notice_display: self.typing_notice_display.unwrap_or(true),
src/main.rs +9 −8
@@ -1063,14 +1063,15 @@ async fn run(settings: ApplicationSettings) -> IambResult<()> {
1063 } 1063 }
1064 1064
1065 // Set up the terminal for drawing, and cleanup properly on panics. 1065 // Set up the terminal for drawing, and cleanup properly on panics.
1066 let enable_enhanced_keys = match crossterm::terminal::supports_keyboard_enhancement() { 1066 let enable_enhanced_keys =
1067 Ok(supported) => supported, 1067 settings.tunables.terminal.enable_extended_keys.unwrap_or_else(|| {
1068 Err(e) => { 1068 crossterm::terminal::supports_keyboard_enhancement()
1069 tracing::warn!(err = %e, 1069 .inspect_err(|e| tracing::warn!(
1070 "Failed to determine whether the terminal supports keyboard enhancements"); 1070 err = %e,
1071 false 1071 "Failed to determine whether the terminal supports keyboard enhancements"
1072 }, 1072 ))
1073 }; 1073 .unwrap_or_default()
1074 });
1074 setup_tty(&settings, enable_enhanced_keys)?; 1075 setup_tty(&settings, enable_enhanced_keys)?;
1075 1076
1076 let orig_hook = std::panic::take_hook(); 1077 let orig_hook = std::panic::take_hook();
src/tests.rs +2
@@ -31,6 +31,7 @@ use crate::{
31 NotifyVia, 31 NotifyVia,
32 ProfileConfig, 32 ProfileConfig,
33 SortOverrides, 33 SortOverrides,
34 Terminal,
34 TunableValues, 35 TunableValues,
35 UserColor, 36 UserColor,
36 UserDisplayStyle, 37 UserDisplayStyle,
@@ -183,6 +184,7 @@ pub fn mock_tunables() -> TunableValues {
183 request_timeout: 120, 184 request_timeout: 120,
184 sort: SortOverrides::default().values(), 185 sort: SortOverrides::default().values(),
185 state_event_display: true, 186 state_event_display: true,
187 terminal: Terminal::default().values(),
186 typing_notice_send: true, 188 typing_notice_send: true,
187 typing_notice_display: true, 189 typing_notice_display: true,
188 users: vec![(TEST_USER5.clone(), UserDisplayTunables { 190 users: vec![(TEST_USER5.clone(), UserDisplayTunables {