Skip to content

Commit

Permalink
Get rid of NOCOLOR_TMP hack
Browse files Browse the repository at this point in the history
#155 (comment)

It also turns out we're not even using it, but might in the future.
  • Loading branch information
schneems committed Jul 11, 2023
1 parent d333b88 commit 7afdb6c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions commons/src/build_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,15 +474,18 @@ pub mod fmt {
pub(crate) const RED: &str = "\x1B[0;31m";
pub(crate) const YELLOW: &str = "\x1B[0;33m";
pub(crate) const CYAN: &str = "\x1B[0;36m";
// pub(crate) const PURPLE: &str = "\x1B[0;35m"; // magenta

#[allow(dead_code)]
pub(crate) const PURPLE: &str = "\x1B[0;35m"; // magenta

pub(crate) const BOLD_CYAN: &str = "\x1B[1;36m";
pub(crate) const BOLD_PURPLE: &str = "\x1B[1;35m"; // magenta

pub(crate) const DEFAULT_DIM: &str = "\x1B[2;1m"; // Default color but softer/less vibrant
pub(crate) const RESET: &str = "\x1B[0m";
pub(crate) const NOCOLOR: &str = "\x1B[0m\x1B[0m"; //differentiate between color clear and explicit no color
pub(crate) const NOCOLOR_TMP: &str = "🙈🙈🙈"; // Used together with NOCOLOR to act as a placeholder

#[allow(dead_code)]
pub(crate) const NOCOLOR: &str = "\x1B[1;39m"; // Differentiate between color clear and explicit no color https://github.com/heroku/buildpacks-ruby/pull/155#discussion_r1260029915

pub(crate) const HEROKU_COLOR: &str = BOLD_PURPLE;
pub(crate) const VALUE_COLOR: &str = YELLOW;
Expand Down Expand Up @@ -661,16 +664,14 @@ pub mod fmt {
/// Colors with newlines are a problem since the contents stream to git which prepends `remote:` before the `libcnb_test`
/// if we don't clear, then we will colorize output that isn't ours.
///
/// Explicitly uncolored output is handled by a hacky process of treating two color clears as a special case
/// Explicitly uncolored output is handled by treating `\x1b[1;39m` (NOCOLOR) as a distinct case from `\x1b[0m`
pub(crate) fn colorize(color: &str, body: impl AsRef<str>) -> String {
body.as_ref()
.split('\n')
.map(|section| section.replace(NOCOLOR, NOCOLOR_TMP)) // Explicit no-color hack so it's not cleaned up by accident
.map(|section| section.replace(RESET, &format!("{RESET}{color}"))) // Handles nested color
.map(|section| format!("{color}{section}{RESET}")) // Clear after every newline
.map(|section| section.replace(&format!("{RESET}{color}{RESET}"), RESET)) // Reduce useless color
.map(|section| section.replace(&format!("{color}{color}"), color)) // Reduce useless color
.map(|section| section.replace(NOCOLOR_TMP, NOCOLOR)) // Explicit no-color repair
.collect::<Vec<String>>()
.join("\n")
}
Expand Down

0 comments on commit 7afdb6c

Please sign in to comment.