-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add IsTerminal
trait to determine if a descriptor or handle is a terminal
#98033
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
2202b56
to
321f20c
Compare
This comment has been minimized.
This comment has been minimized.
857c920
to
08f4705
Compare
This comment has been minimized.
This comment has been minimized.
a0faee9
to
920f59b
Compare
IsTerminal
trait with implementations for AsFd
and AsHandle
If we had the view-from-borrowed thing then we don't need the sealing complications and instead one would do |
I just finished implementing sealing after all, which turned out to be possible. |
This could also be a portability hazard. On unix you can now do I think it would be better if we added let is_terminal = false;
#[cfg(windows)]
let is_terminal = stdin.as_view::<File>().is_terminal()?;
#[cfg(unix)]
let is_terminal = stdin.as_view::<File>().is_terminal()?; This isn't too terrible since one doesn't need |
@the8472 I continue to be quite skeptical of the " However, we could change this to implement |
I have shifted my position a bit, wrappers should have to explicitly opt-in to this kind of conversion but I see I think the conversion is better because we have those structs and useful methods implemented on them anyway. Similarly something might pass a socket as std-in and if you want to do socket-ops on it you need to borrow it as a But maybe you're right and this is a mistake of the past and the basic operations should have been implemented on
Not how I'd do it, but that works too. |
d105439
to
0fc6022
Compare
IsTerminal
trait with implementations for AsFd
and AsHandle
IsTerminal
trait to determine if a descriptor or handle is a terminal
This comment has been minimized.
This comment has been minimized.
… r=thomcc Add `IsTerminal` trait to determine if a descriptor or handle is a terminal The UNIX implementation uses `isatty`. The Windows implementation uses the same logic the `atty` crate uses, including the hack needed to detect msys terminals. Implement this trait for `Stdin`/`Stdout`/`Stderr`/`File` on all platforms. On Unix, implement it for `BorrowedFd`/`OwnedFd`. On Windows, implement it for `BorrowedHandle`/`OwnedHandle`. Based on rust-lang#91121 Co-authored-by: Matt Wilkinson <[email protected]>
@bors r- rollup=iffy failed in a rollup |
…rminal The UNIX and WASI implementations use `isatty`. The Windows implementation uses the same logic the `atty` crate uses, including the hack needed to detect msys terminals. Implement this trait for `File` and for `Stdin`/`Stdout`/`Stderr` and their locked counterparts on all platforms. On UNIX and WASI, implement it for `BorrowedFd`/`OwnedFd`. On Windows, implement it for `BorrowedHandle`/`OwnedHandle`. Based on rust-lang#91121 Co-authored-by: Matt Wilkinson <[email protected]>
If a process has no console, it'll have NULL in place of a console handle, so return early with `false` in that case without making any OS calls.
Rather than referencing a slice's pointer and then creating a new slice with a longer length, offset from the base structure pointer instead. This makes some choices of Rust semantics happier.
ef009b6
to
97d438c
Compare
☀️ Test successful - checks-actions |
Finished benchmarking commit (8154955): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Footnotes |
The UNIX implementation uses
isatty
. The Windows implementation usesthe same logic the
atty
crate uses, including the hack needed todetect msys terminals.
Implement this trait for
Stdin
/Stdout
/Stderr
/File
on allplatforms. On Unix, implement it for
BorrowedFd
/OwnedFd
. On Windows,implement it for
BorrowedHandle
/OwnedHandle
.Based on #91121
Co-authored-by: Matt Wilkinson [email protected]