Commit ddadde6e4c
ddadde6e4c40c0f9550d58a525cbd99e77e09c13
parent: 1de8891b62
Unregistered key
anying <49945850+anyingiit@users.noreply.github.com> · 2026-09-25 05:00 UTC
committer: <noreply@github.com>
Add `message_formatted_display` option to show the plaintext message body (#745)
Layout: unified · split
config.example.toml
+1
| @@ -15,6 +15,7 @@ ignorecase = false |
| 15 | 15 | input_prompt = "❯ " |
| 16 | 16 | log_level = "warn" |
| 17 | 17 | members_split = "vertical" |
| 18 | message_formatted_display = true |
| 18 | 19 | message_shortcode_display = false |
| 19 | 20 | open_command = ["my-open", "--file"] |
| 20 | 21 | reaction_display = true |
docs/iamb.5
+7
| @@ -212,6 +212,13 @@ Enable mouse support |
| 212 | 212 | See |
| 213 | 213 | .Sx MOUSE |
| 214 | 214 | for more details. |
| 215 | .It Sy message_formatted_display |
| 216 | Defines whether or not the formatted (HTML) body of a message should be rendered. |
| 217 | If |
| 218 | .Sy false , |
| 219 | the plain text body is shown as it was sent, without any rich text rendering. |
| 220 | Defaults to |
| 221 | .Sy true . |
| 215 | 222 | .It Sy message_shortcode_display |
| 216 | 223 | Defines whether or not Emoji characters in messages should be replaced by their |
| 217 | 224 | respective shortcodes. |
src/config/mod.rs
+6
| @@ -774,6 +774,7 @@ pub struct TunableValues { |
| 774 | 774 | pub ignorecase: bool, |
| 775 | 775 | pub log_level: String, |
| 776 | 776 | pub max_log_files: usize, |
| 777 | pub message_formatted_display: bool, |
| 777 | 778 | pub message_shortcode_display: bool, |
| 778 | 779 | pub normal_after_send: bool, |
| 779 | 780 | pub proxy: ProxyValues, |
| @@ -834,6 +835,7 @@ pub struct Tunables { |
| 834 | 835 | pub ignorecase: Option<bool>, |
| 835 | 836 | pub log_level: Option<String>, |
| 836 | 837 | pub max_log_files: Option<usize>, |
| 838 | pub message_formatted_display: Option<bool>, |
| 837 | 839 | pub message_shortcode_display: Option<bool>, |
| 838 | 840 | pub normal_after_send: Option<bool>, |
| 839 | 841 | pub reaction_display: Option<bool>, |
| @@ -884,6 +886,9 @@ impl Tunables { |
| 884 | 886 | ignorecase: self.ignorecase.or(other.ignorecase), |
| 885 | 887 | log_level: self.log_level.or(other.log_level), |
| 886 | 888 | max_log_files: self.max_log_files.or(other.max_log_files), |
| 889 | message_formatted_display: self |
| 890 | .message_formatted_display |
| 891 | .or(other.message_formatted_display), |
| 887 | 892 | message_shortcode_display: self |
| 888 | 893 | .message_shortcode_display |
| 889 | 894 | .or(other.message_shortcode_display), |
| @@ -935,6 +940,7 @@ impl Tunables { |
| 935 | 940 | log_level: self.log_level.unwrap_or_else(|| DEFAULT_LOG_LEVEL.to_owned()), |
| 936 | 941 | ignorecase: self.ignorecase.unwrap_or(false), |
| 937 | 942 | max_log_files: self.max_log_files.unwrap_or(7), |
| 943 | message_formatted_display: self.message_formatted_display.unwrap_or(true), |
| 938 | 944 | message_shortcode_display: self.message_shortcode_display.unwrap_or(false), |
| 939 | 945 | normal_after_send: self.normal_after_send.unwrap_or(false), |
| 940 | 946 | reaction_display: self.reaction_display.unwrap_or(true), |
src/message/mod.rs
+38 −1
| @@ -1400,7 +1400,9 @@ impl Message { |
| 1400 | 1400 | text += wrapped_text(filename, width, style); |
| 1401 | 1401 | } |
| 1402 | 1402 | |
| 1403 | | if let Some(html) = &self.html { |
| 1403 | if let Some(html) = &self.html && |
| 1404 | settings.tunables.message_formatted_display |
| 1405 | { |
| 1404 | 1406 | text += html.to_text(width, style, settings, info); |
| 1405 | 1407 | } else { |
| 1406 | 1408 | let mut msg = self.event.body(); |
| @@ -2022,4 +2024,39 @@ pub mod tests { |
| 2022 | 2024 | info.set_receipt(ReceiptThread::Main, user_id, MSG1_EVID.clone()); |
| 2023 | 2025 | assert!(!msg.show_trackbar(Some(&prev), &info, &settings)); |
| 2024 | 2026 | } |
| 2027 | |
| 2028 | #[test] |
| 2029 | fn test_show_msg_html_display() { |
| 2030 | let mut settings = mock_settings(); |
| 2031 | let previews = PreviewManager::new(&settings); |
| 2032 | let info = mock_room(); |
| 2033 | |
| 2034 | let content = RoomMessageEventContent::text_html( |
| 2035 | "**hello** <world>", |
| 2036 | "<strong>hello</strong> <world>", |
| 2037 | ); |
| 2038 | let msg = mock_room1_message(content, TEST_USER1.clone(), MSG1_KEY.clone()); |
| 2039 | |
| 2040 | let render = |settings: &ApplicationSettings| -> String { |
| 2041 | let (text, _) = msg.show_msg(60, Style::default(), settings, &previews, &info); |
| 2042 | |
| 2043 | let s: String = text |
| 2044 | .lines |
| 2045 | .iter() |
| 2046 | .flat_map(|line| line.spans.iter()) |
| 2047 | .map(|span| span.content.as_ref()) |
| 2048 | .collect(); |
| 2049 | |
| 2050 | // The HTML renderer pads lines out to the full width. |
| 2051 | s.trim_end().to_string() |
| 2052 | }; |
| 2053 | |
| 2054 | // By default, the formatted HTML body is rendered. |
| 2055 | assert!(settings.tunables.message_formatted_display); |
| 2056 | assert_eq!(render(&settings), "hello <world>"); |
| 2057 | |
| 2058 | // When disabled, the plain text body is shown exactly as it was sent. |
| 2059 | settings.tunables.message_formatted_display = false; |
| 2060 | assert_eq!(render(&settings), "**hello** <world>"); |
| 2061 | } |
| 2025 | 2062 | } |
src/tests.rs
+1
| @@ -158,6 +158,7 @@ pub fn mock_tunables() -> TunableValues { |
| 158 | 158 | input_prompt: None, |
| 159 | 159 | log_level: "warn".into(), |
| 160 | 160 | max_log_files: 7, |
| 161 | message_formatted_display: true, |
| 161 | 162 | message_shortcode_display: false, |
| 162 | 163 | normal_after_send: true, |
| 163 | 164 | proxy: Proxy::default().values(), |