Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use is_terminal in atty #21010

Merged
merged 1 commit into from
Oct 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions runtime/ops/tty.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.

use std::io::Error;
use std::io::IsTerminal;

use deno_core::error::AnyError;
use deno_core::op2;
use deno_core::OpState;
use deno_core::ResourceHandle;

#[cfg(unix)]
use deno_core::ResourceId;
Expand Down Expand Up @@ -167,24 +165,7 @@ fn op_stdin_set_raw(
#[op2(fast)]
fn op_isatty(state: &mut OpState, rid: u32) -> Result<bool, AnyError> {
let handle = state.resource_table.get_handle(rid)?;
// TODO(mmastrac): this can migrate to the deno_core implementation when it lands
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,
})
Ok(handle.is_terminal())
}

#[op2(fast)]
Expand Down