use {
crate::*,
std::path::PathBuf,
};
#[derive(Debug)]
pub struct Line {
pub item_idx: usize,
pub line_type: LineType,
pub content: TLine,
}
impl Line {
pub fn title_message(&self) -> Option<&str> {
match self.line_type {
LineType::Title(_) => self
.content
.strings
.get(1)
.map(|ts| ts.raw.as_str())
.map(|s| s.trim_start_matches(|c: char| c.is_whitespace() || c == ':')),
_ => None,
}
}
pub fn location(&self) -> Option<&str> {
match self.line_type {
LineType::Location => self.content.strings.get(2).map(|ts| ts.raw.as_str()),
_ => None,
}
}
pub fn location_path(
&self,
mission: &Mission,
) -> Option<PathBuf> {
let location_path = self.location()?;
let mut location_path = PathBuf::from(location_path);
if !location_path.is_absolute() {
location_path = mission.workspace_root.join(location_path);
}
Some(location_path)
}
}
impl WrappableLine for Line {
fn content(&self) -> &TLine {
&self.content
}
fn prefix_cols(&self) -> usize {
self.line_type.cols()
}
}