-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
386 additions
and
178 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ | |
pub mod config; | ||
pub mod error; | ||
pub mod ops; | ||
pub mod shell; | ||
pub mod steps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use std::io::Write; | ||
|
||
use anyhow::Context as _; | ||
pub use termcolor::{Color, ColorChoice}; | ||
use termcolor::{ColorSpec, StandardStream, WriteColor}; | ||
|
||
use crate::error::CargoResult; | ||
|
||
/// Whether to color logged output | ||
fn colorize_stderr() -> ColorChoice { | ||
if concolor_control::get(concolor_control::Stream::Stderr).color() { | ||
ColorChoice::Always | ||
} else { | ||
ColorChoice::Never | ||
} | ||
} | ||
|
||
/// Print a message with a colored title in the style of Cargo shell messages. | ||
pub fn print( | ||
status: &str, | ||
message: impl std::fmt::Display, | ||
color: Color, | ||
justified: bool, | ||
) -> CargoResult<()> { | ||
let color_choice = colorize_stderr(); | ||
let mut output = StandardStream::stderr(color_choice); | ||
|
||
output.set_color(ColorSpec::new().set_fg(Some(color)).set_bold(true))?; | ||
if justified { | ||
write!(output, "{status:>12}")?; | ||
} else { | ||
write!(output, "{}", status)?; | ||
output.set_color(ColorSpec::new().set_bold(true))?; | ||
write!(output, ":")?; | ||
} | ||
output.reset()?; | ||
|
||
writeln!(output, " {message}").with_context(|| "Failed to write message")?; | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Print a styled action message. | ||
pub fn status(action: &str, message: impl std::fmt::Display) -> CargoResult<()> { | ||
print(action, message, Color::Green, true) | ||
} | ||
|
||
/// Print a styled error message. | ||
pub fn error(message: impl std::fmt::Display) -> CargoResult<()> { | ||
print("error", message, Color::Red, false) | ||
} | ||
|
||
/// Print a styled warning message. | ||
pub fn warn(message: impl std::fmt::Display) -> CargoResult<()> { | ||
print("warning", message, Color::Yellow, false) | ||
} | ||
|
||
/// Print a styled warning message. | ||
pub fn note(message: impl std::fmt::Display) -> CargoResult<()> { | ||
print("note", message, Color::Cyan, false) | ||
} | ||
|
||
/// Print a part of a line with formatting | ||
pub fn write_stderr(fragment: impl std::fmt::Display, spec: &ColorSpec) -> CargoResult<()> { | ||
let color_choice = colorize_stderr(); | ||
let mut output = StandardStream::stderr(color_choice); | ||
|
||
output.set_color(spec)?; | ||
write!(output, "{}", fragment)?; | ||
output.reset()?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.