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