mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-18 13:49:59 +01:00
Add Stdin.isTerminal.
This commit is contained in:
@ -16,6 +16,12 @@ Defaults to `false`.
|
|||||||
|
|
||||||
Sets raw mode on or off.
|
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**()
|
### **readByte**()
|
||||||
|
|
||||||
Reads one byte of input from stdin. Blocks the current fiber until a byte has
|
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 statIsFile(WrenVM* vm);
|
||||||
extern void stdinIsRaw(WrenVM* vm);
|
extern void stdinIsRaw(WrenVM* vm);
|
||||||
extern void stdinIsRawSet(WrenVM* vm);
|
extern void stdinIsRawSet(WrenVM* vm);
|
||||||
|
extern void stdinIsTerminal(WrenVM* vm);
|
||||||
extern void stdinReadStart(WrenVM* vm);
|
extern void stdinReadStart(WrenVM* vm);
|
||||||
extern void stdinReadStop(WrenVM* vm);
|
extern void stdinReadStop(WrenVM* vm);
|
||||||
extern void schedulerCaptureMethods(WrenVM* vm);
|
extern void schedulerCaptureMethods(WrenVM* vm);
|
||||||
@ -147,6 +148,7 @@ static ModuleRegistry modules[] =
|
|||||||
CLASS(Stdin)
|
CLASS(Stdin)
|
||||||
STATIC_METHOD("isRaw", stdinIsRaw)
|
STATIC_METHOD("isRaw", stdinIsRaw)
|
||||||
STATIC_METHOD("isRaw=(_)", stdinIsRawSet)
|
STATIC_METHOD("isRaw=(_)", stdinIsRawSet)
|
||||||
|
STATIC_METHOD("isTerminal", stdinIsTerminal)
|
||||||
STATIC_METHOD("readStart_()", stdinReadStart)
|
STATIC_METHOD("readStart_()", stdinReadStart)
|
||||||
STATIC_METHOD("readStop_()", stdinReadStop)
|
STATIC_METHOD("readStop_()", stdinReadStop)
|
||||||
END_CLASS
|
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,
|
static void allocCallback(uv_handle_t* handle, size_t suggestedSize,
|
||||||
uv_buf_t* buf)
|
uv_buf_t* buf)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -217,6 +217,7 @@ foreign class Stat {
|
|||||||
class Stdin {
|
class Stdin {
|
||||||
foreign static isRaw
|
foreign static isRaw
|
||||||
foreign static isRaw=(value)
|
foreign static isRaw=(value)
|
||||||
|
foreign static isTerminal
|
||||||
|
|
||||||
static readByte() {
|
static readByte() {
|
||||||
return read_ {
|
return read_ {
|
||||||
|
|||||||
@ -219,6 +219,7 @@ static const char* ioModuleSource =
|
|||||||
"class Stdin {\n"
|
"class Stdin {\n"
|
||||||
" foreign static isRaw\n"
|
" foreign static isRaw\n"
|
||||||
" foreign static isRaw=(value)\n"
|
" foreign static isRaw=(value)\n"
|
||||||
|
" foreign static isTerminal\n"
|
||||||
"\n"
|
"\n"
|
||||||
" static readByte() {\n"
|
" static readByte() {\n"
|
||||||
" return read_ {\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