Skip to content

Commit

Permalink
Improve single line label rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanzab committed May 18, 2020
1 parent 0c49206 commit 2ab3679
Show file tree
Hide file tree
Showing 18 changed files with 354 additions and 199 deletions.
37 changes: 6 additions & 31 deletions codespan-reporting/src/term/config.rs
Expand Up @@ -32,16 +32,14 @@ impl Default for Config {
}

impl Config {
/// Measure the width of a string, taking into account the tab width.
pub fn width(&self, s: &str) -> usize {
/// Measure the unicode width of a character, taking into account the tab width.
pub fn width(&self, ch: char) -> usize {
use unicode_width::UnicodeWidthChar;

s.chars()
.map(|ch| match ch {
'\t' => self.tab_width,
_ => ch.width().unwrap_or(0),
})
.sum()
match ch {
'\t' => self.tab_width,
_ => ch.width().unwrap_or(0),
}
}

/// Construct a source writer using the current config.
Expand Down Expand Up @@ -281,29 +279,6 @@ pub struct Chars {
pub multi_left: char,
}

impl Chars {
pub fn single_caret_char(&self, label_style: LabelStyle) -> char {
match label_style {
LabelStyle::Primary => self.single_primary_caret,
LabelStyle::Secondary => self.single_secondary_caret,
}
}

pub fn multi_caret_char_start(&self, label_style: LabelStyle) -> char {
match label_style {
LabelStyle::Primary => self.multi_primary_caret_start,
LabelStyle::Secondary => self.multi_secondary_caret_start,
}
}

pub fn multi_caret_char_end(&self, label_style: LabelStyle) -> char {
match label_style {
LabelStyle::Primary => self.multi_primary_caret_end,
LabelStyle::Secondary => self.multi_secondary_caret_end,
}
}
}

impl Default for Chars {
fn default() -> Chars {
Chars {
Expand Down

0 comments on commit 2ab3679

Please sign in to comment.