mod console;
mod diff;
mod layout;
mod problem;
use std::{
env::{
args,
vars
},
collections::HashMap as Map,
io::{
stderr,
Write
}
};
use crate::{
cage::Cage,
report::ToIssue
};
use diff::Diff;
use layout::Layout;
pub use problem::Problem;
pub use console::Console;
pub static TERMINAL: Cage<Terminal> = Cage::new(Terminal {
layout: Layout {..},
stderr: String::new()
});
pub struct Terminal {
layout: Layout,
stderr: String
}
impl Console for Terminal {
fn arguments(&self) -> Vec<String> {args().collect()}
fn environment(&self) -> Map<String, String> {vars().collect()}
#[inline]
fn render(&mut self) -> () {
let content = self.layout.view();
stderr().lock().write(<Diff as Into<Vec<u8>>>::into(Diff::new(&self.stderr, &content)).as_ref()).unwrap();
self.stderr = content;
}
#[inline]
fn error<Object: ToIssue>(&mut self, problem: &Problem<Object>) -> () {
self.layout.problems.push(Problem {
chain: problem.chain.clone(),
at: problem.at,
object: problem.object.to_issue()
});
self.render();
}
}