node.js控制台有多宽? [英] How wide is the node.js console?

查看:268
本文介绍了node.js控制台有多宽?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在node.js中,如何获得控制台窗口和/或缓冲区的当前宽度?

In node.js, how do I get the current width of the console window and/or buffer?

.net中的模拟Console.BufferWidth 和/或 Console.WindowWidth

The analog in .net is Console.BufferWidth and/or Console.WindowWidth.

我想对我的行包装进行更多的控制。 / p>

I want to exercise more control over my line wrapping.

推荐答案

看起来像目前最好的方式是这个属性:

Looks like the current best way is this property:

process.stdout.columns

/ p>

And for height (rows):

process.stdout.rows

另请注意,有一个resize事件,可能派上用场:

Also note that there is a "resize" event, which might come in handy:

process.stdout.on('resize', function() {
  console.log('screen size has changed!');
  console.log(process.stdout.columns + 'x' + process.stdout.rows);
});

此处的文档:
http://nodejs.org/api/tty.html#tty_tty

这篇关于node.js控制台有多宽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆