From 9293d327e0cf765200c3025399a1282032a7983b Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Sat, 9 Nov 2024 23:07:57 +0100 Subject: [PATCH] Truncate long lines --- src/bin/schedule/github_notifications.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/bin/schedule/github_notifications.rs b/src/bin/schedule/github_notifications.rs index 24c4f6f..87c0382 100644 --- a/src/bin/schedule/github_notifications.rs +++ b/src/bin/schedule/github_notifications.rs @@ -41,9 +41,11 @@ impl> Schedule for GithubNotifications { if relevant.is_empty() { return; } + let max_lines = 8; + let max_line_length = 16; let mut lines = vec![]; let mut relevant = relevant.into_iter(); - while lines.len() < 8 { + while lines.len() < max_lines { if let Some(x) = relevant.next() { let url = x.subject.url; let Some(url) = url else { @@ -56,8 +58,10 @@ impl> Schedule for GithubNotifications { continue; } lines.push(format!("{} #{}", parts[5], parts[7])); - if lines.len() < 8 { - lines.push(format!(" {}", x.subject.title)); + if lines.len() < max_lines { + let mut desc = format!(" {}", x.subject.title); + desc.truncate(desc.floor_char_boundary(max_line_length)); + lines.push(desc); } } else { break;