use crate::fs_utils::{EscapedDisplayText, FilesystemConfig};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct BufferDisplayPath {
value: EscapedDisplayText,
}
impl BufferDisplayPath {
#[must_use]
pub fn from_resolved_path(path: &std::path::Path, config: &FilesystemConfig) -> Self {
let display_path = path
.strip_prefix(&config.workspace_root)
.ok()
.filter(|relative| !relative.as_os_str().is_empty())
.unwrap_or(path);
Self {
value: EscapedDisplayText::from_display_text(display_path.to_string_lossy()),
}
}
#[cfg(test)]
pub(super) fn from_sanitized(value: impl Into<String>) -> Self {
Self {
value: EscapedDisplayText::from_display_text(value.into()),
}
}
#[must_use]
pub fn as_str(&self) -> &str {
self.value.as_str()
}
}