mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
chore: use is_terminal in atty (#21010)
This commit is contained in:
parent
857e0841c0
commit
f3b580d001
1 changed files with 1 additions and 20 deletions
|
@ -1,12 +1,10 @@
|
||||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
use std::io::Error;
|
use std::io::Error;
|
||||||
use std::io::IsTerminal;
|
|
||||||
|
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::op2;
|
use deno_core::op2;
|
||||||
use deno_core::OpState;
|
use deno_core::OpState;
|
||||||
use deno_core::ResourceHandle;
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use deno_core::ResourceId;
|
use deno_core::ResourceId;
|
||||||
|
@ -167,24 +165,7 @@ fn op_stdin_set_raw(
|
||||||
#[op2(fast)]
|
#[op2(fast)]
|
||||||
fn op_isatty(state: &mut OpState, rid: u32) -> Result<bool, AnyError> {
|
fn op_isatty(state: &mut OpState, rid: u32) -> Result<bool, AnyError> {
|
||||||
let handle = state.resource_table.get_handle(rid)?;
|
let handle = state.resource_table.get_handle(rid)?;
|
||||||
// TODO(mmastrac): this can migrate to the deno_core implementation when it lands
|
Ok(handle.is_terminal())
|
||||||
Ok(match handle {
|
|
||||||
ResourceHandle::Fd(fd) if handle.is_valid() => {
|
|
||||||
#[cfg(windows)]
|
|
||||||
{
|
|
||||||
// SAFETY: The resource remains open for the for the duration of borrow_raw
|
|
||||||
unsafe {
|
|
||||||
std::os::windows::io::BorrowedHandle::borrow_raw(fd).is_terminal()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[cfg(unix)]
|
|
||||||
{
|
|
||||||
// SAFETY: The resource remains open for the for the duration of borrow_raw
|
|
||||||
unsafe { std::os::fd::BorrowedFd::borrow_raw(fd).is_terminal() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => false,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op2(fast)]
|
#[op2(fast)]
|
||||||
|
|
Loading…
Reference in a new issue