我如何找到宽度&终端窗口的高度? [英] How do I find the width & height of a terminal window?
本文介绍了我如何找到宽度&终端窗口的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
举一个简单的例子,我想编写一个 CLI 脚本,它可以在终端窗口的整个宽度上打印 =
.
As a simple example, I want to write a CLI script which can print =
across the entire width of the terminal window.
#!/usr/bin/env php
<?php
echo str_repeat('=', ???);
或
#!/usr/bin/env python
print '=' * ???
或
#!/usr/bin/env bash
x=0
while [ $x -lt ??? ]; do echo -n '='; let x=$x+1 done; echo
推荐答案
tput cols
告诉您列数.tput lines
告诉您行数.tput cols
tells you the number of columns.tput lines
tells you the number of rows.
这篇关于我如何找到宽度&终端窗口的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文