【问题标题】:Can I actually save several cursor positions using ANSI escape sequences?我真的可以使用 ANSI 转义序列保存几个光标位置吗?
【发布时间】:2018-05-21 13:36:52
【问题描述】:

根据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 cursor-position


    【解决方案1】:

    ANSI 终端没有光标位置的记忆。如果你需要这样复杂的东西,你必须自己跟踪光标位置。

    这需要做很多工作,而且很难做到正确。你最好使用ncurses

    【讨论】:

    • 其实做不到也没关系。我只是想知道这是否可能。谢谢!
    猜你喜欢
    • 2015-05-13
    • 1970-01-01
    • 2011-11-19
    • 2021-01-09
    • 1970-01-01
    • 2015-08-08
    • 2018-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多