How do I determine size of ANSI terminal?

前端 未结 1 1849
梦毁少年i
梦毁少年i 2021-01-11 15:25

Standard input and output are connected to a terminal that implements ANSI escape sequences, but is of unknown dimensions.

I need to know how big the terminal so to

1条回答
  •  别那么骄傲
    2021-01-11 15:50

    The resize program does this by moving the cursor to a very large column and row; the terminal moves as far as it can, e.g.,

    CUP 999 999
    

    Then resize asks where the cursor is:

    DSR 6
    

    The terminal replies with the actual cursor position (i.e., the cursor position report CPR), from which resize knows the terminal's size: the cursor is on the lower-right corner.

    That's all done using standard (ECMA-48 / VT100) escape sequences. In XTerm Control Sequences (which should apply to your "ANSI" terminal)

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

    0 讨论(0)
提交回复
热议问题