【问题标题】:How to use escape sequences [duplicate]如何使用转义序列[重复]
【发布时间】:2020-03-06 05:31:57
【问题描述】:

我正在尝试让转义序列在 Go 应用程序中工作。特别是移动光标的代码。 fmt.Printf("\033[3;5H") 为了完成这项工作,我应该打印/写什么?还是我完全以错误的方式接近这个?每次我运行代码时,我都会在终端中得到一些看起来很时髦的字符,或者什么也没有发生。我正在运行 Windows 10。

我尝试过使用多个不同的fmt.Print 函数,但得到了相同的结果。

// Move the cursor
fmt.Printf("\033[3;5H")

// Print at new position
fmt.Printf("Print this text at the new cursor position")

【问题讨论】:

  • 我不知道 Go,ANSII 转义码在每个控制台中都不起作用。如果您确定代码正确,您的控制台可能不兼容。

标签: windows go ansi-colors


【解决方案1】:

原来你需要在 Windows 10 中启用虚拟终端处理才能使用 ANSII 转义码

https://github.com/konsorten/go-windows-terminal-sequences

【讨论】:

    猜你喜欢
    • 2020-06-20
    • 1970-01-01
    • 1970-01-01
    • 2017-04-06
    • 2016-06-01
    • 2015-09-12
    • 1970-01-01
    • 2013-04-12
    相关资源
    最近更新 更多