Is it possible to get the terminal width in Go?
I tried using http://github.com/nsf/termbox-go with the code:
package main
import (
"fmt"
"github.com/nsf/termbox-go"
)
func main() {
fmt.Println(termbox.Size())
}
But it prints 0 0
.
I also tried http://github.com/buger/goterm but when I try to go get
it, I get an error:
$ go get github.com/buger/goterm
# github.com/buger/goterm
..\..\buger\goterm\terminal.go:78: undefined: syscall.SYS_IOCTL
..\..\buger\goterm\terminal.go:82: not enough arguments in call to syscall.Syscall
Any other ideas on how to get the terminal width?
You need to call termbox.Init()
before you call termbox.Size()
, and then termbox.Close()
when you're done.
package main
import (
"fmt"
"github.com/nsf/termbox-go"
)
func main() {
if err := termbox.Init(); err != nil {
panic(err)
}
w, h := termbox.Size()
termbox.Close()
fmt.Println(w, h)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With