1use once_cell::sync::Lazy;
2use std::fmt;
3
4#[derive(Debug)]
5pub struct FilePosition {
6 url: String,
7 file: Option<String>,
8 source: Option<String>,
9 line: u32,
10 column: u32,
11}
12
13#[derive(Debug)]
14pub struct Position {
15 line: u32,
16 col: u32,
17}
18
19impl fmt::Display for FilePosition {
20 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
21 write!(
22 f,
23 "{:?}:{}:{}:{}:{:?}",
24 self.file, self.line, self.column, self.url, self.source
25 )
26 }
27}
28
29static DEFAULT_INPUT: Lazy<Input> = Lazy::new(Input::default);
30#[derive(Debug, PartialEq, Clone, Default)]
31pub struct Input<'a> {
32 pub css: &'a str,
33 file: Option<String>,
35 id: Option<String>,
36 has_bom: bool,
37 line: u32,
38 column: u32,
39}
40
41impl<'a> Default for &'a Input<'a> {
42 fn default() -> &'a Input<'a> {
43 &DEFAULT_INPUT
44 }
45}
46
47impl<'a> fmt::Display for Input<'a> {
48 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
49 write!(
50 f,
51 "{:?}:{}:{}:{}:{}",
52 self.file, self.line, self.column, self.css, self.has_bom
53 )
54 }
55}
56
57#[derive(Debug)]
58pub struct ProcessOptions {}
59
60impl<'a> Input<'a> {
61 pub fn new(css: &'a str, _opts: Option<ProcessOptions>) -> Input<'a> {
62 Input {
63 css,
64 file: Some(String::new()),
65 id: Some(String::from("123")),
66 has_bom: false,
67 line: 1,
68 column: 1,
69 }
70 }
71
72 pub fn from(&self) -> String {
73 String::from("/home/ai/a.css")
74 }
75
76 pub fn origin(&self, line: u32, column: u32) -> Option<FilePosition> {
77 Some(FilePosition {
78 url: String::from("/home/ai/a.css"),
79 file: Some(String::from("/home/ai/a.css")),
80 source: Some(String::from(".className {}")),
81 line,
82 column,
83 })
84 }
85
86 pub fn from_offset(&self, offset: u32) -> Option<Position> {
87 Some(Position {
88 line: 1,
89 col: offset,
90 })
91 }
92}