Skip to main content

vvv_engine/report/
row.rs

1//! Display rows and their actionable source sites.
2use crate::protocol::display::Line;
3use vvv_core::RelPath;
4
5/// A row: the line to draw, and the source it stands for.
6#[derive(Debug, Clone)]
7pub struct Row {
8    pub line: Line,
9    /// Where the row is, when an interface can act on it.
10    pub source: Option<Source>,
11}
12
13/// The source a row stands for: the file and the line in it.
14#[derive(Debug, Clone, PartialEq, Eq)]
15pub struct Source {
16    pub path: RelPath,
17    pub line: u32,
18}
19
20impl Row {
21    /// A row no renderer can act on.
22    pub fn new(line: Line) -> Self {
23        Self { line, source: None }
24    }
25
26    /// A row that stands for a source.
27    pub fn at(line: Line, path: RelPath, at: u32) -> Self {
28        Self {
29            line,
30            source: Some(Source { path, line: at }),
31        }
32    }
33
34    /// Wrap plain lines as rows no renderer can act on.
35    pub fn wrap(lines: Vec<Line>) -> Vec<Self> {
36        lines.into_iter().map(Self::new).collect()
37    }
38}