alma 0.1.1

A Bevy-native modal text editor with Vim-style navigation.
Documentation
//! Sanitized buffer path display values for status rendering.

use crate::fs_utils::{EscapedDisplayText, FilesystemConfig};

/// User-facing buffer path display value.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct BufferDisplayPath {
    /// Sanitized path text for UI status messages.
    value: EscapedDisplayText,
}

impl BufferDisplayPath {
    /// Builds a display path from a policy-resolved path.
    #[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()),
        }
    }

    /// Builds a display path for tests and already-sanitized path labels.
    #[cfg(test)]
    pub(super) fn from_sanitized(value: impl Into<String>) -> Self {
        Self {
            value: EscapedDisplayText::from_display_text(value.into()),
        }
    }

    /// Returns the sanitized UI path text.
    #[must_use]
    pub fn as_str(&self) -> &str {
        self.value.as_str()
    }
}