@@ -94,30 +94,47 @@ static Handle<Value> SetRawMode (const Arguments& args) {
94
94
}
95
95
96
96
97
- // process.binding('stdio').getColumns();
98
- static Handle <Value> GetColumns (const Arguments& args) {
97
+ // process.binding('stdio').getWindowSize(fd);
98
+ // returns [row, col]
99
+ static Handle <Value> GetWindowSize (const Arguments& args) {
99
100
HandleScope scope;
100
101
102
+ int fd = args[0 ]->IntegerValue ();
103
+
101
104
struct winsize ws;
102
105
103
- if (ioctl (1 , TIOCGWINSZ, &ws) == - 1 ) {
104
- return scope. Close ( Integer::New ( 80 ));
106
+ if (ioctl (fd , TIOCGWINSZ, &ws) < 0 ) {
107
+ return ThrowException ( ErrnoException (errno, " ioctl " ));
105
108
}
106
109
107
- return scope.Close (Integer::NewFromUnsigned (ws.ws_col ));
110
+ Local<Array> ret = Array::New (2 );
111
+ ret->Set (0 , Integer::NewFromUnsigned (ws.ws_row ));
112
+ ret->Set (1 , Integer::NewFromUnsigned (ws.ws_col ));
113
+
114
+ return scope.Close (ret);
108
115
}
109
116
110
- // process.binding('stdio').getRows();
111
- static Handle <Value> GetRows (const Arguments& args) {
117
+
118
+ // process.binding('stdio').setWindowSize(fd, row, col);
119
+ static Handle <Value> SetWindowSize (const Arguments& args) {
112
120
HandleScope scope;
113
121
122
+ int fd = args[0 ]->IntegerValue ();
123
+ int row = args[1 ]->IntegerValue ();
124
+ int col = args[2 ]->IntegerValue ();
125
+
114
126
struct winsize ws;
115
127
116
- if (ioctl (1 , TIOCGWINSZ, &ws) == -1 ) {
117
- return scope.Close (Integer::New (132 ));
128
+ ws.ws_row = row;
129
+ ws.ws_col = col;
130
+ ws.ws_xpixel = 0 ;
131
+ ws.ws_ypixel = 0 ;
132
+
133
+ if (ioctl (fd, TIOCSWINSZ, &ws) < 0 ) {
134
+ return ThrowException (ErrnoException (errno, " ioctl" ));
118
135
}
119
136
120
- return scope. Close ( Integer::NewFromUnsigned (ws. ws_row ) );
137
+ return True ( );
121
138
}
122
139
123
140
@@ -283,8 +300,8 @@ void Stdio::Initialize(v8::Handle<v8::Object> target) {
283
300
NODE_SET_METHOD (target, " isStdoutBlocking" , IsStdoutBlocking);
284
301
NODE_SET_METHOD (target, " isStdinBlocking" , IsStdinBlocking);
285
302
NODE_SET_METHOD (target, " setRawMode" , SetRawMode);
286
- NODE_SET_METHOD (target, " getColumns " , GetColumns );
287
- NODE_SET_METHOD (target, " getRows " , GetRows );
303
+ NODE_SET_METHOD (target, " getWindowSize " , GetWindowSize );
304
+ NODE_SET_METHOD (target, " setWindowSize " , GetWindowSize );
288
305
NODE_SET_METHOD (target, " isatty" , IsATTY);
289
306
NODE_SET_METHOD (target, " openpty" , OpenPTY);
290
307
0 commit comments