Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow forwarding resize events #103 #104

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions term.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package terminal

import (
"github.com/creack/pty"
"image/color"
"io"
"math"
Expand Down Expand Up @@ -86,8 +87,11 @@ type Terminal struct {
printer Printer
cmd *exec.Cmd
readWriterConfigurator ReadWriterConfigurator
onResize ResizeHandler
}

type ResizeHandler = func(size *pty.Winsize)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not expose a third party API as a type in our APIs - it assumes that Terminal is always connected to a "github.com/creack/pty"


// Printer is used for spooling print data when its received.
type Printer interface {
Print([]byte)
Expand Down Expand Up @@ -549,3 +553,7 @@ type ReadWriterConfiguratorFunc func(r io.Reader, w io.WriteCloser) (io.Reader,
func (m ReadWriterConfiguratorFunc) SetupReadWriter(r io.Reader, w io.WriteCloser) (io.Reader, io.WriteCloser) {
return m(r, w)
}

func (t *Terminal) SetResizeHandler(h ResizeHandler) {
t.onResize = h
}
12 changes: 9 additions & 3 deletions term_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,23 @@ import (
)

func (t *Terminal) updatePTYSize() {
if t.pty == nil { // SSH or other direct connection?
if t.pty == nil && t.onResize == nil { // SSH or other direct connection?
return
}
scale := float32(1.0)
c := fyne.CurrentApp().Driver().CanvasForObject(t)
if c != nil {
scale = c.Scale()
}
_ = pty.Setsize(t.pty.(*os.File), &pty.Winsize{
ws := &pty.Winsize{
Rows: uint16(t.config.Rows), Cols: uint16(t.config.Columns),
X: uint16(t.Size().Width * scale), Y: uint16(t.Size().Height * scale)})
X: uint16(t.Size().Width * scale), Y: uint16(t.Size().Height * scale)}
if t.onResize != nil {
t.onResize(ws)
}
if t.pty != nil {
_ = pty.Setsize(t.pty.(*os.File), ws)
}
}

func (t *Terminal) startPTY() (io.WriteCloser, io.Reader, io.Closer, error) {
Expand Down