mirror of https://github.com/zkat/miette.git
feat(handler): context lines config support
This commit is contained in:
parent
b10693a91c
commit
b33084bdbf
|
|
@ -25,6 +25,7 @@ pub struct MietteHandlerOpts {
|
||||||
pub(crate) color: Option<bool>,
|
pub(crate) color: Option<bool>,
|
||||||
pub(crate) unicode: Option<bool>,
|
pub(crate) unicode: Option<bool>,
|
||||||
pub(crate) footer: Option<String>,
|
pub(crate) footer: Option<String>,
|
||||||
|
pub(crate) context_lines: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MietteHandlerOpts {
|
impl MietteHandlerOpts {
|
||||||
|
|
@ -99,6 +100,12 @@ impl MietteHandlerOpts {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the number of context lines before and after a span to display.
|
||||||
|
pub fn context_lines(mut self, context_lines: usize) -> Self {
|
||||||
|
self.context_lines = Some(context_lines);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Builds a [MietteHandler] from this builder.
|
/// Builds a [MietteHandler] from this builder.
|
||||||
pub fn build(self) -> MietteHandler {
|
pub fn build(self) -> MietteHandler {
|
||||||
let graphical = self.is_graphical();
|
let graphical = self.is_graphical();
|
||||||
|
|
@ -108,6 +115,9 @@ impl MietteHandlerOpts {
|
||||||
if let Some(footer) = self.footer {
|
if let Some(footer) = self.footer {
|
||||||
handler = handler.with_footer(footer);
|
handler = handler.with_footer(footer);
|
||||||
}
|
}
|
||||||
|
if let Some(context_lines) = self.context_lines {
|
||||||
|
handler = handler.with_context_lines(context_lines);
|
||||||
|
}
|
||||||
MietteHandler {
|
MietteHandler {
|
||||||
inner: Box::new(handler),
|
inner: Box::new(handler),
|
||||||
}
|
}
|
||||||
|
|
@ -141,6 +151,9 @@ impl MietteHandlerOpts {
|
||||||
if let Some(footer) = self.footer {
|
if let Some(footer) = self.footer {
|
||||||
handler = handler.with_footer(footer);
|
handler = handler.with_footer(footer);
|
||||||
}
|
}
|
||||||
|
if let Some(context_lines) = self.context_lines {
|
||||||
|
handler = handler.with_context_lines(context_lines);
|
||||||
|
}
|
||||||
MietteHandler {
|
MietteHandler {
|
||||||
inner: Box::new(handler),
|
inner: Box::new(handler),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue