Skip to content

Commit

Permalink
refact(std/console/styles): add support_ansi_escape_codes
Browse files Browse the repository at this point in the history
remove `stdout_support_styles` and `stderr_support_styles`
  • Loading branch information
StunxFS committed Dec 22, 2023
1 parent c414e3d commit c5471bb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/rivet/src/prefs/mod.ri
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ pub struct Prefs {
"Force the use of ANSI colors for the error/warning messages,\n"
" or disable them completely."
) {
utils.stderr_support_styles = show_color;
utils.support_ansi_escape_codes = show_color;
}
if verbose := fp.bool_flag("verbose", 'v', "Print additional messages to the console."); verbose {
prefs.is_verbose = true;
Expand Down
14 changes: 7 additions & 7 deletions lib/rivet/src/utils/mod.ri
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import std/console/styles;
pub const LF: uint8 := 10;
pub const CR: uint8 := 13;

pub var mut stderr_support_styles := styles.stderr_support_styles();
pub var mut support_ansi_escape_codes := styles.support_ansi_escape_codes();

pub var tabs_table := [
"",
Expand Down Expand Up @@ -73,32 +73,32 @@ pub func info(msg: string, args: ...traits.Stringable) {

#[inline]
pub func bold(msg: string) -> string {
return if stderr_support_styles { styles.bold(msg) } else { msg };
return if support_ansi_escape_codes { styles.bold(msg) } else { msg };
}

#[inline]
pub func red(msg: string) -> string {
return if stderr_support_styles { styles.red(msg) } else { msg };
return if support_ansi_escape_codes { styles.red(msg) } else { msg };
}

#[inline]
pub func yellow(msg: string) -> string {
return if stderr_support_styles { styles.yellow(msg) } else { msg };
return if support_ansi_escape_codes { styles.yellow(msg) } else { msg };
}

#[inline]
pub func cyan(msg: string) -> string {
return if stderr_support_styles { styles.cyan(msg) } else { msg };
return if support_ansi_escape_codes { styles.cyan(msg) } else { msg };
}

#[inline]
pub func blue(msg: string) -> string {
return if stderr_support_styles { styles.blue(msg) } else { msg };
return if support_ansi_escape_codes { styles.blue(msg) } else { msg };
}

#[inline]
pub func green(msg: string) -> string {
return if stderr_support_styles { styles.green(msg) } else { msg };
return if support_ansi_escape_codes { styles.green(msg) } else { msg };
}

/// Rounds the number `n` up to the next mult
Expand Down
22 changes: 12 additions & 10 deletions lib/std/src/console/styles/mod.ri
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
// Use of this source code is governed by an MIT license that can
// be found in the LICENSE file.

import std/console;

#[inline]
pub func stdout_support_styles() -> bool {
return console.is_atty(1);
}

#[inline]
pub func stderr_support_styles() -> bool {
return console.is_atty(2);
import ../../env;
import ../../console;

#[inline]
pub func support_ansi_escape_codes() -> bool {
if console.is_atty(1) && console.is_atty(2) {
if term := env.get("TERM"); term == "dumb" {
return false;
}
return true;
}
return false;
}

#[inline]
Expand Down

0 comments on commit c5471bb

Please sign in to comment.