Skip to content

Commit

Permalink
Resizing bufixes
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmcd committed Nov 11, 2018
1 parent 9e034f4 commit 5d7cbdb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
8 changes: 6 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func sendTermSize(term *os.File, dcSend func(p datachannel.Payload) error) error
size := fmt.Sprintf(`["set_size",%d,%d,%d,%d]`,
winSize.Rows, winSize.Cols, winSize.X, winSize.Y)

return dcSend(&datachannel.PayloadString{Data: []byte(size)})
return dcSend(datachannel.PayloadString{Data: []byte(size)})
}

func clientDataChannelOnOpen(errChan chan error, dc *webrtc.RTCDataChannel) func() {
Expand All @@ -40,7 +40,11 @@ func clientDataChannelOnOpen(errChan chan error, dc *webrtc.RTCDataChannel) func
signal.Notify(ch, syscall.SIGWINCH)
go func() {
for range ch {
sendTermSize(os.Stdin, dc.Send)
err := sendTermSize(os.Stdin, dc.Send)
if err != nil {
log.Println(err)
errChan <- err
}
}
}()
ch <- syscall.SIGWINCH // Initial resize.
Expand Down
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestSendTermSize(t *testing.T) {

dcSend := func(payload datachannel.Payload) error {
switch p := payload.(type) {
case *datachannel.PayloadString:
case datachannel.PayloadString:
onMessage, errChan := makeShPty(t)
size, err := pty.GetsizeFull(ptmx)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion host.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"os/signal"
"time"

"github.com/kr/pty"
"github.com/mitchellh/colorstring"
Expand Down Expand Up @@ -41,6 +42,8 @@ func hostDataChannelOnOpen(dc *webrtc.RTCDataChannel, errChan chan error) func()
errChan <- err
return
}
// wait for pmtx to be readyd
time.Sleep(time.Millisecond * 10)

if _, err = terminal.MakeRaw(int(os.Stdin.Fd())); err != nil {
log.Println(err)
Expand Down Expand Up @@ -119,6 +122,7 @@ func hostDataChannelOnMessage(errChan chan error) func(payload datachannel.Paylo
if err != nil {
log.Println(err)
errChan <- err
return
}
ws.Rows = uint16(size[1])
ws.Cols = uint16(size[2])
Expand All @@ -128,7 +132,7 @@ func hostDataChannelOnMessage(errChan chan error) func(payload datachannel.Paylo
ws.Y = uint16(size[4])
}

if err = pty.Setsize(ptmx, ws); err != nil {
if err := pty.Setsize(ptmx, ws); err != nil {
log.Println(err)
errChan <- err
}
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"flag"
"fmt"
"io/ioutil"
"log"

Expand All @@ -12,13 +13,13 @@ import (
func main() {
oneWay := flag.Bool("o", false, "One-way connection with no response needed.")
verbose := flag.Bool("v", false, "Verbose logging")
flag.Parse()
if *verbose {
log.SetFlags(log.LstdFlags | log.Lshortfile)
} else {
log.SetFlags(0)
log.SetOutput(ioutil.Discard)
}
flag.Parse()
args := flag.Args()
var offerString string
if len(args) > 0 {
Expand All @@ -28,12 +29,12 @@ func main() {
if len(offerString) == 0 {
err := runHost(*oneWay)
if err != nil {
log.Println(err)
fmt.Println(err)
}
} else {
err := runClient(offerString)
if err != nil {
log.Println(err)
fmt.Println(err)
}
}
resumeTerminal()
Expand Down

0 comments on commit 5d7cbdb

Please sign in to comment.