#[cfg(feature = "file-picker")]
use gpui::*;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub enum ValidationDisplay {
#[default]
Full,
ColorsOnly,
MessageOnly,
Hidden,
}
#[cfg(feature = "file-picker")]
pub(crate) struct PathHighlight {
pub start: usize,
pub end: usize,
pub color: u32,
}
#[cfg(feature = "file-picker")]
pub(crate) struct PathDisplayInfo {
pub full_text: String,
pub highlights: Vec<PathHighlight>,
pub explanation: Option<(String, u32)>,
}
#[cfg(feature = "file-picker")]
impl PathDisplayInfo {
pub fn new() -> Self {
Self {
full_text: String::new(),
highlights: Vec::new(),
explanation: None,
}
}
pub fn add_segment(&mut self, text: &str, color: u32) {
if !text.is_empty() {
let start = self.full_text.len();
self.full_text.push_str(text);
let end = self.full_text.len();
self.highlights.push(PathHighlight { start, end, color });
}
}
pub fn add_path_prefix(&mut self, text: &str, color: u32) {
let start = self.full_text.len();
self.full_text.push('/');
self.full_text.push_str(text);
let end = self.full_text.len();
self.highlights.push(PathHighlight { start, end, color });
}
pub fn set_explanation(&mut self, msg: &str, color: u32) {
self.explanation = Some((msg.to_string(), color));
}
pub fn to_styled_text(&self) -> StyledText {
let highlights: Vec<(std::ops::Range<usize>, HighlightStyle)> = self
.highlights
.iter()
.map(|h| (h.start..h.end, HighlightStyle::color(rgb(h.color).into())))
.collect();
StyledText::new(self.full_text.clone()).with_highlights(highlights)
}
pub fn is_empty(&self) -> bool {
self.full_text.is_empty()
}
}
#[cfg(feature = "file-picker")]
impl Default for PathDisplayInfo {
fn default() -> Self {
Self::new()
}
}