feat: add Stdin.isTerminal method to detect TTY connection

Add a new `isTerminal` static method to the Stdin class that returns `true` when
stdin is connected to a TTY (interactive terminal) and `false` when input comes
from a pipe. Implementation uses libuv's `uv_guess_handle` to check the stdin
descriptor. Includes documentation, foreign method declaration, module
registration, and a test expecting `false` since tests run non-interactively.
This commit is contained in:
Bob Nystrom
2016-05-21 19:51:11 +00:00
parent 95ef1a2814
commit 67bf74777c
6 changed files with 20 additions and 0 deletions
+6
View File
@@ -539,6 +539,12 @@ void stdinIsRawSet(WrenVM* vm)
}
}
void stdinIsTerminal(WrenVM* vm)
{
initStdin();
wrenSetSlotBool(vm, 0, uv_guess_handle(stdinDescriptor) == UV_TTY);
}
static void allocCallback(uv_handle_t* handle, size_t suggestedSize,
uv_buf_t* buf)
{
+1
View File
@@ -217,6 +217,7 @@ foreign class Stat {
class Stdin {
foreign static isRaw
foreign static isRaw=(value)
foreign static isTerminal
static readByte() {
return read_ {
+1
View File
@@ -219,6 +219,7 @@ static const char* ioModuleSource =
"class Stdin {\n"
" foreign static isRaw\n"
" foreign static isRaw=(value)\n"
" foreign static isTerminal\n"
"\n"
" static readByte() {\n"
" return read_ {\n"