use std::fmt;
use crate::formatter::{get_term_style, style::Stylesheet};
pub struct DisplayList<'a> {
pub body: Vec<DisplayLine<'a>>,
pub stylesheet: Box<dyn Stylesheet>,
pub anonymized_line_numbers: bool,
}
impl<'a> From<Vec<DisplayLine<'a>>> for DisplayList<'a> {
fn from(body: Vec<DisplayLine<'a>>) -> DisplayList<'a> {
Self {
body,
anonymized_line_numbers: false,
stylesheet: get_term_style(false),
}
}
}
impl<'a> PartialEq for DisplayList<'a> {
fn eq(&self, other: &Self) -> bool {
self.body == other.body && self.anonymized_line_numbers == other.anonymized_line_numbers
}
}
impl<'a> fmt::Debug for DisplayList<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("DisplayList")
.field("body", &self.body)
.field("anonymized_line_numbers", &self.anonymized_line_numbers)
.finish()
}
}
#[derive(Debug, Default, Copy, Clone)]
pub struct FormatOptions {
pub color: bool,
pub anonymized_line_numbers: bool,
}
#[derive(Debug, PartialEq)]
pub struct Annotation<'a> {
pub annotation_type: DisplayAnnotationType,
pub id: Option<&'a str>,
pub label: Vec<DisplayTextFragment<'a>>,
}
#[derive(Debug, PartialEq)]
pub enum DisplayLine<'a> {
Source {
lineno: Option<usize>,
inline_marks: Vec<DisplayMark>,
line: DisplaySourceLine<'a>,
},
Fold { inline_marks: Vec<DisplayMark> },
Raw(DisplayRawLine<'a>),
}
#[derive(Debug, PartialEq)]
pub enum DisplaySourceLine<'a> {
Content {
text: &'a str,
range: (usize, usize), },
Annotation {
annotation: Annotation<'a>,
range: (usize, usize),
annotation_type: DisplayAnnotationType,
annotation_part: DisplayAnnotationPart,
},
Empty,
}
#[derive(Debug, PartialEq)]
pub enum DisplayRawLine<'a> {
Origin {
path: &'a str,
pos: Option<(usize, usize)>,
header_type: DisplayHeaderType,
},
Annotation {
annotation: Annotation<'a>,
source_aligned: bool,
continuation: bool,
},
}
#[derive(Debug, PartialEq)]
pub struct DisplayTextFragment<'a> {
pub content: &'a str,
pub style: DisplayTextStyle,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum DisplayTextStyle {
Regular,
Emphasis,
}
#[derive(Debug, Clone, PartialEq)]
pub enum DisplayAnnotationPart {
Standalone,
LabelContinuation,
Consequitive,
MultilineStart,
MultilineEnd,
}
#[derive(Debug, Clone, PartialEq)]
pub struct DisplayMark {
pub mark_type: DisplayMarkType,
pub annotation_type: DisplayAnnotationType,
}
#[derive(Debug, Clone, PartialEq)]
pub enum DisplayMarkType {
AnnotationThrough,
AnnotationStart,
}
#[derive(Debug, Clone, PartialEq)]
pub enum DisplayAnnotationType {
None,
Error,
Warning,
Info,
Note,
Help,
}
#[derive(Debug, Clone, PartialEq)]
pub enum DisplayHeaderType {
Initial,
Continuation,
}