Skip to content

Configurations checking #2292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ getopts = "0.2"
derive-new = "0.5"
cargo_metadata = "0.4"

[dev-dependencies]
lazy_static = "1.0.0"

[target.'cfg(unix)'.dependencies]
libc = "0.2.11"

Expand Down
4 changes: 2 additions & 2 deletions Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,12 +511,12 @@ Maximum length of comments. No effect unless`wrap_comments = true`.

**Note:** A value of `0` results in [`wrap_comments`](#wrap_comments) being applied regardless of a line's width.

#### Comments shorter than `comment_width`:
#### `80` (default; comments shorter than `comment_width`):
```rust
// Lorem ipsum dolor sit amet, consectetur adipiscing elit.
```

#### Comments longer than `comment_width`:
#### `60` (comments longer than `comment_width`):
```rust
// Lorem ipsum dolor sit amet,
// consectetur adipiscing elit.
Expand Down
23 changes: 18 additions & 5 deletions src/rustfmt_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,28 @@ pub fn make_diff(expected: &str, actual: &str, context_size: usize) -> Vec<Misma
results
}

// A representation of how to write output.
pub enum PrintType {
Fancy, // want to output color and the terminal supports it
Basic, // do not want to output color or the terminal does not support color
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nrc: Here's the first set of comments you requested.

After this PR, I'm going to spin up a new one to merge print_diff_fancy and print_diff_basic by adding more implementation to the enum. I think the enum is too abstract like this.

}

impl PrintType {
pub fn get(color: Color) -> Self {
match term::stdout() {
Some(ref t) if use_colored_tty(color) && t.supports_color() => PrintType::Fancy,
_ => PrintType::Basic,
}
}
}

pub fn print_diff<F>(diff: Vec<Mismatch>, get_section_title: F, color: Color)
where
F: Fn(u32) -> String,
{
match term::stdout() {
Some(ref t) if use_colored_tty(color) && t.supports_color() => {
print_diff_fancy(diff, get_section_title, term::stdout().unwrap())
}
_ => print_diff_basic(diff, get_section_title),
match PrintType::get(color) {
PrintType::Fancy => print_diff_fancy(diff, get_section_title, term::stdout().unwrap()),
PrintType::Basic => print_diff_basic(diff, get_section_title),
}
}

Expand Down
Loading