Skip to content

Commit

Permalink
fix #20
Browse files Browse the repository at this point in the history
  • Loading branch information
wrfly committed Sep 18, 2018
1 parent 149d051 commit 5f64d3a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
3 changes: 1 addition & 2 deletions route/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,9 @@ func (server *Server) handleLogs(c *gin.Context) {
}

if err := tty.Run(ctx); err != nil {
if err != webtty.ErrMasterClosed && err != webtty.ErrMasterClosed {
if err != webtty.ErrMasterClosed && err != webtty.ErrSlaveClosed {
log.Errorf("failed to run webtty: %s", err)
}
return
}
}

Expand Down
25 changes: 22 additions & 3 deletions route/slave_wrapper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package route

import (
"bytes"
"io"

"github.com/yudai/gotty/webtty"
Expand Down Expand Up @@ -44,9 +45,27 @@ func newSlave(rc io.ReadCloser) webtty.Slave {
if err != nil {
return
}
pw.Write(bs[:n])
if bs[n-1] == 10 {
pw.Write([]byte{13})
if len(bs) <= 1 {
continue
}

if bs[n-2] == 13 { // \r\n
pw.Write(bs[:n])
continue
}

// only \n or a long log string containes \n
s, e := 0, 0
for e < n {
x := bytes.IndexByte(bs[e:n], 10)
if x == -1 {
break
}
s = e
e += x
pw.Write(bs[s:e])
pw.Write([]byte{13, 10})
e++ // skip this \n
}
}
}()
Expand Down

0 comments on commit 5f64d3a

Please sign in to comment.