diff options
author | Marvin Hagemeister <marvin@deno.com> | 2024-07-19 12:39:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-19 12:39:05 +0200 |
commit | ee2e6933403811d398540e0e8275b2d216546dd8 (patch) | |
tree | 4ed2944dfbc516ea127c4bee50cc771ac12f902d /runtime/ops | |
parent | 76b8ecbb6d8c07d29c34fb0b301cc3bf3351e3aa (diff) |
fix(node): support `tty.hasColors()` and `tty.getColorDepth()` (#24619)
This PR adds support for
[`tty.WriteStream.prototype.hasColors()`](https://nodejs.org/api/tty.html#writestreamhascolorscount-env)
and
[`tty.WriteStream.prototype.getColorDepth()`](https://nodejs.org/api/tty.html#writestreamgetcolordepthenv).
I couldn't find any usage on GitHub which passes parameters to it.
Therefore I've skipped adding support for the `env` parameter to keep
our snapshot size small.
Based on https://github.com/denoland/deno_terminal/pull/3
Fixes https://github.com/denoland/deno/issues/24616
Diffstat (limited to 'runtime/ops')
-rw-r--r-- | runtime/ops/bootstrap.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/runtime/ops/bootstrap.rs b/runtime/ops/bootstrap.rs index c5c193ef3..997bebd76 100644 --- a/runtime/ops/bootstrap.rs +++ b/runtime/ops/bootstrap.rs @@ -2,6 +2,7 @@ use deno_core::op2; use deno_core::OpState; +use deno_terminal::colors::ColorLevel; use serde::Serialize; use crate::BootstrapOptions; @@ -16,6 +17,7 @@ deno_core::extension!( op_bootstrap_language, op_bootstrap_log_level, op_bootstrap_no_color, + op_bootstrap_color_depth, op_bootstrap_is_stdout_tty, op_bootstrap_is_stderr_tty, op_bootstrap_unstable_args, @@ -127,6 +129,17 @@ pub fn op_bootstrap_no_color(state: &mut OpState) -> bool { } #[op2(fast)] +pub fn op_bootstrap_color_depth(state: &mut OpState) -> i32 { + let options = state.borrow::<BootstrapOptions>(); + match options.color_level { + ColorLevel::None => 1, + ColorLevel::Ansi => 4, + ColorLevel::Ansi256 => 8, + ColorLevel::TrueColor => 24, + } +} + +#[op2(fast)] pub fn op_bootstrap_is_stdout_tty(state: &mut OpState) -> bool { let options = state.borrow::<BootstrapOptions>(); options.is_stdout_tty |