Commit 3ed87aae05

3ed87aae0570e5de89687a48a68d070a7691a613

parent: 1325295d2b

Unregistered key

Benjamin Grosse <ste3ls@gmail.com> · 2024-02-28 06:52 UTC
committer: <noreply@github.com>

Support coloring entire message with the user color (#193)

Layout: unified · split

docs/iamb.5.md +3
@@ -82,6 +82,9 @@ overridden as described in *PROFILES*.
82**default_room** (type: string) 82**default_room** (type: string)
83> The room to show by default instead of a welcome-screen. 83> The room to show by default instead of a welcome-screen.
84 84
85**message_user_color** (type: boolean)
86> Defines whether or not the message body is colored like the username.
87
85**image_preview** (type: image_preview object) 88**image_preview** (type: image_preview object)
86> Enable image previews and configure it. An empty object will enable the 89> Enable image previews and configure it. An empty object will enable the
87> feature with default settings, omitting it will disable the feature. 90> feature with default settings, omitting it will disable the feature.
src/config.rs +4
@@ -347,6 +347,7 @@ pub struct TunableValues {
347 pub typing_notice_display: bool, 347 pub typing_notice_display: bool,
348 pub users: UserOverrides, 348 pub users: UserOverrides,
349 pub username_display: UserDisplayStyle, 349 pub username_display: UserDisplayStyle,
350 pub message_user_color: bool,
350 pub default_room: Option<String>, 351 pub default_room: Option<String>,
351 pub open_command: Option<Vec<String>>, 352 pub open_command: Option<Vec<String>>,
352 pub image_preview: Option<ImagePreviewValues>, 353 pub image_preview: Option<ImagePreviewValues>,
@@ -366,6 +367,7 @@ pub struct Tunables {
366 pub typing_notice_display: Option<bool>, 367 pub typing_notice_display: Option<bool>,
367 pub users: Option<UserOverrides>, 368 pub users: Option<UserOverrides>,
368 pub username_display: Option<UserDisplayStyle>, 369 pub username_display: Option<UserDisplayStyle>,
370 pub message_user_color: Option<bool>,
369 pub default_room: Option<String>, 371 pub default_room: Option<String>,
370 pub open_command: Option<Vec<String>>, 372 pub open_command: Option<Vec<String>>,
371 pub image_preview: Option<ImagePreview>, 373 pub image_preview: Option<ImagePreview>,
@@ -387,6 +389,7 @@ impl Tunables {
387 typing_notice_display: self.typing_notice_display.or(other.typing_notice_display), 389 typing_notice_display: self.typing_notice_display.or(other.typing_notice_display),
388 users: merge_users(self.users, other.users), 390 users: merge_users(self.users, other.users),
389 username_display: self.username_display.or(other.username_display), 391 username_display: self.username_display.or(other.username_display),
392 message_user_color: self.message_user_color.or(other.message_user_color),
390 default_room: self.default_room.or(other.default_room), 393 default_room: self.default_room.or(other.default_room),
391 open_command: self.open_command.or(other.open_command), 394 open_command: self.open_command.or(other.open_command),
392 image_preview: self.image_preview.or(other.image_preview), 395 image_preview: self.image_preview.or(other.image_preview),
@@ -406,6 +409,7 @@ impl Tunables {
406 typing_notice_display: self.typing_notice_display.unwrap_or(true), 409 typing_notice_display: self.typing_notice_display.unwrap_or(true),
407 users: self.users.unwrap_or_default(), 410 users: self.users.unwrap_or_default(),
408 username_display: self.username_display.unwrap_or_default(), 411 username_display: self.username_display.unwrap_or_default(),
412 message_user_color: self.message_user_color.unwrap_or(false),
409 default_room: self.default_room, 413 default_room: self.default_room,
410 open_command: self.open_command, 414 open_command: self.open_command,
411 image_preview: self.image_preview.map(ImagePreview::values), 415 image_preview: self.image_preview.map(ImagePreview::values),
src/message/mod.rs +7 −2
@@ -635,7 +635,7 @@ impl Message {
635 } 635 }
636 } 636 }
637 637
638 fn get_render_style(&self, selected: bool) -> Style { 638 fn get_render_style(&self, selected: bool, settings: &ApplicationSettings) -> Style {
639 let mut style = Style::default(); 639 let mut style = Style::default();
640 640
641 if selected { 641 if selected {
@@ -646,6 +646,11 @@ impl Message {
646 style = style.add_modifier(StyleModifier::ITALIC); 646 style = style.add_modifier(StyleModifier::ITALIC);
647 } 647 }
648 648
649 if settings.tunables.message_user_color {
650 let color = crate::config::user_color(self.sender.as_str());
651 style = style.fg(color);
652 }
653
649 return style; 654 return style;
650 } 655 }
651 656
@@ -739,7 +744,7 @@ impl Message {
739 ) -> Text<'a> { 744 ) -> Text<'a> {
740 let width = vwctx.get_width(); 745 let width = vwctx.get_width();
741 746
742 let style = self.get_render_style(selected); 747 let style = self.get_render_style(selected, settings);
743 let mut fmt = self.get_render_format(prev, width, info, settings); 748 let mut fmt = self.get_render_format(prev, width, info, settings);
744 let mut text = Text { lines: vec![] }; 749 let mut text = Text { lines: vec![] };
745 let width = fmt.width(); 750 let width = fmt.width();
src/tests.rs +1
@@ -196,6 +196,7 @@ pub fn mock_tunables() -> TunableValues {
196 .collect::<HashMap<_, _>>(), 196 .collect::<HashMap<_, _>>(),
197 open_command: None, 197 open_command: None,
198 username_display: UserDisplayStyle::Username, 198 username_display: UserDisplayStyle::Username,
199 message_user_color: false,
199 image_preview: None, 200 image_preview: None,
200 } 201 }
201} 202}