mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 06:08:41 +01:00
Add Stdin.isTerminal.
This commit is contained in:
@ -16,6 +16,12 @@ Defaults to `false`.
|
||||
|
||||
Sets raw mode on or off.
|
||||
|
||||
### **isTerminal**
|
||||
|
||||
Returns `true` if Stdin is connected to a "TTY". This is true when the user is
|
||||
running Wren in an interactive terminal, and false if it its input is coming
|
||||
from a pipe.
|
||||
|
||||
### **readByte**()
|
||||
|
||||
Reads one byte of input from stdin. Blocks the current fiber until a byte has
|
||||
|
||||
@ -39,6 +39,7 @@ extern void statIsDirectory(WrenVM* vm);
|
||||
extern void statIsFile(WrenVM* vm);
|
||||
extern void stdinIsRaw(WrenVM* vm);
|
||||
extern void stdinIsRawSet(WrenVM* vm);
|
||||
extern void stdinIsTerminal(WrenVM* vm);
|
||||
extern void stdinReadStart(WrenVM* vm);
|
||||
extern void stdinReadStop(WrenVM* vm);
|
||||
extern void schedulerCaptureMethods(WrenVM* vm);
|
||||
@ -147,6 +148,7 @@ static ModuleRegistry modules[] =
|
||||
CLASS(Stdin)
|
||||
STATIC_METHOD("isRaw", stdinIsRaw)
|
||||
STATIC_METHOD("isRaw=(_)", stdinIsRawSet)
|
||||
STATIC_METHOD("isTerminal", stdinIsTerminal)
|
||||
STATIC_METHOD("readStart_()", stdinReadStart)
|
||||
STATIC_METHOD("readStop_()", stdinReadStop)
|
||||
END_CLASS
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -217,6 +217,7 @@ foreign class Stat {
|
||||
class Stdin {
|
||||
foreign static isRaw
|
||||
foreign static isRaw=(value)
|
||||
foreign static isTerminal
|
||||
|
||||
static readByte() {
|
||||
return read_ {
|
||||
|
||||
@ -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"
|
||||
|
||||
4
test/io/stdin/is_terminal.wren
Normal file
4
test/io/stdin/is_terminal.wren
Normal file
@ -0,0 +1,4 @@
|
||||
import "io" for Stdin
|
||||
|
||||
// The tests aren't run in a terminal.
|
||||
System.print(Stdin.isTerminal) // expect: false
|
||||
Reference in New Issue
Block a user