diff options
| author | Max Bernstein <max.bernstein@shopify.com> | 2024-12-09 07:36:17 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-09 10:36:17 -0500 |
| commit | 8010d79bb429ed8dac5244e481ba5ddc108797a2 (patch) | |
| tree | 082bcd25201e03dbe73bf0fd5ff863138975ba73 /yjit/src/utils.rs | |
| parent | b11287706f691bb5fffede44559132544f553d7f (diff) | |
YJIT: Only enable disassembly colors for tty (#12283)
* YJIT: Use fully-qualified name for OPTIONS in get_options!
* YJIT: Only enable disassembly colors for tty
Notes
Notes:
Merged-By: maximecb <maximecb@ruby-lang.org>
Diffstat (limited to 'yjit/src/utils.rs')
| -rw-r--r-- | yjit/src/utils.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/yjit/src/utils.rs b/yjit/src/utils.rs index c4b5fbd2e7..8c4133546d 100644 --- a/yjit/src/utils.rs +++ b/yjit/src/utils.rs @@ -3,6 +3,7 @@ use crate::backend::ir::*; use crate::cruby::*; use std::slice; +use std::os::raw::c_int; /// Trait for casting to [usize] that allows you to say `.as_usize()`. /// Implementation conditional on the cast preserving the numeric value on @@ -239,6 +240,14 @@ pub fn print_str(asm: &mut Assembler, str: &str) { asm.cpop_all(); } +pub fn stdout_supports_colors() -> bool { + // TODO(max): Use std::io::IsTerminal after upgrading Rust to 1.70 + extern "C" { fn isatty(fd: c_int) -> c_int; } + let stdout = 1; + let is_terminal = unsafe { isatty(stdout) } == 1; + is_terminal +} + #[cfg(test)] mod tests { use super::*; |
