1#![feature(const_trait_impl)]
7#![feature(const_default)]
8#![feature(transmute_neo)]
9
10mod descriptor;
12mod metadata;
13mod problem;
14mod section;
15#[cfg(test)]
16mod tests;
17mod update;
18
19use std::{
21 env::args,
22 fs::File,
23 path::PathBuf,
24 sync::LazyLock,
25 time::Instant
26};
27
28use core::fmt::{
30 Debug,
31 Display
32};
33
34use libutils_cage::Cage;
36
37use update::Update;
39
40use libutils_issue::{
42 Issue,
43 Severity
44};
45
46use libutils_console::{
48 Console,
49 Argument,
50 Update as UpdateTrait,
51 Descriptor as DescriptorTrait
52};
53
54use section::Section;
56
57use problem::Problem;
59
60use descriptor::Descriptor;
62
63
64static ARGUMENTS: LazyLock<Vec<Argument>> = LazyLock::new(|| args().map(Argument::from).collect());
70static LAYOUT: Cage<Vec<Section>> = Cage::default();
71static OUTPUT: Cage<String> = Cage::default();
72
73pub struct Terminal;
75
76impl Console for Terminal {
78 fn arguments() -> &'static [Argument] {return ARGUMENTS.as_slice()}
79 fn open(filename: &str) -> Result<impl DescriptorTrait, Issue> {
80 match File::open(PathBuf::from(filename)) {
81 Ok(file) => Ok(Descriptor {
82 file: file
83 }),
84 Err(error) => Err(Issue {
85 name: "Failed to open file",
86 description: Some(error.to_string()),
87 severity: Severity::Error
88 })
89 }
90 }
91 fn problem(issue: Issue, chain: &[&'static str]) -> impl UpdateTrait {
92 LAYOUT.write(|layout| layout.push(Section::Problem(Problem {
93 chain: Vec::from(chain),
94 issue: issue,
95 _at: Instant::now()
96 })));
97 return Update;
98 }
99 fn print(value: impl Display) -> impl UpdateTrait {
100 LAYOUT.write(|layout| layout.push(Section::Display(value.to_string())));
101 return Update;
102 }
103 fn debug(value: impl Debug) -> impl UpdateTrait {
104 LAYOUT.write(|layout| layout.push(Section::Debug(format!("{value:#?}"))));
105 return Update;
106 }
107}