Permalink
Browse files

getWindowSize/setWindowSize

  • Loading branch information...
1 parent 63bd237 commit b9cfd9527acad0a686083078863bff028dfd785a @ry ry committed Jan 11, 2011
Showing with 36 additions and 15 deletions.
  1. +5 −2 lib/readline.js
  2. +2 −1 lib/tty.js
  3. +29 −12 src/node_stdio.cc
View
@@ -49,11 +49,14 @@ function Interface(output, completer) {
this.history = [];
this.historyIndex = -1;
- exports.columns = tty.getColumns();
+ // 0 for stdin
+ var winSize = tty.getWindowSize(0);
+ exports.columns = winSize[1];
if (process.listeners('SIGWINCH').length === 0) {
process.on('SIGWINCH', function() {
- exports.columns = tty.getColumns();
+ var winSize = tty.getWindowSize(0);
+ exports.columns = winSize[1];
});
}
}
View
@@ -4,7 +4,8 @@ var binding = process.binding('stdio');
exports.isatty = binding.isatty;
exports.setRawMode = binding.setRawMode;
-exports.getColumns = binding.getColumns;
+exports.getWindowSize = binding.getWindowSize;
+exports.setWindowSize = binding.setWindowSize;
exports.open = function(path, args) {
View
@@ -94,30 +94,47 @@ static Handle<Value> SetRawMode (const Arguments& args) {
}
-// process.binding('stdio').getColumns();
-static Handle<Value> GetColumns (const Arguments& args) {
+// process.binding('stdio').getWindowSize(fd);
+// returns [row, col]
+static Handle<Value> GetWindowSize (const Arguments& args) {
HandleScope scope;
+ int fd = args[0]->IntegerValue();
+
struct winsize ws;
- if (ioctl(1, TIOCGWINSZ, &ws) == -1) {
- return scope.Close(Integer::New(80));
+ if (ioctl(fd, TIOCGWINSZ, &ws) < 0) {
+ return ThrowException(ErrnoException(errno, "ioctl"));
}
- return scope.Close(Integer::NewFromUnsigned(ws.ws_col));
+ Local<Array> ret = Array::New(2);
+ ret->Set(0, Integer::NewFromUnsigned(ws.ws_row));
+ ret->Set(1, Integer::NewFromUnsigned(ws.ws_col));
+
+ return scope.Close(ret);
}
-// process.binding('stdio').getRows();
-static Handle<Value> GetRows (const Arguments& args) {
+
+// process.binding('stdio').setWindowSize(fd, row, col);
+static Handle<Value> SetWindowSize (const Arguments& args) {
HandleScope scope;
+ int fd = args[0]->IntegerValue();
+ int row = args[1]->IntegerValue();
+ int col = args[2]->IntegerValue();
+
struct winsize ws;
- if (ioctl(1, TIOCGWINSZ, &ws) == -1) {
- return scope.Close(Integer::New(132));
+ ws.ws_row = row;
+ ws.ws_col = col;
+ ws.ws_xpixel = 0;
+ ws.ws_ypixel = 0;
+
+ if (ioctl(fd, TIOCSWINSZ, &ws) < 0) {
+ return ThrowException(ErrnoException(errno, "ioctl"));
}
- return scope.Close(Integer::NewFromUnsigned(ws.ws_row));
+ return True();
}
@@ -283,8 +300,8 @@ void Stdio::Initialize(v8::Handle<v8::Object> target) {
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, "getWindowSize", GetWindowSize);
+ NODE_SET_METHOD(target, "setWindowSize", GetWindowSize);
NODE_SET_METHOD(target, "isatty", IsATTY);
NODE_SET_METHOD(target, "openpty", OpenPTY);

0 comments on commit b9cfd95

Please sign in to comment.