use crate::fs_utils::EscapedDisplayText;
use std::fmt::{Display, Formatter};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct StatusInfoText {
value: String,
}
impl StatusInfoText {
#[must_use]
pub fn trusted_static(text: &'static str) -> Self {
Self {
value: text.to_owned(),
}
}
#[must_use]
pub(crate) const fn trusted_generated(text: String) -> Self {
Self { value: text }
}
#[must_use]
pub fn from_escaped_display(text: &EscapedDisplayText) -> Self {
Self {
value: text.as_str().to_owned(),
}
}
#[must_use]
pub fn escaped_display(text: impl AsRef<str>) -> Self {
let escaped = EscapedDisplayText::from_display_text(text);
Self::from_escaped_display(&escaped)
}
#[must_use]
pub fn as_str(&self) -> &str {
&self.value
}
}
impl Display for StatusInfoText {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
formatter.write_str(self.as_str())
}
}
#[cfg(test)]
mod tests {
use super::StatusInfoText;
#[test]
fn escaped_display_text_is_single_line() {
let status = StatusInfoText::escaped_display("bad\nname\tbidi\u{202E}.txt");
assert_eq!(status.as_str(), "bad\\nname\\tbidi\\u{202E}.txt");
assert!(!status.as_str().contains('\n'));
assert!(!status.as_str().contains('\t'));
assert!(!status.as_str().contains('\u{202E}'));
}
}