Can Terminal.app be made to respect ANSI escape codes?

你说的曾经没有我的故事 提交于 2019-12-02 20:30:34
n.m.

Don't use ANSI codes. Use proper terminfo-based techniques. Xterm-based terminals are not specified to support all ANSI codes. Some do for compatibility, some don't.

Save cursor position sequence is given by the tput sc command and the restore cursor position is tput rc.

echo -e "$(tput sc)Hello world$(tput rc)G'day"

should work on any terminal that supports these sequences.

To see a readable representation of the supported sequences, use the infocmp command. The output might be quite long. If you are interested in sc and rc:

infocmp | grep --color ' [sr]c='

Disclaimer: tested on my Linux machine, don't have a Mac nearby.

UPDATE

Terminal.app is modeled after xterm and xterm is modelled after the VT100 terminal. VT100 did not implement CSI u and CSI s sequences, but used DEC private ESC 7 and ESC 8 sequences (source). Later VT models supported both CSI s/u and ESC 7/8, under different name and with slightly different functionality (source).

ECMA 48 doesn't seem to specify any save/restore cursor position sequences (source (PDF)), or I could not find them there. I don't know where CSU s/u come from. Their name in VT510 documentation suggests they are somehow connected with SCO. This source suggests they are in fact private sequences with no standard meaning. SUN terminals use SCI s to do a reset. It is probably an error to brand these two sequences ANSI.

Modern versions of xterm and other X11 terminal programs (konsole, rxvt...) do support both ESC 7/8 and CSI s/u, but the terminfo database only advertises ESC 7/8. Terminal.app apparently only supports ESC 7/8.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!