From 835f550bbb40cda11b90d55953dfbf8904a8033a Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 23 Mar 2021 15:51:59 -0400 Subject: [PATCH] Add terminal size lookup --- internal/editor/editor.go | 5 +++++ internal/terminal/terminal.go | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/internal/editor/editor.go b/internal/editor/editor.go index 6c5f9cd..8142232 100644 --- a/internal/editor/editor.go +++ b/internal/editor/editor.go @@ -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) { diff --git a/internal/terminal/terminal.go b/internal/terminal/terminal.go index fa9f735..4d48483 100644 --- a/internal/terminal/terminal.go +++ b/internal/terminal/terminal.go @@ -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...)