Commit 46e081b1e4

46e081b1e4e4964eda42be91b04a7affb099a8a7

parent: 23a729e565

Unregistered key

mordquist <16607572+mordquist@users.noreply.github.com> · 2024-03-24 01:54 UTC
committer: <noreply@github.com>

Support configuring user gutter width (#223)

Layout: unified · split

docs/iamb.5.md +4
@@ -111,6 +111,10 @@ overridden as described in *PROFILES*.
111> *protocol.font_size* is an optional list of two numbers representing font 111> *protocol.font_size* is an optional list of two numbers representing font
112> width and height in pixels. 112> width and height in pixels.
113 113
114**user_gutter_width** (type: usize)
115> Specify the width of the column where usernames are displayed in a room.
116> Usernames that are too long are truncated.
117
114## USER OVERRIDES 118## USER OVERRIDES
115 119
116Overrides are mapped onto matrix User IDs such as _@user:matrix.org_ and are 120Overrides are mapped onto matrix User IDs such as _@user:matrix.org_ and are
src/config.rs +4
@@ -485,6 +485,7 @@ pub struct TunableValues {
485 pub open_command: Option<Vec<String>>, 485 pub open_command: Option<Vec<String>>,
486 pub notifications: Notifications, 486 pub notifications: Notifications,
487 pub image_preview: Option<ImagePreviewValues>, 487 pub image_preview: Option<ImagePreviewValues>,
488 pub user_gutter_width: usize,
488} 489}
489 490
490#[derive(Clone, Default, Deserialize)] 491#[derive(Clone, Default, Deserialize)]
@@ -507,6 +508,7 @@ pub struct Tunables {
507 pub open_command: Option<Vec<String>>, 508 pub open_command: Option<Vec<String>>,
508 pub notifications: Option<Notifications>, 509 pub notifications: Option<Notifications>,
509 pub image_preview: Option<ImagePreview>, 510 pub image_preview: Option<ImagePreview>,
511 pub user_gutter_width: Option<usize>,
510} 512}
511 513
512impl Tunables { 514impl Tunables {
@@ -533,6 +535,7 @@ impl Tunables {
533 open_command: self.open_command.or(other.open_command), 535 open_command: self.open_command.or(other.open_command),
534 notifications: self.notifications.or(other.notifications), 536 notifications: self.notifications.or(other.notifications),
535 image_preview: self.image_preview.or(other.image_preview), 537 image_preview: self.image_preview.or(other.image_preview),
538 user_gutter_width: self.user_gutter_width.or(other.user_gutter_width),
536 } 539 }
537 } 540 }
538 541
@@ -555,6 +558,7 @@ impl Tunables {
555 open_command: self.open_command, 558 open_command: self.open_command,
556 notifications: self.notifications.unwrap_or_default(), 559 notifications: self.notifications.unwrap_or_default(),
557 image_preview: self.image_preview.map(ImagePreview::values), 560 image_preview: self.image_preview.map(ImagePreview::values),
561 user_gutter_width: self.user_gutter_width.unwrap_or(30),
558 } 562 }
559 } 563 }
560} 564}
src/message/mod.rs +20 −17
@@ -120,14 +120,10 @@ const BOLD_STYLE: Style = Style {
120 underline_color: None, 120 underline_color: None,
121}; 121};
122 122
123const USER_GUTTER: usize = 30;
124const TIME_GUTTER: usize = 12; 123const TIME_GUTTER: usize = 12;
125const READ_GUTTER: usize = 5; 124const READ_GUTTER: usize = 5;
126const MIN_MSG_LEN: usize = 30; 125const MIN_MSG_LEN: usize = 30;
127 126
128const USER_GUTTER_EMPTY: &str = " ";
129const USER_GUTTER_EMPTY_SPAN: Span<'static> = span_static(USER_GUTTER_EMPTY);
130
131const TIME_GUTTER_EMPTY: &str = " "; 127const TIME_GUTTER_EMPTY: &str = " ";
132const TIME_GUTTER_EMPTY_SPAN: Span<'static> = span_static(TIME_GUTTER_EMPTY); 128const TIME_GUTTER_EMPTY_SPAN: Span<'static> = span_static(TIME_GUTTER_EMPTY);
133 129
@@ -576,10 +572,13 @@ impl<'a> MessageFormatter<'a> {
576 text.lines.push(Line::from(vec![leading, date, trailing])); 572 text.lines.push(Line::from(vec![leading, date, trailing]));
577 } 573 }
578 574
575 let user_gutter_empty_span =
576 space_span(self.settings.tunables.user_gutter_width, Style::default());
577
579 match self.cols { 578 match self.cols {
580 MessageColumns::Four => { 579 MessageColumns::Four => {
581 let settings = self.settings; 580 let settings = self.settings;
582 let user = self.user.take().unwrap_or(USER_GUTTER_EMPTY_SPAN); 581 let user = self.user.take().unwrap_or(user_gutter_empty_span);
583 let time = self.time.take().unwrap_or(TIME_GUTTER_EMPTY_SPAN); 582 let time = self.time.take().unwrap_or(TIME_GUTTER_EMPTY_SPAN);
584 583
585 let mut line = vec![user]; 584 let mut line = vec![user];
@@ -604,7 +603,7 @@ impl<'a> MessageFormatter<'a> {
604 text.lines.push(Line::from(line)) 603 text.lines.push(Line::from(line))
605 }, 604 },
606 MessageColumns::Three => { 605 MessageColumns::Three => {
607 let user = self.user.take().unwrap_or(USER_GUTTER_EMPTY_SPAN); 606 let user = self.user.take().unwrap_or(user_gutter_empty_span);
608 let time = self.time.take().unwrap_or_else(|| Span::from("")); 607 let time = self.time.take().unwrap_or_else(|| Span::from(""));
609 608
610 let mut line = vec![user]; 609 let mut line = vec![user];
@@ -614,7 +613,7 @@ impl<'a> MessageFormatter<'a> {
614 text.lines.push(Line::from(line)) 613 text.lines.push(Line::from(line))
615 }, 614 },
616 MessageColumns::Two => { 615 MessageColumns::Two => {
617 let user = self.user.take().unwrap_or(USER_GUTTER_EMPTY_SPAN); 616 let user = self.user.take().unwrap_or(user_gutter_empty_span);
618 let mut line = vec![user]; 617 let mut line = vec![user];
619 line.extend(prev_line.spans); 618 line.extend(prev_line.spans);
620 619
@@ -743,28 +742,29 @@ impl Message {
743 Some(prev) if prev.timestamp.same_day(&self.timestamp) => None, 742 Some(prev) if prev.timestamp.same_day(&self.timestamp) => None,
744 _ => self.timestamp.show_date(), 743 _ => self.timestamp.show_date(),
745 }; 744 };
745 let user_gutter = settings.tunables.user_gutter_width;
746 746
747 if USER_GUTTER + TIME_GUTTER + READ_GUTTER + MIN_MSG_LEN <= width && 747 if user_gutter + TIME_GUTTER + READ_GUTTER + MIN_MSG_LEN <= width &&
748 settings.tunables.read_receipt_display 748 settings.tunables.read_receipt_display
749 { 749 {
750 let cols = MessageColumns::Four; 750 let cols = MessageColumns::Four;
751 let fill = width - USER_GUTTER - TIME_GUTTER - READ_GUTTER; 751 let fill = width - user_gutter - TIME_GUTTER - READ_GUTTER;
752 let user = self.show_sender(prev, true, info, settings); 752 let user = self.show_sender(prev, true, info, settings);
753 let time = self.timestamp.show_time(); 753 let time = self.timestamp.show_time();
754 let read = info.event_receipts.get(self.event.event_id()).map(|read| read.iter()); 754 let read = info.event_receipts.get(self.event.event_id()).map(|read| read.iter());
755 755
756 MessageFormatter { settings, cols, orig, fill, user, date, time, read } 756 MessageFormatter { settings, cols, orig, fill, user, date, time, read }
757 } else if USER_GUTTER + TIME_GUTTER + MIN_MSG_LEN <= width { 757 } else if user_gutter + TIME_GUTTER + MIN_MSG_LEN <= width {
758 let cols = MessageColumns::Three; 758 let cols = MessageColumns::Three;
759 let fill = width - USER_GUTTER - TIME_GUTTER; 759 let fill = width - user_gutter - TIME_GUTTER;
760 let user = self.show_sender(prev, true, info, settings); 760 let user = self.show_sender(prev, true, info, settings);
761 let time = self.timestamp.show_time(); 761 let time = self.timestamp.show_time();
762 let read = None; 762 let read = None;
763 763
764 MessageFormatter { settings, cols, orig, fill, user, date, time, read } 764 MessageFormatter { settings, cols, orig, fill, user, date, time, read }
765 } else if USER_GUTTER + MIN_MSG_LEN <= width { 765 } else if user_gutter + MIN_MSG_LEN <= width {
766 let cols = MessageColumns::Two; 766 let cols = MessageColumns::Two;
767 let fill = width - USER_GUTTER; 767 let fill = width - user_gutter;
768 let user = self.show_sender(prev, true, info, settings); 768 let user = self.show_sender(prev, true, info, settings);
769 let time = None; 769 let time = None;
770 let read = None; 770 let read = None;
@@ -787,11 +787,13 @@ impl Message {
787 prev: Option<&Message>, 787 prev: Option<&Message>,
788 vwctx: &ViewportContext<MessageCursor>, 788 vwctx: &ViewportContext<MessageCursor>,
789 info: &'a RoomInfo, 789 info: &'a RoomInfo,
790 settings: &'a ApplicationSettings,
790 ) -> Option<(&dyn Protocol, u16, u16)> { 791 ) -> Option<(&dyn Protocol, u16, u16)> {
791 let width = vwctx.get_width(); 792 let width = vwctx.get_width();
793 let user_gutter = settings.tunables.user_gutter_width;
792 // The x position where get_render_format would render the text. 794 // The x position where get_render_format would render the text.
793 let x = (if USER_GUTTER + MIN_MSG_LEN <= width { 795 let x = (if user_gutter + MIN_MSG_LEN <= width {
794 USER_GUTTER 796 user_gutter
795 } else { 797 } else {
796 0 798 0
797 }) as u16; 799 }) as u16;
@@ -1029,8 +1031,9 @@ impl Message {
1029 } 1031 }
1030 1032
1031 let Span { content, style } = self.sender_span(info, settings); 1033 let Span { content, style } = self.sender_span(info, settings);
1032 let ((truncated, width), _) = take_width(content, 28); 1034 let user_gutter = settings.tunables.user_gutter_width;
1033 let padding = 28 - width; 1035 let ((truncated, width), _) = take_width(content, user_gutter - 2);
1036 let padding = user_gutter - 2 - width;
1034 1037
1035 let sender = if align_right { 1038 let sender = if align_right {
1036 space(padding) + &truncated + " " 1039 space(padding) + &truncated + " "
src/tests.rs +1
@@ -203,6 +203,7 @@ pub fn mock_tunables() -> TunableValues {
203 message_user_color: false, 203 message_user_color: false,
204 notifications: Notifications { enabled: false, show_message: None }, 204 notifications: Notifications { enabled: false, show_message: None },
205 image_preview: None, 205 image_preview: None,
206 user_gutter_width: 30,
206 } 207 }
207} 208}
208 209
src/windows/room/scrollback.rs +1 −1
@@ -1352,7 +1352,7 @@ impl<'a> StatefulWidget for Scrollback<'a> {
1352 let txt = item.show(prev, foc && sel, &state.viewctx, info, settings); 1352 let txt = item.show(prev, foc && sel, &state.viewctx, info, settings);
1353 1353
1354 let mut msg_preview = if picker.is_some() { 1354 let mut msg_preview = if picker.is_some() {
1355 item.line_preview(prev, &state.viewctx, info) 1355 item.line_preview(prev, &state.viewctx, info, settings)
1356 } else { 1356 } else {
1357 None 1357 None
1358 }; 1358 };