1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#include <node_stdio.h>
#include <platform_win32.h>
#include <v8.h>
using namespace v8;
namespace node {
NO_IMPL(void, Stdio::DisableRawMode, , int fd);
NO_IMPL(void, Stdio::Flush, , );
NO_IMPL(static Handle<Value>, OpenStdin, RET_V8UNDEFINED, const Arguments& args);
NO_IMPL(static Handle<Value>, IsStdinBlocking, RET_V8FALSE, const Arguments& args);
NO_IMPL(static Handle<Value>, SetRawMode, RET_V8TRUE, const Arguments& args);
NO_IMPL(static Handle<Value>, GetColumns, RET_V8INT(80), const Arguments& args);
NO_IMPL(static Handle<Value>, GetRows, RET_V8INT(25), const Arguments& args);
NO_IMPL(static Handle<Value>, IsATTY, RET_V8FALSE, const Arguments& args);
/*
* STDERR should always be blocking & utf-8
* TODO: check correctness
*/
static Handle<Value>
WriteError (const Arguments& args)
{
HandleScope scope;
if (args.Length() < 1)
return Undefined();
String::Utf8Value msg(args[0]->ToString());
fprintf(stderr, "%s", (char*)*msg);
return Undefined();
}
/*
* Assume that stdout is never blocking on windows
* TODO: check correctness and really implement this
*/
static Handle<Value>
IsStdoutBlocking (const Arguments& args)
{
return True();
}
void Stdio::Initialize(v8::Handle<v8::Object> target) {
target->Set(String::NewSymbol("stdoutFD"), Integer::New(STDOUT_FILENO));
target->Set(String::NewSymbol("stderrFD"), Integer::New(STDERR_FILENO));
target->Set(String::NewSymbol("stdinFD"), Integer::New(STDIN_FILENO));
NODE_SET_METHOD(target, "writeError", WriteError);
NODE_SET_METHOD(target, "openStdin", OpenStdin);
NODE_SET_METHOD(target, "isStdoutBlocking", IsStdoutBlocking);
NODE_SET_METHOD(target, "isStdinBlocking", IsStdinBlocking);
NODE_SET_METHOD(target, "setRawMode", SetRawMode);
NODE_SET_METHOD(target, "getColumns", GetColumns);
NODE_SET_METHOD(target, "getRows", GetRows);
NODE_SET_METHOD(target, "isatty", IsATTY);
}
} // namespace node
NODE_MODULE(node_stdio, node::Stdio::Initialize);
|