Skip to content

Commit

Permalink
Updated tscreen stub (SQUASH ME)
Browse files Browse the repository at this point in the history
  • Loading branch information
diamondburned committed Mar 5, 2021
1 parent f1edf2e commit 5ccc41b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 33 deletions.
35 changes: 7 additions & 28 deletions tscreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"time"
"unicode/utf8"

"golang.org/x/sys/unix"
"golang.org/x/term"
"golang.org/x/text/transform"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}

Expand Down
4 changes: 2 additions & 2 deletions tscreen_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 21 additions & 3 deletions tscreen_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5ccc41b

Please sign in to comment.