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
1515input_prompt = "❯ "
1616log_level = "warn"
1717members_split = "vertical"
18message_formatted_display = true
1819message_shortcode_display = false
1920open_command = ["my-open", "--file"]
2021reaction_display = true
docs/iamb.5 +7
@@ -212,6 +212,13 @@ Enable mouse support
212212See
213213.Sx MOUSE
214214for more details.
215.It Sy message_formatted_display
216Defines whether or not the formatted (HTML) body of a message should be rendered.
217If
218.Sy false ,
219the plain text body is shown as it was sent, without any rich text rendering.
220Defaults to
221.Sy true .
215222.It Sy message_shortcode_display
216223Defines whether or not Emoji characters in messages should be replaced by their
217224respective shortcodes.
src/config/mod.rs +6
@@ -774,6 +774,7 @@ pub struct TunableValues {
774774 pub ignorecase: bool,
775775 pub log_level: String,
776776 pub max_log_files: usize,
777 pub message_formatted_display: bool,
777778 pub message_shortcode_display: bool,
778779 pub normal_after_send: bool,
779780 pub proxy: ProxyValues,
@@ -834,6 +835,7 @@ pub struct Tunables {
834835 pub ignorecase: Option<bool>,
835836 pub log_level: Option<String>,
836837 pub max_log_files: Option<usize>,
838 pub message_formatted_display: Option<bool>,
837839 pub message_shortcode_display: Option<bool>,
838840 pub normal_after_send: Option<bool>,
839841 pub reaction_display: Option<bool>,
@@ -884,6 +886,9 @@ impl Tunables {
884886 ignorecase: self.ignorecase.or(other.ignorecase),
885887 log_level: self.log_level.or(other.log_level),
886888 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),
887892 message_shortcode_display: self
888893 .message_shortcode_display
889894 .or(other.message_shortcode_display),
@@ -935,6 +940,7 @@ impl Tunables {
935940 log_level: self.log_level.unwrap_or_else(|| DEFAULT_LOG_LEVEL.to_owned()),
936941 ignorecase: self.ignorecase.unwrap_or(false),
937942 max_log_files: self.max_log_files.unwrap_or(7),
943 message_formatted_display: self.message_formatted_display.unwrap_or(true),
938944 message_shortcode_display: self.message_shortcode_display.unwrap_or(false),
939945 normal_after_send: self.normal_after_send.unwrap_or(false),
940946 reaction_display: self.reaction_display.unwrap_or(true),
src/message/mod.rs +38 −1
@@ -1400,7 +1400,9 @@ impl Message {
14001400 text += wrapped_text(filename, width, style);
14011401 }
14021402
1403 if let Some(html) = &self.html {
1403 if let Some(html) = &self.html &&
1404 settings.tunables.message_formatted_display
1405 {
14041406 text += html.to_text(width, style, settings, info);
14051407 } else {
14061408 let mut msg = self.event.body();
@@ -2022,4 +2024,39 @@ pub mod tests {
20222024 info.set_receipt(ReceiptThread::Main, user_id, MSG1_EVID.clone());
20232025 assert!(!msg.show_trackbar(Some(&prev), &info, &settings));
20242026 }
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> &lt;world&gt;",
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 }
20252062}
src/tests.rs +1
@@ -158,6 +158,7 @@ pub fn mock_tunables() -> TunableValues {
158158 input_prompt: None,
159159 log_level: "warn".into(),
160160 max_log_files: 7,
161 message_formatted_display: true,
161162 message_shortcode_display: false,
162163 normal_after_send: true,
163164 proxy: Proxy::default().values(),