1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#![deny(missing_docs)]
use std::{cmp::Ordering, fmt::Arguments, result::Result as StdResult, str::FromStr};
use tectonic_errors::Error;
pub mod plain;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum MessageKind {
Note,
Warning,
Error,
}
#[repr(usize)]
#[non_exhaustive]
#[derive(Clone, Copy, Eq, Debug)]
pub enum ChatterLevel {
Minimal = 0,
Normal,
}
impl ChatterLevel {
pub fn suppress_message(&self, kind: MessageKind) -> bool {
match self {
ChatterLevel::Normal => false,
ChatterLevel::Minimal => kind == MessageKind::Note,
}
}
}
impl Default for ChatterLevel {
fn default() -> Self {
ChatterLevel::Normal
}
}
impl FromStr for ChatterLevel {
type Err = &'static str;
fn from_str(a_str: &str) -> StdResult<Self, Self::Err> {
match a_str {
"default" => Ok(ChatterLevel::Normal),
"minimal" => Ok(ChatterLevel::Minimal),
_ => Err("unsupported or unknown chatter level"),
}
}
}
impl PartialEq for ChatterLevel {
#[inline]
fn eq(&self, other: &ChatterLevel) -> bool {
*self as usize == *other as usize
}
}
impl PartialOrd for ChatterLevel {
#[inline]
fn partial_cmp(&self, other: &ChatterLevel) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for ChatterLevel {
#[inline]
fn cmp(&self, other: &ChatterLevel) -> Ordering {
(*self as usize).cmp(&(*other as usize))
}
}
pub trait StatusBackend {
fn report(&mut self, kind: MessageKind, args: Arguments, err: Option<&Error>);
fn report_error(&mut self, err: &Error) {
self.report(
MessageKind::Error,
format_args!("an error occurred"),
Some(err),
)
}
fn note_highlighted(&mut self, before: &str, highlighted: &str, after: &str) {
self.report(
MessageKind::Note,
format_args!("{}{}{}", before, highlighted, after),
None,
)
}
fn dump_error_logs(&mut self, output: &[u8]);
}
#[macro_export]
macro_rules! tt_note {
($dest:expr, $( $fmt_args:expr ),*) => {
$dest.report($crate::MessageKind::Note, format_args!($( $fmt_args ),*), None)
};
($dest:expr, $( $fmt_args:expr ),* ; $err:expr) => {
$dest.report($crate::MessageKind::Note, format_args!($( $fmt_args ),*), Some(&$err))
};
}
#[macro_export]
macro_rules! tt_warning {
($dest:expr, $( $fmt_args:expr ),*) => {
$dest.report($crate::MessageKind::Warning, format_args!($( $fmt_args ),*), None)
};
($dest:expr, $( $fmt_args:expr ),* ; $err:expr) => {
$dest.report($crate::MessageKind::Warning, format_args!($( $fmt_args ),*), Some(&$err))
};
}
#[macro_export]
macro_rules! tt_error {
($dest:expr, $( $fmt_args:expr ),*) => {
$dest.report($crate::MessageKind::Error, format_args!($( $fmt_args ),*), None)
};
($dest:expr, $( $fmt_args:expr ),* ; $err:expr) => {
$dest.report($crate::MessageKind::Error, format_args!($( $fmt_args ),*), Some(&$err))
};
}
#[derive(Copy, Clone, Debug, Default)]
pub struct NoopStatusBackend {}
impl StatusBackend for NoopStatusBackend {
fn report(&mut self, _kind: MessageKind, _args: Arguments, _err: Option<&Error>) {}
fn dump_error_logs(&mut self, _output: &[u8]) {}
}