Commit 9e40b49e5e
9e40b49e5ee761825bd07fc64e02531d1a389e69
parent: 33d3407694
Unregistered key
VAWVAW <git@nlih.de> · 2025-06-17 01:30 UTC
committer: <noreply@github.com>
Fix display of tabs in code blocks (#463)
Layout: unified · split
docs/iamb.5
+4
| @@ -231,6 +231,10 @@ Possible values are |
| 231 | 231 | Specify the width of the column where usernames are displayed in a room. |
| 232 | 232 | Usernames that are too long are truncated. |
| 233 | 233 | Defaults to 30. |
| 234 | |
| 235 | .It Sy tabstop |
| 236 | Number of spaces that a <Tab> counts for. |
| 237 | Defaults to 4. |
| 234 | 238 | .El |
| 235 | 239 | |
| 236 | 240 | .Ss Example 1: Avoid showing Emojis (useful for terminals w/o support) |
src/config.rs
+4
| @@ -574,6 +574,7 @@ pub struct TunableValues { |
| 574 | 574 | pub image_preview: Option<ImagePreviewValues>, |
| 575 | 575 | pub user_gutter_width: usize, |
| 576 | 576 | pub external_edit_file_suffix: String, |
| 577 | pub tabstop: usize, |
| 577 | 578 | } |
| 578 | 579 | |
| 579 | 580 | #[derive(Clone, Default, Deserialize)] |
| @@ -600,6 +601,7 @@ pub struct Tunables { |
| 600 | 601 | pub image_preview: Option<ImagePreview>, |
| 601 | 602 | pub user_gutter_width: Option<usize>, |
| 602 | 603 | pub external_edit_file_suffix: Option<String>, |
| 604 | pub tabstop: Option<usize>, |
| 603 | 605 | } |
| 604 | 606 | |
| 605 | 607 | impl Tunables { |
| @@ -632,6 +634,7 @@ impl Tunables { |
| 632 | 634 | external_edit_file_suffix: self |
| 633 | 635 | .external_edit_file_suffix |
| 634 | 636 | .or(other.external_edit_file_suffix), |
| 637 | tabstop: self.tabstop.or(other.tabstop), |
| 635 | 638 | } |
| 636 | 639 | } |
| 637 | 640 | |
| @@ -660,6 +663,7 @@ impl Tunables { |
| 660 | 663 | external_edit_file_suffix: self |
| 661 | 664 | .external_edit_file_suffix |
| 662 | 665 | .unwrap_or_else(|| ".md".to_string()), |
| 666 | tabstop: self.tabstop.unwrap_or(4), |
| 663 | 667 | } |
| 664 | 668 | } |
| 665 | 669 | } |
src/message/html.rs
+18 −3
| @@ -1415,13 +1415,14 @@ pub mod tests { |
| 1415 | 1415 | let s = concat!( |
| 1416 | 1416 | "<pre><code class=\"language-rust\">", |
| 1417 | 1417 | "fn hello() -> usize {\n", |
| 1418 | " \t// weired\n", |
| 1418 | 1419 | " return 5;\n", |
| 1419 | 1420 | "}\n", |
| 1420 | 1421 | "</code></pre>\n" |
| 1421 | 1422 | ); |
| 1422 | 1423 | let tree = parse_matrix_html(s); |
| 1423 | 1424 | let text = tree.to_text(25, Style::default(), true, &settings); |
| 1424 | | assert_eq!(text.lines.len(), 5); |
| 1425 | assert_eq!(text.lines.len(), 6); |
| 1425 | 1426 | assert_eq!( |
| 1426 | 1427 | text.lines[0], |
| 1427 | 1428 | Line::from(vec![ |
| @@ -1452,6 +1453,20 @@ pub mod tests { |
| 1452 | 1453 | ); |
| 1453 | 1454 | assert_eq!( |
| 1454 | 1455 | text.lines[2], |
| 1456 | Line::from(vec![ |
| 1457 | Span::raw(line::VERTICAL), |
| 1458 | Span::raw(" "), |
| 1459 | Span::raw(" "), |
| 1460 | Span::raw("/"), |
| 1461 | Span::raw("/"), |
| 1462 | Span::raw(" "), |
| 1463 | Span::raw("weired"), |
| 1464 | Span::raw(" "), |
| 1465 | Span::raw(line::VERTICAL) |
| 1466 | ]) |
| 1467 | ); |
| 1468 | assert_eq!( |
| 1469 | text.lines[3], |
| 1455 | 1470 | Line::from(vec![ |
| 1456 | 1471 | Span::raw(line::VERTICAL), |
| 1457 | 1472 | Span::raw(" "), |
| @@ -1464,7 +1479,7 @@ pub mod tests { |
| 1464 | 1479 | ]) |
| 1465 | 1480 | ); |
| 1466 | 1481 | assert_eq!( |
| 1467 | | text.lines[3], |
| 1482 | text.lines[4], |
| 1468 | 1483 | Line::from(vec![ |
| 1469 | 1484 | Span::raw(line::VERTICAL), |
| 1470 | 1485 | Span::raw("}"), |
| @@ -1473,7 +1488,7 @@ pub mod tests { |
| 1473 | 1488 | ]) |
| 1474 | 1489 | ); |
| 1475 | 1490 | assert_eq!( |
| 1476 | | text.lines[4], |
| 1491 | text.lines[5], |
| 1477 | 1492 | Line::from(vec![ |
| 1478 | 1493 | Span::raw(line::BOTTOM_LEFT), |
| 1479 | 1494 | Span::raw(line::HORIZONTAL.repeat(23)), |
src/message/printer.rs
+9 −1
| @@ -216,6 +216,8 @@ impl<'a> TextPrinter<'a> { |
| 216 | 216 | return; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | let tabstop = self.settings().tunables.tabstop; |
| 220 | |
| 219 | 221 | for mut word in UnicodeSegmentation::split_word_bounds(s) { |
| 220 | 222 | if let "\n" | "\r\n" = word { |
| 221 | 223 | if self.literal { |
| @@ -232,11 +234,17 @@ impl<'a> TextPrinter<'a> { |
| 232 | 234 | continue; |
| 233 | 235 | } |
| 234 | 236 | |
| 235 | | let cow = if self.emoji_shortcodes() { |
| 237 | let mut cow = if self.emoji_shortcodes() { |
| 236 | 238 | Cow::Owned(replace_emojis_in_str(word)) |
| 237 | 239 | } else { |
| 238 | 240 | Cow::Borrowed(word) |
| 239 | 241 | }; |
| 242 | |
| 243 | if cow == "\t" { |
| 244 | let tablen = tabstop - (self.curr_width % tabstop); |
| 245 | cow = Cow::Owned(" ".repeat(tablen)); |
| 246 | } |
| 247 | |
| 240 | 248 | let sw = UnicodeWidthStr::width(cow.as_ref()); |
| 241 | 249 | |
| 242 | 250 | if sw > self.width { |
src/tests.rs
+1
| @@ -198,6 +198,7 @@ pub fn mock_tunables() -> TunableValues { |
| 198 | 198 | }, |
| 199 | 199 | image_preview: None, |
| 200 | 200 | user_gutter_width: 30, |
| 201 | tabstop: 4, |
| 201 | 202 | } |
| 202 | 203 | } |
| 203 | 204 | |