Run goimports

This commit is contained in:
c-bata 2017-07-18 02:01:24 +09:00
parent 66c8d4ca5c
commit d916343aba
6 changed files with 27 additions and 28 deletions

@ -24,7 +24,6 @@ func main() {
pt := prompt.NewPrompt(
executor,
completer,
prompt.OptionMaxCompletions(8),
prompt.OptionPrefix(">>> "),
prompt.OptionTitle("sqlite3-cli"),
prompt.OptionOutputTextColor(prompt.DarkGray),

@ -10,7 +10,7 @@ type Buffer struct {
workingIndex int
CursorPosition int
cacheDocument *Document
preferredColumn int // Remember the original column for the next up/down movement.
preferredColumn int // Remember the original column for the next up/down movement.
}
// Text returns string of the current line.

@ -142,11 +142,11 @@ func NewPrompt(executor Executor, completer Completer, opts ...option) *Prompt {
selectedSuggestionTextColor: Black,
selectedSuggestionBGColor: Turquoise,
},
buf: NewBuffer(),
executor: executor,
completer: completer,
buf: NewBuffer(),
executor: executor,
completer: completer,
maxCompletions: 6,
selected: -1,
selected: -1,
}
for _, opt := range opts {

@ -17,7 +17,7 @@ type Prompt struct {
executor Executor
completer Completer
maxCompletions uint16
selected int // -1 means nothing one is selected.
selected int // -1 means nothing one is selected.
}
func (p *Prompt) Run() {

@ -3,11 +3,11 @@ package prompt
import "strings"
type Render struct {
out ConsoleWriter
prefix string
title string
row uint16
col uint16
out ConsoleWriter
prefix string
title string
row uint16
col uint16
// colors
prefixTextColor Color
prefixBGColor Color
@ -80,14 +80,14 @@ func (r *Render) renderCompletion(buf *Buffer, words []string, max uint16, selec
formatted, width := formatCompletions(
words,
int(r.col) - len(r.prefix),
int(r.col)-len(r.prefix),
" ",
" ",
)
l := len(formatted)
d := (len(r.prefix) + len(buf.Document().TextBeforeCursor())) % int(r.col)
if d + width > int(r.col) {
if d+width > int(r.col) {
r.out.CursorBackward(d + width - int(r.col))
}
@ -102,7 +102,7 @@ func (r *Render) renderCompletion(buf *Buffer, words []string, max uint16, selec
r.out.WriteStr(formatted[i])
r.out.CursorBackward(width)
}
if d + width > int(r.col) {
if d+width > int(r.col) {
r.out.CursorForward(d + width - int(r.col))
}
@ -172,15 +172,15 @@ func formatCompletions(words []string, max int, prefix string, suffix string) (n
}
}
if len(prefix) + width + len(suffix) > max {
if len(prefix)+width+len(suffix) > max {
width = max - len(prefix) - len(suffix)
}
for i := 0; i < num; i++ {
if l := len(words[i]); l > width {
new[i] = prefix + words[i][:width - len("...")] + "..." + suffix
} else if l < width {
spaces := strings.Repeat(" ", width - len([]rune(words[i])))
new[i] = prefix + words[i][:width-len("...")] + "..." + suffix
} else if l < width {
spaces := strings.Repeat(" ", width-len([]rune(words[i])))
new[i] = prefix + words[i] + spaces + suffix
} else {
new[i] = prefix + words[i] + suffix

@ -6,15 +6,15 @@ import (
)
func TestFormatCompletion(t *testing.T) {
scenarioTable := [] struct {
scenario string
completions []string
prefix string
suffix string
expected []string
maxWidth int
scenarioTable := []struct {
scenario string
completions []string
prefix string
suffix string
expected []string
maxWidth int
expectedWidth int
} {
}{
{
scenario: "",
completions: []string{
@ -31,7 +31,7 @@ func TestFormatCompletion(t *testing.T) {
" insert ",
" where ",
},
maxWidth: 20,
maxWidth: 20,
expectedWidth: 8,
},
}