-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #159 from uselagoon/terminal-resize
fix: handle terminal resizing correctly
- Loading branch information
Showing
3 changed files
with
50 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package k8s | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/gliderlabs/ssh" | ||
"k8s.io/client-go/tools/remotecommand" | ||
) | ||
|
||
type termSizeQueue struct { | ||
send chan *remotecommand.TerminalSize | ||
} | ||
|
||
// newTermSizeQueue returns a termSizeQueue which implements the | ||
// remotecommand.TerminalSizeQueue interface. It starts a goroutine which exits | ||
// when the given context is done. | ||
func newTermSizeQueue(ctx context.Context, winch <-chan ssh.Window) *termSizeQueue { | ||
tsq := termSizeQueue{ | ||
send: make(chan *remotecommand.TerminalSize, 1), | ||
} | ||
go func() { | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
close(tsq.send) | ||
return | ||
case window := <-winch: | ||
tsq.send <- &remotecommand.TerminalSize{ | ||
Width: uint16(window.Width), | ||
Height: uint16(window.Height), | ||
} | ||
} | ||
} | ||
}() | ||
return &tsq | ||
} | ||
|
||
func (t *termSizeQueue) Next() *remotecommand.TerminalSize { | ||
return <-t.send | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters