我真的可以使用 ANSI 转义序列保存多个光标位置吗?
Can I actually save several cursor positions using ANSI escape sequences?
根据this source,这些是可以对游标进行的操作:
- Position the Cursor:
3[<L>;<C>H
Or
3[<L>;<C>f
puts the cursor at line L and column C.
- Move the cursor up N lines:
3[<N>A
- Move the cursor down N lines:
3[<N>B
- Move the cursor forward N columns:
3[<N>C
- Move the cursor backward N columns:
3[<N>D
- Clear the screen, move to (0,0):
3[2J
- Erase to end of line:
3[K
- Save cursor position:
3[s
- Restore cursor position:
3[u
因此您可以使用 3[s
保存光标位置,然后使用 3[u
恢复它。但是如果我想保存几个光标位置呢?
例如,假设我想保存两个光标位置,然后恢复它们。值会被删除吗?所以我的问题是:有没有办法使用 ANSI 转义序列 或不 来保存几个光标位置以便稍后在 bash 中恢复它们?
ANSI 终端没有光标位置的记忆。如果你需要像那样复杂的东西,你将不得不自己跟踪光标位置。
要做到这一点需要做很多工作并且很棘手。你最好使用 ncurses
.
根据this source,这些是可以对游标进行的操作:
- Position the Cursor:
3[<L>;<C>H
Or
3[<L>;<C>f
puts the cursor at line L and column C.
- Move the cursor up N lines:
3[<N>A
- Move the cursor down N lines:
3[<N>B
- Move the cursor forward N columns:
3[<N>C
- Move the cursor backward N columns:
3[<N>D
- Clear the screen, move to (0,0):
3[2J
- Erase to end of line:
3[K
- Save cursor position:
3[s
- Restore cursor position:
3[u
因此您可以使用 3[s
保存光标位置,然后使用 3[u
恢复它。但是如果我想保存几个光标位置呢?
例如,假设我想保存两个光标位置,然后恢复它们。值会被删除吗?所以我的问题是:有没有办法使用 ANSI 转义序列 或不 来保存几个光标位置以便稍后在 bash 中恢复它们?
ANSI 终端没有光标位置的记忆。如果你需要像那样复杂的东西,你将不得不自己跟踪光标位置。
要做到这一点需要做很多工作并且很棘手。你最好使用 ncurses
.