Add terminal size lookup

This commit is contained in:
Timothy Warren 2021-03-23 15:51:59 -04:00
parent e8ba6825aa
commit 835f550bbb
2 changed files with 15 additions and 0 deletions

View File

@ -8,6 +8,11 @@ import (
"timshome.page/gilo/internal/terminal"
)
type Editor struct {
rows int
cols int
}
var reader = bufio.NewReader(os.Stdin)
func readKey() (rune, int) {

View File

@ -41,6 +41,16 @@ func ANSICode (code string) {
fmt.Printf("\x1b[%s", code)
}
func Size () (width int, height int) {
width, height, err := term.GetSize(int(os.Stdin.Fd()))
if err != nil {
width = 80
height = 24
}
return width, height
}
// Print a formatted string to stdout, with CRLF line endings for proper terminal formatting
func OutLn(format string, a ...interface{}) {
formatted := fmt.Sprintf(format, a...)