Name session checkpoints by their session title
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -552,8 +552,7 @@ impl App {
|
||||
false
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn session_title(&self, session_id: i32) -> Option<String> {
|
||||
pub(super) fn session_title(&self, session_id: i32) -> Option<String> {
|
||||
self.projects
|
||||
.iter()
|
||||
.flat_map(|project| &project.sessions)
|
||||
|
||||
@@ -417,9 +417,16 @@ impl App {
|
||||
let mut rows = column![].spacing(7);
|
||||
for entry in &usage.entries {
|
||||
let path = entry.path.clone();
|
||||
let label = entry
|
||||
.session
|
||||
.and_then(|id| self.session_title(id))
|
||||
.map_or_else(
|
||||
|| entry.name.clone(),
|
||||
|title| format!("{}: {}", entry.name, shorten(&title)),
|
||||
);
|
||||
rows = rows.push(
|
||||
row![
|
||||
text(entry.name.clone()).size(12),
|
||||
text(label).size(12),
|
||||
Space::with_width(Length::Fill),
|
||||
text(format!(
|
||||
"{} · {} old",
|
||||
@@ -499,6 +506,15 @@ const AGE_COLORS: [Color; 5] = [
|
||||
Color::from_rgb(0.45, 0.45, 0.48),
|
||||
];
|
||||
|
||||
/// Keeps a long session title from crowding out the size and the action.
|
||||
fn shorten(title: &str) -> String {
|
||||
const LIMIT: usize = 44;
|
||||
if title.chars().count() <= LIMIT {
|
||||
return title.to_owned();
|
||||
}
|
||||
title.chars().take(LIMIT - 1).chain(['…']).collect()
|
||||
}
|
||||
|
||||
fn portion(bytes: u64, capacity: u64) -> u16 {
|
||||
((bytes.saturating_mul(1000) / capacity.max(1)) as u16).max(1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user