summaryrefslogtreecommitdiffstats
path: root/src/util/format.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/format.rs')
-rw-r--r--src/util/format.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/util/format.rs b/src/util/format.rs
index 3079840..3a9bc54 100644
--- a/src/util/format.rs
+++ b/src/util/format.rs
@@ -26,3 +26,27 @@ pub fn mtime_to_string(mtime: time::SystemTime) -> String {
let datetime: chrono::DateTime<chrono::offset::Local> = mtime.into();
datetime.format(MTIME_FORMATTING).to_string()
}
+
+pub fn format_tab_bar_title_string(
+ max_len: usize,
+ number: Option<usize>,
+ title: impl Into<String>,
+) -> String {
+ let title: String = title.into();
+
+ if let Some(number) = number {
+ if title.len() > max_len {
+ format!(
+ "{}: {}…",
+ number + 1,
+ title.chars().take(max_len - 1).collect::<String>()
+ )
+ } else {
+ format!("{}: {}", number + 1, title)
+ }
+ } else if title.len() > max_len {
+ format!("{}…", title.chars().take(max_len - 1).collect::<String>())
+ } else {
+ title.to_string()
+ }
+}