Skip to main content

codeframe/
codeframe_builder.rs

1//! Pretty Capture codeframes
2//!
3//! Ex:
4//! let raw_lines = "let a: i64 = 12;";
5//! let codeframe = Codeframe::new(raw_lines, 1).set_color("red").capture();
6//!
7//!
8//! Colors Supported
9//! Black
10//! Red
11//! Green
12//! Yellow
13//! Blue
14//! Magenta or (Purple)
15//! Cyan
16//! White
17
18use crate::capture;
19use crate::Color;
20
21pub struct Codeframe {
22    color: Color,
23    line: i64,
24    raw_lines: String,
25}
26
27impl Codeframe {
28    pub fn new(raw_lines: String, line: i64) -> Codeframe {
29        Codeframe {
30            color: Color::Red,
31            line,
32            raw_lines,
33        }
34    }
35
36    pub fn set_color(mut self, color: Color) -> Self {
37        self.color = color;
38        self
39    }
40
41    pub fn capture(self) -> Option<String> {
42        let vec_lines = self.raw_lines.split('\n').map(|s| s.to_owned()).collect();
43        capture::capture_codeframe(vec_lines, self.line, self.color)
44    }
45}