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

Fix suggested by go vet #154

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (o *Operation) ioloop() {
for {
keepInSearchMode := false
keepInCompleteMode := false
r := o.t.ReadRune()
r, _, _ := o.t.ReadRune()
if o.GetConfig().FuncFilterInputRune != nil {
var process bool
r, process = o.GetConfig().FuncFilterInputRune(r)
Expand Down Expand Up @@ -154,7 +154,10 @@ func (o *Operation) ioloop() {
}

if o.IsEnableVimMode() {
r = o.HandleVim(r, o.t.ReadRune)
r = o.HandleVim(r, func() rune {
c, _, _ := o.t.ReadRune()
return c
})
if r == 0 {
continue
}
Expand Down
7 changes: 3 additions & 4 deletions remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ loop:
break
}
n, err := ctx.msg.WriteTo(r.conn)
ctx.reply <- &writeReply{n, err}
ctx.reply <- &writeReply{int(n), err}
case <-r.stopChan:
break loop
}
Expand Down Expand Up @@ -273,13 +273,12 @@ func NewMessage(t MsgType, data []byte) *Message {
return &Message{t, data}
}

func (m *Message) WriteTo(w io.Writer) (int, error) {
func (m *Message) WriteTo(w io.Writer) (int64, error) {
buf := bytes.NewBuffer(make([]byte, 0, len(m.Data)+2+4))
binary.Write(buf, binary.BigEndian, int32(len(m.Data)+2))
binary.Write(buf, binary.BigEndian, m.Type)
buf.Write(m.Data)
n, err := buf.WriteTo(w)
return int(n), err
return buf.WriteTo(w)
}

// -----------------------------------------------------------------------------
Expand Down
7 changes: 4 additions & 3 deletions terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"sync"
"sync/atomic"
"unicode/utf8"
)

type Terminal struct {
Expand Down Expand Up @@ -96,12 +97,12 @@ func (t *Terminal) Readline() *Operation {
}

// return rune(0) if meet EOF
func (t *Terminal) ReadRune() rune {
func (t *Terminal) ReadRune() (rune, int, error) {
ch, ok := <-t.outchan
if !ok {
return rune(0)
return rune(0), 1, nil
}
return ch
return ch, utf8.RuneLen(ch), nil
}

func (t *Terminal) IsReading() bool {
Expand Down