Commit ddadde6e4c
Unregistered key
Layout: unified · split
config.example.toml +1
| @@ -15,6 +15,7 @@ ignorecase = false | |||
| 15 | input_prompt = "❯ " | 15 | input_prompt = "❯ " |
| 16 | log_level = "warn" | 16 | log_level = "warn" |
| 17 | members_split = "vertical" | 17 | members_split = "vertical" |
| 18 | message_formatted_display = true | ||
| 18 | message_shortcode_display = false | 19 | message_shortcode_display = false |
| 19 | open_command = ["my-open", "--file"] | 20 | open_command = ["my-open", "--file"] |
| 20 | reaction_display = true | 21 | reaction_display = true |
docs/iamb.5 +7
| @@ -212,6 +212,13 @@ Enable mouse support | |||
| 212 | See | 212 | See |
| 213 | .Sx MOUSE | 213 | .Sx MOUSE |
| 214 | for more details. | 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 | .It Sy message_shortcode_display | 222 | .It Sy message_shortcode_display |
| 216 | Defines whether or not Emoji characters in messages should be replaced by their | 223 | Defines whether or not Emoji characters in messages should be replaced by their |
| 217 | respective shortcodes. | 224 | respective shortcodes. |
src/config/mod.rs +6
| @@ -774,6 +774,7 @@ pub struct TunableValues { | |||
| 774 | pub ignorecase: bool, | 774 | pub ignorecase: bool, |
| 775 | pub log_level: String, | 775 | pub log_level: String, |
| 776 | pub max_log_files: usize, | 776 | pub max_log_files: usize, |
| 777 | pub message_formatted_display: bool, | ||
| 777 | pub message_shortcode_display: bool, | 778 | pub message_shortcode_display: bool, |
| 778 | pub normal_after_send: bool, | 779 | pub normal_after_send: bool, |
| 779 | pub proxy: ProxyValues, | 780 | pub proxy: ProxyValues, |
| @@ -834,6 +835,7 @@ pub struct Tunables { | |||
| 834 | pub ignorecase: Option<bool>, | 835 | pub ignorecase: Option<bool>, |
| 835 | pub log_level: Option<String>, | 836 | pub log_level: Option<String>, |
| 836 | pub max_log_files: Option<usize>, | 837 | pub max_log_files: Option<usize>, |
| 838 | pub message_formatted_display: Option<bool>, | ||
| 837 | pub message_shortcode_display: Option<bool>, | 839 | pub message_shortcode_display: Option<bool>, |
| 838 | pub normal_after_send: Option<bool>, | 840 | pub normal_after_send: Option<bool>, |
| 839 | pub reaction_display: Option<bool>, | 841 | pub reaction_display: Option<bool>, |
| @@ -884,6 +886,9 @@ impl Tunables { | |||
| 884 | ignorecase: self.ignorecase.or(other.ignorecase), | 886 | ignorecase: self.ignorecase.or(other.ignorecase), |
| 885 | log_level: self.log_level.or(other.log_level), | 887 | log_level: self.log_level.or(other.log_level), |
| 886 | max_log_files: self.max_log_files.or(other.max_log_files), | 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 | message_shortcode_display: self | 892 | message_shortcode_display: self |
| 888 | .message_shortcode_display | 893 | .message_shortcode_display |
| 889 | .or(other.message_shortcode_display), | 894 | .or(other.message_shortcode_display), |
| @@ -935,6 +940,7 @@ impl Tunables { | |||
| 935 | log_level: self.log_level.unwrap_or_else(|| DEFAULT_LOG_LEVEL.to_owned()), | 940 | log_level: self.log_level.unwrap_or_else(|| DEFAULT_LOG_LEVEL.to_owned()), |
| 936 | ignorecase: self.ignorecase.unwrap_or(false), | 941 | ignorecase: self.ignorecase.unwrap_or(false), |
| 937 | max_log_files: self.max_log_files.unwrap_or(7), | 942 | max_log_files: self.max_log_files.unwrap_or(7), |
| 943 | message_formatted_display: self.message_formatted_display.unwrap_or(true), | ||
| 938 | message_shortcode_display: self.message_shortcode_display.unwrap_or(false), | 944 | message_shortcode_display: self.message_shortcode_display.unwrap_or(false), |
| 939 | normal_after_send: self.normal_after_send.unwrap_or(false), | 945 | normal_after_send: self.normal_after_send.unwrap_or(false), |
| 940 | reaction_display: self.reaction_display.unwrap_or(true), | 946 | reaction_display: self.reaction_display.unwrap_or(true), |
src/message/mod.rs +38 −1
| @@ -1400,7 +1400,9 @@ impl Message { | |||
| 1400 | text += wrapped_text(filename, width, style); | 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 | text += html.to_text(width, style, settings, info); | 1406 | text += html.to_text(width, style, settings, info); |
| 1405 | } else { | 1407 | } else { |
| 1406 | let mut msg = self.event.body(); | 1408 | let mut msg = self.event.body(); |
| @@ -2022,4 +2024,39 @@ pub mod tests { | |||
| 2022 | info.set_receipt(ReceiptThread::Main, user_id, MSG1_EVID.clone()); | 2024 | info.set_receipt(ReceiptThread::Main, user_id, MSG1_EVID.clone()); |
| 2023 | assert!(!msg.show_trackbar(Some(&prev), &info, &settings)); | 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 | input_prompt: None, | 158 | input_prompt: None, |
| 159 | log_level: "warn".into(), | 159 | log_level: "warn".into(), |
| 160 | max_log_files: 7, | 160 | max_log_files: 7, |
| 161 | message_formatted_display: true, | ||
| 161 | message_shortcode_display: false, | 162 | message_shortcode_display: false, |
| 162 | normal_after_send: true, | 163 | normal_after_send: true, |
| 163 | proxy: Proxy::default().values(), | 164 | proxy: Proxy::default().values(), |