Skip to content

Commit

Permalink
Add comments for golint
Browse files Browse the repository at this point in the history
  • Loading branch information
hymkor committed Mar 4, 2021
1 parent 6eb86dd commit 2614264
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
13 changes: 10 additions & 3 deletions buffer.go
Expand Up @@ -14,6 +14,7 @@ type undoT struct {
text string
}

// Buffer is ReadLine's internal data structure
type Buffer struct {
*Editor
Buffer []Moji
Expand All @@ -26,6 +27,7 @@ type Buffer struct {
pending string
}

// ViewWidth returns the cell-width screen can show in the one-line.
func (B *Buffer) ViewWidth() WidthT {
return WidthT(B.termWidth) - WidthT(B.topColumn) - forbiddenWidth
}
Expand Down Expand Up @@ -72,9 +74,8 @@ func (B *Buffer) insertString(pos int, s string) _Range {
return _Range(list)
}

// Insert String :s at :pos (Do not update screen)
// returns
// count of rune
// InsertString inserts string s at pos (Do not update screen)
// It returns the count of runes
func (B *Buffer) InsertString(pos int, s string) int {
return len(B.insertString(pos, s))
}
Expand Down Expand Up @@ -116,10 +117,12 @@ func (B *Buffer) ResetViewStart() {
}
}

// GetWidthBetween returns the width between start and end
func (B *Buffer) GetWidthBetween(from int, to int) WidthT {
return _Range(B.Buffer[from:to]).Width()
}

// SubString returns the readline string between start and end
func (B *Buffer) SubString(start, end int) string {
return moji2string(B.Buffer[start:end])
}
Expand All @@ -128,8 +131,11 @@ func (B Buffer) String() string {
return moji2string(B.Buffer)
}

// Delimiters means the quationmarks. The whitespace enclosed by them
// are not treat as parameters separator.
var Delimiters = "\"'"

// CurrentWordTop returns the position of the current word the cursor exists
func (B *Buffer) CurrentWordTop() (wordTop int) {
wordTop = -1
quotedchar := '\000'
Expand All @@ -155,6 +161,7 @@ func (B *Buffer) CurrentWordTop() (wordTop int) {
return wordTop
}

// CurrentWord returns the current word the cursor exists and word's position
func (B *Buffer) CurrentWord() (string, int) {
start := B.CurrentWordTop()
return B.SubString(start, B.Cursor), start
Expand Down
3 changes: 3 additions & 0 deletions getkey.go
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/zetamatta/go-readline-ny/internal/github.com/mattn/go-tty"
)

// KeyGetter is the interface from which the ReadLine can read console input
type KeyGetter interface {
Raw() (func() error, error)
ReadRune() (rune, error)
Expand Down Expand Up @@ -56,6 +57,8 @@ type _DefaultTty struct {
*tty.TTY
}

// NewDefaultTty returns the instance for KeyGetter, which is the customized
// version of go-tty.TTY
func NewDefaultTty() (KeyGetter, error) {
tty1, err := tty.Open()
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions history.go
Expand Up @@ -6,6 +6,8 @@ import (
"io"
)

// IHistory is the interface ReadLine can use as container for history.
// It can be set to Editor.History field
type IHistory interface {
Len() int
At(int) string
Expand All @@ -19,10 +21,12 @@ func (*_EmptyHistory) Len() int { return 0 }
// At always returns empty-string because the receiver is dummy.
func (*_EmptyHistory) At(int) string { return "" }

// KeyMap is the class for key-bindings
type KeyMap struct {
KeyMap map[string]KeyFuncT
}

// Editor is the main class to hold the parameter for ReadLine
type Editor struct {
KeyMap
History IHistory
Expand Down

0 comments on commit 2614264

Please sign in to comment.