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

This commit is contained in:
Benjamin Grosse 2024-02-28 06:52:24 +00:00 committed by GitHub
parent 1325295d2b
commit 3ed87aae05
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 15 additions and 2 deletions

View file

@ -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<String>,
pub open_command: Option<Vec<String>>,
pub image_preview: Option<ImagePreviewValues>,
@ -366,6 +367,7 @@ pub struct Tunables {
pub typing_notice_display: Option<bool>,
pub users: Option<UserOverrides>,
pub username_display: Option<UserDisplayStyle>,
pub message_user_color: Option<bool>,
pub default_room: Option<String>,
pub open_command: Option<Vec<String>>,
pub image_preview: Option<ImagePreview>,
@ -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),

View file

@ -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();

View file

@ -196,6 +196,7 @@ pub fn mock_tunables() -> TunableValues {
.collect::<HashMap<_, _>>(),
open_command: None,
username_display: UserDisplayStyle::Username,
message_user_color: false,
image_preview: None,
}
}