From 5ccc41ba3ea761d227c40af7104d6295f0b5f1fc Mon Sep 17 00:00:00 2001 From: diamondburned Date: Thu, 4 Mar 2021 18:23:09 -0800 Subject: [PATCH] Updated tscreen stub (SQUASH ME) --- tscreen.go | 35 +++++++---------------------------- tscreen_stub.go | 4 ++-- tscreen_unix.go | 24 +++++++++++++++++++++--- 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/tscreen.go b/tscreen.go index 9fe54aa4..26efb5f6 100644 --- a/tscreen.go +++ b/tscreen.go @@ -24,7 +24,6 @@ import ( "time" "unicode/utf8" - "golang.org/x/sys/unix" "golang.org/x/term" "golang.org/x/text/transform" @@ -140,23 +139,6 @@ type tScreenSize struct { ypx int } -func (t *tScreenSize) updateScreenSize(winsz *unix.Winsize) (changed bool) { - h := int(winsz.Row) - w := int(winsz.Col) - xpx := int(winsz.Xpixel) - ypx := int(winsz.Ypixel) - - changed = t.h != h || t.w != w || t.xpx != xpx || t.ypx != ypx - if changed { - t.h = h - t.w = w - t.xpx = xpx - t.ypx = ypx - } - - return -} - func (t tScreen) Init() error { if e := t.initialize(); e != nil { return e @@ -984,21 +966,18 @@ func (t tScreen) PixelSize() (int, int) { } func (t tScreen) resize(dispatch bool) { - winsz, err := t.getWinSize() - if err != nil { + if !t.updateScreenSize() { return } - if t.updateScreenSize(winsz) { - t.cx = -1 - t.cy = -1 + t.cx = -1 + t.cy = -1 - t.cells.Resize(t.w, t.h) - t.cells.Invalidate() + t.cells.Resize(t.w, t.h) + t.cells.Invalidate() - if dispatch { - t.dispatchResizeEvent() - } + if dispatch { + t.dispatchResizeEvent() } } diff --git a/tscreen_stub.go b/tscreen_stub.go index 09a9070f..cdb630b7 100644 --- a/tscreen_stub.go +++ b/tscreen_stub.go @@ -34,8 +34,8 @@ func (t tScreen) initialize() error { func (t tScreen) finalize() { } -func (t tScreen) getWinSize() (int, int, error) { - return 0, 0, ErrNoScreen +func (t tScreen) updateScreenSize() bool { + return false } func (t tScreen) Beep() error { diff --git a/tscreen_unix.go b/tscreen_unix.go index e9607957..507abbc5 100644 --- a/tscreen_unix.go +++ b/tscreen_unix.go @@ -112,9 +112,27 @@ func (t tScreen) finalize() { t.disengage() } -// getWinSize is called to obtain the terminal dimensions. -func (t tScreen) getWinSize() (*unix.Winsize, error) { - return unix.IoctlGetWinsize(int(t.in.Fd()), unix.TIOCGWINSZ) +// updateScreenSize is called to update the terminal dimensions. +func (t tScreen) updateScreenSize() (updated bool) { + winsz, err := unix.IoctlGetWinsize(int(t.in.Fd()), unix.TIOCGWINSZ) + if err != nil { + return false + } + + h := int(winsz.Row) + w := int(winsz.Col) + xpx := int(winsz.Xpixel) + ypx := int(winsz.Ypixel) + + updated = t.h != h || t.w != w || t.xpx != xpx || t.ypx != ypx + if updated { + t.h = h + t.w = w + t.xpx = xpx + t.ypx = ypx + } + + return } // Beep emits a beep to the terminal.