Improved formatting of tab title
This commit is contained in:
parent
cefc6e8705
commit
7f7ec68427
2 changed files with 40 additions and 13 deletions
|
@ -7,6 +7,7 @@ use gpui::{
|
||||||
actions, elements::*, AnyViewHandle, AppContext, Entity, ModelHandle, MutableAppContext, Task,
|
actions, elements::*, AnyViewHandle, AppContext, Entity, ModelHandle, MutableAppContext, Task,
|
||||||
View, ViewContext, ViewHandle,
|
View, ViewContext, ViewHandle,
|
||||||
};
|
};
|
||||||
|
use util::truncate_and_trailoff;
|
||||||
use workspace::searchable::{SearchEvent, SearchOptions, SearchableItem, SearchableItemHandle};
|
use workspace::searchable::{SearchEvent, SearchOptions, SearchableItem, SearchableItemHandle};
|
||||||
use workspace::{Item, Workspace};
|
use workspace::{Item, Workspace};
|
||||||
|
|
||||||
|
@ -253,19 +254,28 @@ impl Item for TerminalContainer {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|fpi| {
|
.map(|fpi| {
|
||||||
format!(
|
format!(
|
||||||
"{} - {}{}",
|
"{} — {}",
|
||||||
fpi.cwd
|
truncate_and_trailoff(
|
||||||
.file_name()
|
&fpi.cwd
|
||||||
.map(|name| name.to_string_lossy().to_string())
|
.file_name()
|
||||||
.unwrap_or_default(),
|
.map(|name| name.to_string_lossy().to_string())
|
||||||
fpi.name,
|
.unwrap_or_default(),
|
||||||
{
|
25
|
||||||
if fpi.argv.len() >= 1 {
|
),
|
||||||
format!(" {}", (&fpi.argv[1..]).join(" "))
|
truncate_and_trailoff(
|
||||||
} else {
|
&{
|
||||||
"".to_string()
|
format!(
|
||||||
}
|
"{}{}",
|
||||||
}
|
fpi.name,
|
||||||
|
if fpi.argv.len() >= 1 {
|
||||||
|
format!(" {}", (&fpi.argv[1..]).join(" "))
|
||||||
|
} else {
|
||||||
|
"".to_string()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
25
|
||||||
|
)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| "Terminal".to_string()),
|
.unwrap_or_else(|| "Terminal".to_string()),
|
||||||
|
|
|
@ -9,6 +9,23 @@ use std::{
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub fn truncate(s: &str, max_chars: usize) -> &str {
|
||||||
|
match s.char_indices().nth(max_chars) {
|
||||||
|
None => s,
|
||||||
|
Some((idx, _)) => &s[..idx],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn truncate_and_trailoff(s: &str, max_chars: usize) -> String {
|
||||||
|
debug_assert!(max_chars >= 5);
|
||||||
|
|
||||||
|
if s.len() > max_chars {
|
||||||
|
format!("{}…", truncate(&s, max_chars.saturating_sub(3)))
|
||||||
|
} else {
|
||||||
|
s.to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn post_inc<T: From<u8> + AddAssign<T> + Copy>(value: &mut T) -> T {
|
pub fn post_inc<T: From<u8> + AddAssign<T> + Copy>(value: &mut T) -> T {
|
||||||
let prev = *value;
|
let prev = *value;
|
||||||
*value += T::from(1);
|
*value += T::from(1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue