Refactor variable names
This commit is contained in:
parent
3240009ad5
commit
3e90ac1b91
|
@ -24,7 +24,7 @@ type Suggest struct {
|
|||
type CompletionManager struct {
|
||||
selected int // -1 means nothing one is selected.
|
||||
tmp []Suggest
|
||||
Max uint16
|
||||
max uint16
|
||||
completer Completer
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ func (c *CompletionManager) Completing() bool {
|
|||
}
|
||||
|
||||
func (c *CompletionManager) update() {
|
||||
max := int(c.Max)
|
||||
max := int(c.max)
|
||||
if len(c.tmp) < max {
|
||||
max = len(c.tmp)
|
||||
}
|
||||
|
@ -120,17 +120,17 @@ func formatTexts(o []string, max int, prefix, suffix string) (new []string, widt
|
|||
return n, lenPrefix + width + lenSuffix
|
||||
}
|
||||
|
||||
func formatCompletions(completions []Suggest, max int) (new []Suggest, width int) {
|
||||
num := len(completions)
|
||||
func formatSuggestions(suggests []Suggest, max int) (new []Suggest, width int) {
|
||||
num := len(suggests)
|
||||
new = make([]Suggest, num)
|
||||
|
||||
left := make([]string, num)
|
||||
for i := 0; i < num; i++ {
|
||||
left[i] = completions[i].Text
|
||||
left[i] = suggests[i].Text
|
||||
}
|
||||
right := make([]string, num)
|
||||
for i := 0; i < num; i++ {
|
||||
right[i] = completions[i].Description
|
||||
right[i] = suggests[i].Description
|
||||
}
|
||||
|
||||
left, leftWidth := formatTexts(left, max, leftPrefix, leftSuffix)
|
||||
|
@ -148,7 +148,7 @@ func formatCompletions(completions []Suggest, max int) (new []Suggest, width int
|
|||
func NewCompletionManager(completer Completer, max uint16) *CompletionManager {
|
||||
return &CompletionManager{
|
||||
selected: -1,
|
||||
Max: max,
|
||||
max: max,
|
||||
completer: completer,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ func TestFormatShortSuggestion(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, s := range scenarioTable {
|
||||
actual, width := formatCompletions(s.in, s.max)
|
||||
actual, width := formatSuggestions(s.in, s.max)
|
||||
if width != s.exWidth {
|
||||
t.Errorf("[scenario %d] Want %d but got %d\n", i, s.exWidth, width)
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ func OptionSelectedDescriptionBGColor(x Color) option {
|
|||
|
||||
func OptionMaxSuggestion(x uint16) option {
|
||||
return func(p *Prompt) error {
|
||||
p.completion.Max = x
|
||||
p.completion.max = x
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ func (r *Render) renderWindowTooSmall() {
|
|||
}
|
||||
|
||||
func (r *Render) renderCompletion(buf *Buffer, completions *CompletionManager) {
|
||||
max := completions.Max
|
||||
max := completions.max
|
||||
if max > r.row {
|
||||
max = r.row
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ func (r *Render) renderCompletion(buf *Buffer, completions *CompletionManager) {
|
|||
suggestions = suggestions[:max]
|
||||
}
|
||||
|
||||
formatted, width := formatCompletions(
|
||||
formatted, width := formatSuggestions(
|
||||
suggestions,
|
||||
int(r.col)-len(r.prefix),
|
||||
)
|
||||
|
@ -131,7 +131,7 @@ func (r *Render) Render(buffer *Buffer, completion *CompletionManager) {
|
|||
|
||||
// prepare area
|
||||
line := buffer.Text()
|
||||
h := ((len(r.prefix) + len(line)) / int(r.col)) + 1 + int(completion.Max)
|
||||
h := ((len(r.prefix) + len(line)) / int(r.col)) + 1 + int(completion.max)
|
||||
if h > int(r.row) || completionMargin > int(r.col) {
|
||||
r.renderWindowTooSmall()
|
||||
return
|
||||
|
|
|
@ -56,7 +56,7 @@ func TestFormatCompletion(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, s := range scenarioTable {
|
||||
ac, width := formatCompletions(s.completions, s.maxWidth)
|
||||
ac, width := formatSuggestions(s.completions, s.maxWidth)
|
||||
if !reflect.DeepEqual(ac, s.expected) {
|
||||
t.Errorf("Should be %#v, but got %#v", s.expected, ac)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue