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