diff --git a/src/handler.rs b/src/handler.rs index b47a37f..c11a2de 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -25,6 +25,7 @@ pub struct MietteHandlerOpts { pub(crate) color: Option, pub(crate) unicode: Option, pub(crate) footer: Option, + pub(crate) context_lines: Option, } impl MietteHandlerOpts { @@ -99,6 +100,12 @@ impl MietteHandlerOpts { 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. pub fn build(self) -> MietteHandler { let graphical = self.is_graphical(); @@ -108,6 +115,9 @@ impl MietteHandlerOpts { if let Some(footer) = self.footer { handler = handler.with_footer(footer); } + if let Some(context_lines) = self.context_lines { + handler = handler.with_context_lines(context_lines); + } MietteHandler { inner: Box::new(handler), } @@ -141,6 +151,9 @@ impl MietteHandlerOpts { if let Some(footer) = self.footer { handler = handler.with_footer(footer); } + if let Some(context_lines) = self.context_lines { + handler = handler.with_context_lines(context_lines); + } MietteHandler { inner: Box::new(handler), }