Skip to content

Commit

Permalink
Expose tab_width through MietteHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
jlkiri committed Oct 4, 2021
1 parent 5228153 commit cb073dd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ miette::set_hook(Box::new(|_| {
.terminal_links(true)
.unicode(false)
.context_lines(3)
.with_tab_width(4)
.tab_width(4)
.build())
}))

Expand Down
10 changes: 10 additions & 0 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub struct MietteHandlerOpts {
pub(crate) unicode: Option<bool>,
pub(crate) footer: Option<String>,
pub(crate) context_lines: Option<usize>,
pub(crate) tab_width: Option<usize>,
}

impl MietteHandlerOpts {
Expand Down Expand Up @@ -119,6 +120,12 @@ impl MietteHandlerOpts {
self
}

/// Set the displayed tab width in spaces.
pub fn tab_width(mut self, width: usize) -> Self {
self.tab_width = Some(width);
self
}

/// Builds a [MietteHandler] from this builder.
pub fn build(self) -> MietteHandler {
let graphical = self.is_graphical();
Expand Down Expand Up @@ -167,6 +174,9 @@ impl MietteHandlerOpts {
if let Some(context_lines) = self.context_lines {
handler = handler.with_context_lines(context_lines);
}
if let Some(w) = self.tab_width {
handler = handler.tab_width(w);
}
MietteHandler {
inner: Box::new(handler),
}
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/graphical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ impl GraphicalReportHandler {
}
}

/// Replace tabs with spaces.
pub fn with_tab_width(mut self, width: usize) -> Self {
/// Set the displayed tab width in spaces.
pub fn tab_width(mut self, width: usize) -> Self {
self.tab_width = Some(width);
self
}
Expand Down
2 changes: 1 addition & 1 deletion tests/graphical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn fmt_report(diag: Report) -> String {
} else if let Ok(w) = std::env::var("REPLACE_TABS") {
GraphicalReportHandler::new_themed(GraphicalTheme::unicode_nocolor())
.with_width(80)
.with_tab_width(w.parse().expect("Invalid tab width."))
.tab_width(w.parse().expect("Invalid tab width."))
.render_report(&mut out, diag.as_ref())
.unwrap();
} else {
Expand Down

0 comments on commit cb073dd

Please sign in to comment.