diff --git a/docs/iamb.5.md b/docs/iamb.5.md index 0b54930..7c52a3c 100644 --- a/docs/iamb.5.md +++ b/docs/iamb.5.md @@ -82,6 +82,9 @@ overridden as described in *PROFILES*. **default_room** (type: string) > The room to show by default instead of a welcome-screen. +**message_user_color** (type: boolean) +> Defines whether or not the message body is colored like the username. + **image_preview** (type: image_preview object) > Enable image previews and configure it. An empty object will enable the > feature with default settings, omitting it will disable the feature. diff --git a/src/config.rs b/src/config.rs index a0b877b..a571321 100644 --- a/src/config.rs +++ b/src/config.rs @@ -347,6 +347,7 @@ pub struct TunableValues { pub typing_notice_display: bool, pub users: UserOverrides, pub username_display: UserDisplayStyle, + pub message_user_color: bool, pub default_room: Option, pub open_command: Option>, pub image_preview: Option, @@ -366,6 +367,7 @@ pub struct Tunables { pub typing_notice_display: Option, pub users: Option, pub username_display: Option, + pub message_user_color: Option, pub default_room: Option, pub open_command: Option>, pub image_preview: Option, @@ -387,6 +389,7 @@ impl Tunables { typing_notice_display: self.typing_notice_display.or(other.typing_notice_display), users: merge_users(self.users, other.users), username_display: self.username_display.or(other.username_display), + message_user_color: self.message_user_color.or(other.message_user_color), default_room: self.default_room.or(other.default_room), open_command: self.open_command.or(other.open_command), image_preview: self.image_preview.or(other.image_preview), @@ -406,6 +409,7 @@ impl Tunables { typing_notice_display: self.typing_notice_display.unwrap_or(true), users: self.users.unwrap_or_default(), username_display: self.username_display.unwrap_or_default(), + message_user_color: self.message_user_color.unwrap_or(false), default_room: self.default_room, open_command: self.open_command, image_preview: self.image_preview.map(ImagePreview::values), diff --git a/src/message/mod.rs b/src/message/mod.rs index 8a2a6bd..814ec29 100644 --- a/src/message/mod.rs +++ b/src/message/mod.rs @@ -635,7 +635,7 @@ impl Message { } } - fn get_render_style(&self, selected: bool) -> Style { + fn get_render_style(&self, selected: bool, settings: &ApplicationSettings) -> Style { let mut style = Style::default(); if selected { @@ -646,6 +646,11 @@ impl Message { style = style.add_modifier(StyleModifier::ITALIC); } + if settings.tunables.message_user_color { + let color = crate::config::user_color(self.sender.as_str()); + style = style.fg(color); + } + return style; } @@ -739,7 +744,7 @@ impl Message { ) -> Text<'a> { let width = vwctx.get_width(); - let style = self.get_render_style(selected); + let style = self.get_render_style(selected, settings); let mut fmt = self.get_render_format(prev, width, info, settings); let mut text = Text { lines: vec![] }; let width = fmt.width(); diff --git a/src/tests.rs b/src/tests.rs index af07a15..b30c2df 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -196,6 +196,7 @@ pub fn mock_tunables() -> TunableValues { .collect::>(), open_command: None, username_display: UserDisplayStyle::Username, + message_user_color: false, image_preview: None, } }