diff --git a/docs/iamb.5.md b/docs/iamb.5.md index 96043d3..adc2450 100644 --- a/docs/iamb.5.md +++ b/docs/iamb.5.md @@ -111,6 +111,10 @@ overridden as described in *PROFILES*. > *protocol.font_size* is an optional list of two numbers representing font > width and height in pixels. +**user_gutter_width** (type: usize) +> Specify the width of the column where usernames are displayed in a room. +> Usernames that are too long are truncated. + ## USER OVERRIDES Overrides are mapped onto matrix User IDs such as _@user:matrix.org_ and are diff --git a/src/config.rs b/src/config.rs index 6fb7fba..f2e36aa 100644 --- a/src/config.rs +++ b/src/config.rs @@ -485,6 +485,7 @@ pub struct TunableValues { pub open_command: Option>, pub notifications: Notifications, pub image_preview: Option, + pub user_gutter_width: usize, } #[derive(Clone, Default, Deserialize)] @@ -507,6 +508,7 @@ pub struct Tunables { pub open_command: Option>, pub notifications: Option, pub image_preview: Option, + pub user_gutter_width: Option, } impl Tunables { @@ -533,6 +535,7 @@ impl Tunables { open_command: self.open_command.or(other.open_command), notifications: self.notifications.or(other.notifications), image_preview: self.image_preview.or(other.image_preview), + user_gutter_width: self.user_gutter_width.or(other.user_gutter_width), } } @@ -555,6 +558,7 @@ impl Tunables { open_command: self.open_command, notifications: self.notifications.unwrap_or_default(), image_preview: self.image_preview.map(ImagePreview::values), + user_gutter_width: self.user_gutter_width.unwrap_or(30), } } } diff --git a/src/message/mod.rs b/src/message/mod.rs index c17dbce..0cd49f4 100644 --- a/src/message/mod.rs +++ b/src/message/mod.rs @@ -120,14 +120,10 @@ const BOLD_STYLE: Style = Style { underline_color: None, }; -const USER_GUTTER: usize = 30; const TIME_GUTTER: usize = 12; const READ_GUTTER: usize = 5; const MIN_MSG_LEN: usize = 30; -const USER_GUTTER_EMPTY: &str = " "; -const USER_GUTTER_EMPTY_SPAN: Span<'static> = span_static(USER_GUTTER_EMPTY); - const TIME_GUTTER_EMPTY: &str = " "; const TIME_GUTTER_EMPTY_SPAN: Span<'static> = span_static(TIME_GUTTER_EMPTY); @@ -576,10 +572,13 @@ impl<'a> MessageFormatter<'a> { text.lines.push(Line::from(vec![leading, date, trailing])); } + let user_gutter_empty_span = + space_span(self.settings.tunables.user_gutter_width, Style::default()); + match self.cols { MessageColumns::Four => { let settings = self.settings; - let user = self.user.take().unwrap_or(USER_GUTTER_EMPTY_SPAN); + let user = self.user.take().unwrap_or(user_gutter_empty_span); let time = self.time.take().unwrap_or(TIME_GUTTER_EMPTY_SPAN); let mut line = vec![user]; @@ -604,7 +603,7 @@ impl<'a> MessageFormatter<'a> { text.lines.push(Line::from(line)) }, MessageColumns::Three => { - let user = self.user.take().unwrap_or(USER_GUTTER_EMPTY_SPAN); + let user = self.user.take().unwrap_or(user_gutter_empty_span); let time = self.time.take().unwrap_or_else(|| Span::from("")); let mut line = vec![user]; @@ -614,7 +613,7 @@ impl<'a> MessageFormatter<'a> { text.lines.push(Line::from(line)) }, MessageColumns::Two => { - let user = self.user.take().unwrap_or(USER_GUTTER_EMPTY_SPAN); + let user = self.user.take().unwrap_or(user_gutter_empty_span); let mut line = vec![user]; line.extend(prev_line.spans); @@ -743,28 +742,29 @@ impl Message { Some(prev) if prev.timestamp.same_day(&self.timestamp) => None, _ => self.timestamp.show_date(), }; + let user_gutter = settings.tunables.user_gutter_width; - if USER_GUTTER + TIME_GUTTER + READ_GUTTER + MIN_MSG_LEN <= width && + if user_gutter + TIME_GUTTER + READ_GUTTER + MIN_MSG_LEN <= width && settings.tunables.read_receipt_display { let cols = MessageColumns::Four; - let fill = width - USER_GUTTER - TIME_GUTTER - READ_GUTTER; + let fill = width - user_gutter - TIME_GUTTER - READ_GUTTER; let user = self.show_sender(prev, true, info, settings); let time = self.timestamp.show_time(); let read = info.event_receipts.get(self.event.event_id()).map(|read| read.iter()); MessageFormatter { settings, cols, orig, fill, user, date, time, read } - } else if USER_GUTTER + TIME_GUTTER + MIN_MSG_LEN <= width { + } else if user_gutter + TIME_GUTTER + MIN_MSG_LEN <= width { let cols = MessageColumns::Three; - let fill = width - USER_GUTTER - TIME_GUTTER; + let fill = width - user_gutter - TIME_GUTTER; let user = self.show_sender(prev, true, info, settings); let time = self.timestamp.show_time(); let read = None; MessageFormatter { settings, cols, orig, fill, user, date, time, read } - } else if USER_GUTTER + MIN_MSG_LEN <= width { + } else if user_gutter + MIN_MSG_LEN <= width { let cols = MessageColumns::Two; - let fill = width - USER_GUTTER; + let fill = width - user_gutter; let user = self.show_sender(prev, true, info, settings); let time = None; let read = None; @@ -787,11 +787,13 @@ impl Message { prev: Option<&Message>, vwctx: &ViewportContext, info: &'a RoomInfo, + settings: &'a ApplicationSettings, ) -> Option<(&dyn Protocol, u16, u16)> { let width = vwctx.get_width(); + let user_gutter = settings.tunables.user_gutter_width; // The x position where get_render_format would render the text. - let x = (if USER_GUTTER + MIN_MSG_LEN <= width { - USER_GUTTER + let x = (if user_gutter + MIN_MSG_LEN <= width { + user_gutter } else { 0 }) as u16; @@ -1029,8 +1031,9 @@ impl Message { } let Span { content, style } = self.sender_span(info, settings); - let ((truncated, width), _) = take_width(content, 28); - let padding = 28 - width; + let user_gutter = settings.tunables.user_gutter_width; + let ((truncated, width), _) = take_width(content, user_gutter - 2); + let padding = user_gutter - 2 - width; let sender = if align_right { space(padding) + &truncated + " " diff --git a/src/tests.rs b/src/tests.rs index 08802ed..0adabe3 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -203,6 +203,7 @@ pub fn mock_tunables() -> TunableValues { message_user_color: false, notifications: Notifications { enabled: false, show_message: None }, image_preview: None, + user_gutter_width: 30, } } diff --git a/src/windows/room/scrollback.rs b/src/windows/room/scrollback.rs index 9ca1978..d5a4223 100644 --- a/src/windows/room/scrollback.rs +++ b/src/windows/room/scrollback.rs @@ -1352,7 +1352,7 @@ impl<'a> StatefulWidget for Scrollback<'a> { let txt = item.show(prev, foc && sel, &state.viewctx, info, settings); let mut msg_preview = if picker.is_some() { - item.line_preview(prev, &state.viewctx, info) + item.line_preview(prev, &state.viewctx, info, settings) } else { None };