我真的可以使用 ANSI 转义序列保存多个光标位置吗?

问题描述 投票:0回答:1

根据this source,这些是可以对光标进行的操作:

- Position the Cursor:
  \033[<L>;<C>H
     Or
  \033[<L>;<C>f
  puts the cursor at line L and column C.
- Move the cursor up N lines:
  \033[<N>A
- Move the cursor down N lines:
  \033[<N>B
- Move the cursor forward N columns:
  \033[<N>C
- Move the cursor backward N columns:
  \033[<N>D

- Clear the screen, move to (0,0):
  \033[2J
- Erase to end of line:
  \033[K

- Save cursor position:
  \033[s
- Restore cursor position:
  \033[u

因此您可以使用

\033[s
保存光标位置,然后使用
\033[u
恢复它。但是如果我想保存几个光标位置呢?

例如,假设我想保存两个光标位置,然后恢复它们。值会被删除吗?所以我的问题是:有没有办法,使用 ANSI 转义序列或不,保存几个光标位置以便稍后在 bash 中恢复它们?

bash ansi-escape cursor-position
1个回答
1
投票

ANSI 终端没有光标位置的记忆。如果你需要像那样复杂的东西,你将不得不自己跟踪光标位置。

要做到这一点需要做很多工作并且很棘手。你最好使用

ncurses
.

© www.soinside.com 2019 - 2024. All rights reserved.