VT100 ANSI转义序列:获取屏幕大小,条件ANSI [英] VT100 ANSI escape sequences: getting screen size, conditional ANSI

查看:745
本文介绍了VT100 ANSI转义序列:获取屏幕大小,条件ANSI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 当我调整终端大小时,它保持全屏。
    我想,有一些可以找出终端的屏幕尺寸。如何在VT100中执行此操作?

  1. When I resizing on terminal, it keeps full screen. I guess, there's someway that can find out what screen size the terminal is. How can I do that in VT100?

当我列出文件夹时,会显示蓝色的文件夹。 (或者让我们说不同的颜色)但是,如果将输出保存到文本文件(ls> out.txt)中,则不会看到任何ANSI代码,而是纯文本。但是,如果您尝试(vi> out.txt),您将看到ANSI代码。如何知道?

With , when I list folder, it shows folder in blue color. (or let's say different color) But, if you save output into a text file ( ls > out.txt ), you don't see any ANSI code but plain text. However, if you try ( vi > out.txt ), you will see ANSI code. How does know that?

谢谢

推荐答案

自动调整为屏幕调整大小的程序(例如 vi )正在响应 SIGWINCH 信号,并使用系统调用获取系统有关屏幕尺寸的信息。参见例如 在c ++中获取终端窗口的宽度/高度? 。顺便说一句,虽然广泛实现,但似乎没有记录在POSIX signal.h

Programs (such as vi) which automatically adjust to screen resizing are responding to the SIGWINCH signal, and using a system call to obtain the system's information about the screen-size. See for example Get width/height of a terminal window in c++?. By the way, though widely implemented, it does not appear to be documented in POSIX signal.h.

不使用 SIGWINCH ,一个程序可以向终端询问其屏幕大小。 调整大小 程序这通过将终端控制序列发送到

Without taking SIGWINCH into account, a program could ask the terminal about its screensize. The resize program does this, by sending the terminal control sequences to


  • 将光标移动到右下角(实际上是行/列999/999 ,这是足够好的),并且

  • 向终端询问光标的真实位置。

关于嵌入其输出中的ANSI控制序列的 ls vi (和其他程序)的行为取决于在程序的设计上。他们可能会使用 检测到他们的输出重定向到文件isatty 功能,并根据输出是否到终端或文件进行不同的操作。

The behavior of ls and vi (and other programs) regarding ANSI control sequences which would be embedded in their output depends upon the design of the program. They likely detect the redirection of their output to a file using the isatty function, and do something different depending on whether the output is to a terminal, or to a file.

这篇关于VT100 ANSI转义序列:获取屏幕大小,条件ANSI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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