VT100 escape sequences: Cursor movement wrap around to end of line

♀尐吖头ヾ 提交于 2019-12-04 19:14:47

The bw capability in a termcap terminal description says whether moving left at the edge of a screen wraps to the previous line. It was present in a PuTTy description I checked (infocmp putty under ncurses), but not in many others (e.g. not in infocmp gnome).

You could try to keep track of which column the cursor is in and use movement control sequences when you want to wrap round to the previous line. You would have to know the width of the user's screen, which can be done by them setting the LINES and COLS environmental variables.

As noted, the bw capability could solve part of the problem, but it is rare. In particular, it is not a feature of vt100-compatible programs (such as xterm). The OP mentioned both PuTTY and gnome-terminal. The latter does not use bw, so a different solution is preferred.

On the other hand, PuTTY does implement the vt100 cursor position report which is used by resize as a fallback when it cannot obtain the screensize using system calls. Quoting from xterm's control sequences document:

CSI Ps n  Device Status Report (DSR).
            Ps = 5  -> Status Report.
          Result (``OK'') is CSI 0 n
            Ps = 6  -> Report Cursor Position (CPR) [row;column].
          Result is CSI r ; c R

The resize program uses this by

  • sending the cursor to the lower right corner of a "huge" (999 by 999) window
  • sending the CPR sequence
  • reading the report of the actual cursor position

Knowing the screensize, the server could send the cursor to more useful positions.

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