donglian1523
2019-06-05 12:38
浏览 1.1k
已采纳

Golang的fmt.Print(“ \ 033c”)和fmt.Print(“ \ x1bc”)无法清除屏幕(ANSI Escape代码不起作用)如何解决?

Whenever I run fmt.Print("\033c") in golang on windows cmd it does not clear screen but prints c whenever I do console.log("\033c") in javascript it works fine.

According to the following links this should have worked: https://en.wikipedia.org/wiki/ANSI_escape_code#Windows

https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#samples

I have tried logging it in javascript and it works fine I also tried adding a character to the end which printed c and changing it to \x1bc which also just printed: c

the following all prints: c on windows cmd


func main() {
  fmt.Print("\033c")
  fmt.Print("\033c
")
  fmt.Print("\x1bc")
  fmt.Print("\x1bc
")
  fmt.Println("\033c")
  fmt.Println("\x1bc")
}

I expected that it would just clear the screen as in javascript but for some reason it doesn't

To clarify I am talking about that the ANSI escape code is not working.

图片转代码服务由CSDN问答提供 功能建议

每当我在Windows cmd的golang中运行 fmt.Print(“ \ 033c”)</ code> 它不会清除屏幕,但是每当我在javascript中执行 console.log(“ \ 033c”)</ code>时,都会打印 c </ code>。它工作正常。</ p>

根据以下链接,它应该已经起作用: https://en.wikipedia.org / wiki / ANSI_escape_code#Windows </ p>

https://docs.microsoft.com/zh-cn/windows/console/console-virtual-terminal-sequences#samples </ p>

我尝试将其记录在javascript中,并且工作正常,我还尝试在打印 c </ code>的末尾添加一个 字符,并将其更改为也刚刚打印的\ x1bc: c </ code> </ p>

以下所有打印内容:Windows cmd上的 c </ code> </ p>

  
func  main(){
 fmt.Print(“ \ 033c”)
 fmt.Print(“ \ 033c 
”)
 fmt.Print(“ \ x1bc”)
 fmt.Print(“ \ x1bc 
  “)
 fmt.Println(” \ 033c“)
 fmt.Println(” \ x1bc“)​​
} 
 </ code> </ pre> 
 
 

我希望它只是 清除javascript中的屏幕,但出于某种原因</ p>

要澄清一下,我说的是 ANSI转义代码不起作用。</ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题