英文:
golang - open file in an empty bash window
问题
让我们假设我有以下代码:
package main
import (
"io/ioutil"
"fmt"
)
func check(err error) {
if err != nil {
panic(err)
}
}
func main() {
file, err := ioutil.ReadFile("test.txt")
check(err)
fmt.Print(string(file))
}
当使用go run
运行它时,我希望它在一个清晰的bash窗口中显示。是否可以在不使用任何额外的开源库的情况下实现这一点?
提前感谢。
英文:
lets say I have this code:
package main
import (
"io/ioutil"
"fmt"
)
func check(err error) {
if err != nil {
panic(err)
}
}
func main() {
file, err := ioutil.ReadFile("test.txt")
check(err)
fmt.Print(string(file))
}
when running it with go run
I want it to be written in a cleared bash window. Is it possible to do so without using any additional open-source repositories?
Thanks in advance.
答案1
得分: 1
如果清除终端确实是你的程序责任的一部分,那么可以参考这个问题的答案:https://stackoverflow.com/questions/22891644/how-can-i-clear-the-terminal-screen-in-go
然而,如果你只是想在开发过程中清除屏幕,那么可以简单地执行以下操作:
clear && go run *.go
英文:
If clearing the terminal is truly part of your program's responsibility then check out the answers in this question https://stackoverflow.com/questions/22891644/how-can-i-clear-the-terminal-screen-in-go
However if you're just wanting to clear the screen as part of your development process then I would keep it simple and do something like this
clear && go run *.go
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论