Fix golint-cli -fast warnings
This commit is contained in:
parent
269b041399
commit
20fd13d133
|
@ -71,6 +71,7 @@ func (b *Buffer) setText(v string) {
|
||||||
b.workingLines[b.workingIndex] = v
|
b.workingLines[b.workingIndex] = v
|
||||||
|
|
||||||
if o != v {
|
if o != v {
|
||||||
|
dummyExecutor("")
|
||||||
// Text is changed.
|
// Text is changed.
|
||||||
// TODO: Call callback function triggered by text changed. And also history search text should reset.
|
// TODO: Call callback function triggered by text changed. And also history search text should reset.
|
||||||
// https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/buffer.py#L380-L384
|
// https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/buffer.py#L380-L384
|
||||||
|
@ -86,6 +87,7 @@ func (b *Buffer) setCursorPosition(p int) {
|
||||||
b.cursorPosition = 0
|
b.cursorPosition = 0
|
||||||
}
|
}
|
||||||
if p != o {
|
if p != o {
|
||||||
|
dummyExecutor("")
|
||||||
// Cursor position is changed.
|
// Cursor position is changed.
|
||||||
// TODO: Call a onCursorPositionChanged function.
|
// TODO: Call a onCursorPositionChanged function.
|
||||||
}
|
}
|
||||||
|
@ -101,14 +103,12 @@ func (b *Buffer) setDocument(d *Document) {
|
||||||
func (b *Buffer) CursorLeft(count int) {
|
func (b *Buffer) CursorLeft(count int) {
|
||||||
l := b.Document().GetCursorLeftPosition(count)
|
l := b.Document().GetCursorLeftPosition(count)
|
||||||
b.cursorPosition += l
|
b.cursorPosition += l
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CursorRight move to right on the current line.
|
// CursorRight move to right on the current line.
|
||||||
func (b *Buffer) CursorRight(count int) {
|
func (b *Buffer) CursorRight(count int) {
|
||||||
l := b.Document().GetCursorRightPosition(count)
|
l := b.Document().GetCursorRightPosition(count)
|
||||||
b.cursorPosition += l
|
b.cursorPosition += l
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CursorUp move cursor to the previous line.
|
// CursorUp move cursor to the previous line.
|
||||||
|
|
|
@ -61,13 +61,11 @@ func (c *CompletionManager) Reset() {
|
||||||
c.selected = -1
|
c.selected = -1
|
||||||
c.verticalScroll = 0
|
c.verticalScroll = 0
|
||||||
c.Update(*NewDocument())
|
c.Update(*NewDocument())
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update to update the suggestions.
|
// Update to update the suggestions.
|
||||||
func (c *CompletionManager) Update(in Document) {
|
func (c *CompletionManager) Update(in Document) {
|
||||||
c.tmp = c.completer(in)
|
c.tmp = c.completer(in)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Previous to select the previous suggestion item.
|
// Previous to select the previous suggestion item.
|
||||||
|
@ -77,7 +75,6 @@ func (c *CompletionManager) Previous() {
|
||||||
}
|
}
|
||||||
c.selected--
|
c.selected--
|
||||||
c.update()
|
c.update()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next to select the next suggestion item.
|
// Next to select the next suggestion item.
|
||||||
|
@ -87,7 +84,6 @@ func (c *CompletionManager) Next() {
|
||||||
}
|
}
|
||||||
c.selected++
|
c.selected++
|
||||||
c.update()
|
c.update()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Completing returns whether the CompletionManager selects something one.
|
// Completing returns whether the CompletionManager selects something one.
|
||||||
|
|
|
@ -30,10 +30,10 @@ func FilterFuzzy(completions []Suggest, sub string, ignoreCase bool) []Suggest {
|
||||||
|
|
||||||
func fuzzyMatch(s, sub string) bool {
|
func fuzzyMatch(s, sub string) bool {
|
||||||
sChars := []rune(s)
|
sChars := []rune(s)
|
||||||
subChars := []rune(sub)
|
|
||||||
sIdx := 0
|
sIdx := 0
|
||||||
|
|
||||||
for _, c := range subChars {
|
// https://staticcheck.io/docs/checks#S1029
|
||||||
|
for _, c := range sub {
|
||||||
found := false
|
found := false
|
||||||
for ; sIdx < len(sChars); sIdx++ {
|
for ; sIdx < len(sChars); sIdx++ {
|
||||||
if sChars[sIdx] == c {
|
if sChars[sIdx] == c {
|
||||||
|
|
|
@ -13,25 +13,21 @@ type VT100Writer struct {
|
||||||
// WriteRaw to write raw byte array
|
// WriteRaw to write raw byte array
|
||||||
func (w *VT100Writer) WriteRaw(data []byte) {
|
func (w *VT100Writer) WriteRaw(data []byte) {
|
||||||
w.buffer = append(w.buffer, data...)
|
w.buffer = append(w.buffer, data...)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write to write safety byte array by removing control sequences.
|
// Write to write safety byte array by removing control sequences.
|
||||||
func (w *VT100Writer) Write(data []byte) {
|
func (w *VT100Writer) Write(data []byte) {
|
||||||
w.WriteRaw(bytes.Replace(data, []byte{0x1b}, []byte{'?'}, -1))
|
w.WriteRaw(bytes.Replace(data, []byte{0x1b}, []byte{'?'}, -1))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteRawStr to write raw string
|
// WriteRawStr to write raw string
|
||||||
func (w *VT100Writer) WriteRawStr(data string) {
|
func (w *VT100Writer) WriteRawStr(data string) {
|
||||||
w.WriteRaw([]byte(data))
|
w.WriteRaw([]byte(data))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteStr to write safety string by removing control sequences.
|
// WriteStr to write safety string by removing control sequences.
|
||||||
func (w *VT100Writer) WriteStr(data string) {
|
func (w *VT100Writer) WriteStr(data string) {
|
||||||
w.Write([]byte(data))
|
w.Write([]byte(data))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Erase */
|
/* Erase */
|
||||||
|
@ -39,37 +35,31 @@ func (w *VT100Writer) WriteStr(data string) {
|
||||||
// EraseScreen erases the screen with the background colour and moves the cursor to home.
|
// EraseScreen erases the screen with the background colour and moves the cursor to home.
|
||||||
func (w *VT100Writer) EraseScreen() {
|
func (w *VT100Writer) EraseScreen() {
|
||||||
w.WriteRaw([]byte{0x1b, '[', '2', 'J'})
|
w.WriteRaw([]byte{0x1b, '[', '2', 'J'})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EraseUp erases the screen from the current line up to the top of the screen.
|
// EraseUp erases the screen from the current line up to the top of the screen.
|
||||||
func (w *VT100Writer) EraseUp() {
|
func (w *VT100Writer) EraseUp() {
|
||||||
w.WriteRaw([]byte{0x1b, '[', '1', 'J'})
|
w.WriteRaw([]byte{0x1b, '[', '1', 'J'})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EraseDown erases the screen from the current line down to the bottom of the screen.
|
// EraseDown erases the screen from the current line down to the bottom of the screen.
|
||||||
func (w *VT100Writer) EraseDown() {
|
func (w *VT100Writer) EraseDown() {
|
||||||
w.WriteRaw([]byte{0x1b, '[', 'J'})
|
w.WriteRaw([]byte{0x1b, '[', 'J'})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EraseStartOfLine erases from the current cursor position to the start of the current line.
|
// EraseStartOfLine erases from the current cursor position to the start of the current line.
|
||||||
func (w *VT100Writer) EraseStartOfLine() {
|
func (w *VT100Writer) EraseStartOfLine() {
|
||||||
w.WriteRaw([]byte{0x1b, '[', '1', 'K'})
|
w.WriteRaw([]byte{0x1b, '[', '1', 'K'})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EraseEndOfLine erases from the current cursor position to the end of the current line.
|
// EraseEndOfLine erases from the current cursor position to the end of the current line.
|
||||||
func (w *VT100Writer) EraseEndOfLine() {
|
func (w *VT100Writer) EraseEndOfLine() {
|
||||||
w.WriteRaw([]byte{0x1b, '[', 'K'})
|
w.WriteRaw([]byte{0x1b, '[', 'K'})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EraseLine erases the entire current line.
|
// EraseLine erases the entire current line.
|
||||||
func (w *VT100Writer) EraseLine() {
|
func (w *VT100Writer) EraseLine() {
|
||||||
w.WriteRaw([]byte{0x1b, '[', '2', 'K'})
|
w.WriteRaw([]byte{0x1b, '[', '2', 'K'})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cursor */
|
/* Cursor */
|
||||||
|
@ -82,7 +72,6 @@ func (w *VT100Writer) ShowCursor() {
|
||||||
// HideCursor hides cursor.
|
// HideCursor hides cursor.
|
||||||
func (w *VT100Writer) HideCursor() {
|
func (w *VT100Writer) HideCursor() {
|
||||||
w.WriteRaw([]byte{0x1b, '[', '?', '2', '5', 'l'})
|
w.WriteRaw([]byte{0x1b, '[', '?', '2', '5', 'l'})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CursorGoTo sets the cursor position where subsequent text will begin.
|
// CursorGoTo sets the cursor position where subsequent text will begin.
|
||||||
|
@ -99,7 +88,6 @@ func (w *VT100Writer) CursorGoTo(row, col int) {
|
||||||
w.WriteRaw([]byte{';'})
|
w.WriteRaw([]byte{';'})
|
||||||
w.WriteRaw([]byte(c))
|
w.WriteRaw([]byte(c))
|
||||||
w.WriteRaw([]byte{'H'})
|
w.WriteRaw([]byte{'H'})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CursorUp moves the cursor up by 'n' rows; the default count is 1.
|
// CursorUp moves the cursor up by 'n' rows; the default count is 1.
|
||||||
|
@ -114,7 +102,6 @@ func (w *VT100Writer) CursorUp(n int) {
|
||||||
w.WriteRaw([]byte{0x1b, '['})
|
w.WriteRaw([]byte{0x1b, '['})
|
||||||
w.WriteRaw([]byte(s))
|
w.WriteRaw([]byte(s))
|
||||||
w.WriteRaw([]byte{'A'})
|
w.WriteRaw([]byte{'A'})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CursorDown moves the cursor down by 'n' rows; the default count is 1.
|
// CursorDown moves the cursor down by 'n' rows; the default count is 1.
|
||||||
|
@ -129,7 +116,6 @@ func (w *VT100Writer) CursorDown(n int) {
|
||||||
w.WriteRaw([]byte{0x1b, '['})
|
w.WriteRaw([]byte{0x1b, '['})
|
||||||
w.WriteRaw([]byte(s))
|
w.WriteRaw([]byte(s))
|
||||||
w.WriteRaw([]byte{'B'})
|
w.WriteRaw([]byte{'B'})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CursorForward moves the cursor forward by 'n' columns; the default count is 1.
|
// CursorForward moves the cursor forward by 'n' columns; the default count is 1.
|
||||||
|
@ -144,7 +130,6 @@ func (w *VT100Writer) CursorForward(n int) {
|
||||||
w.WriteRaw([]byte{0x1b, '['})
|
w.WriteRaw([]byte{0x1b, '['})
|
||||||
w.WriteRaw([]byte(s))
|
w.WriteRaw([]byte(s))
|
||||||
w.WriteRaw([]byte{'C'})
|
w.WriteRaw([]byte{'C'})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CursorBackward moves the cursor backward by 'n' columns; the default count is 1.
|
// CursorBackward moves the cursor backward by 'n' columns; the default count is 1.
|
||||||
|
@ -159,26 +144,22 @@ func (w *VT100Writer) CursorBackward(n int) {
|
||||||
w.WriteRaw([]byte{0x1b, '['})
|
w.WriteRaw([]byte{0x1b, '['})
|
||||||
w.WriteRaw([]byte(s))
|
w.WriteRaw([]byte(s))
|
||||||
w.WriteRaw([]byte{'D'})
|
w.WriteRaw([]byte{'D'})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AskForCPR asks for a cursor position report (CPR).
|
// AskForCPR asks for a cursor position report (CPR).
|
||||||
func (w *VT100Writer) AskForCPR() {
|
func (w *VT100Writer) AskForCPR() {
|
||||||
// CPR: Cursor Position Request.
|
// CPR: Cursor Position Request.
|
||||||
w.WriteRaw([]byte{0x1b, '[', '6', 'n'})
|
w.WriteRaw([]byte{0x1b, '[', '6', 'n'})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveCursor saves current cursor position.
|
// SaveCursor saves current cursor position.
|
||||||
func (w *VT100Writer) SaveCursor() {
|
func (w *VT100Writer) SaveCursor() {
|
||||||
w.WriteRaw([]byte{0x1b, '[', 's'})
|
w.WriteRaw([]byte{0x1b, '[', 's'})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnSaveCursor restores cursor position after a Save Cursor.
|
// UnSaveCursor restores cursor position after a Save Cursor.
|
||||||
func (w *VT100Writer) UnSaveCursor() {
|
func (w *VT100Writer) UnSaveCursor() {
|
||||||
w.WriteRaw([]byte{0x1b, '[', 'u'})
|
w.WriteRaw([]byte{0x1b, '[', 'u'})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Scrolling */
|
/* Scrolling */
|
||||||
|
@ -186,13 +167,11 @@ func (w *VT100Writer) UnSaveCursor() {
|
||||||
// ScrollDown scrolls display down one line.
|
// ScrollDown scrolls display down one line.
|
||||||
func (w *VT100Writer) ScrollDown() {
|
func (w *VT100Writer) ScrollDown() {
|
||||||
w.WriteRaw([]byte{0x1b, 'D'})
|
w.WriteRaw([]byte{0x1b, 'D'})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScrollUp scroll display up one line.
|
// ScrollUp scroll display up one line.
|
||||||
func (w *VT100Writer) ScrollUp() {
|
func (w *VT100Writer) ScrollUp() {
|
||||||
w.WriteRaw([]byte{0x1b, 'M'})
|
w.WriteRaw([]byte{0x1b, 'M'})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Title */
|
/* Title */
|
||||||
|
@ -220,13 +199,11 @@ func (w *VT100Writer) SetTitle(title string) {
|
||||||
w.WriteRaw([]byte{0x1b, ']', '2', ';'})
|
w.WriteRaw([]byte{0x1b, ']', '2', ';'})
|
||||||
w.WriteRaw(titleBytes)
|
w.WriteRaw(titleBytes)
|
||||||
w.WriteRaw([]byte{0x07})
|
w.WriteRaw([]byte{0x07})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearTitle clears a title of terminal window.
|
// ClearTitle clears a title of terminal window.
|
||||||
func (w *VT100Writer) ClearTitle() {
|
func (w *VT100Writer) ClearTitle() {
|
||||||
w.WriteRaw([]byte{0x1b, ']', '2', ';', 0x07})
|
w.WriteRaw([]byte{0x1b, ']', '2', ';', 0x07})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Font */
|
/* Font */
|
||||||
|
@ -240,7 +217,6 @@ func (w *VT100Writer) SetColor(fg, bg Color, bold bool) {
|
||||||
// Details are https://github.com/c-bata/go-prompt/pull/85
|
// Details are https://github.com/c-bata/go-prompt/pull/85
|
||||||
w.SetDisplayAttributes(fg, bg, DisplayReset)
|
w.SetDisplayAttributes(fg, bg, DisplayReset)
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDisplayAttributes to set VT100 display attributes.
|
// SetDisplayAttributes to set VT100 display attributes.
|
||||||
|
@ -269,7 +245,6 @@ func (w *VT100Writer) SetDisplayAttributes(fg, bg Color, attrs ...DisplayAttribu
|
||||||
b = backgroundANSIColors[DefaultColor]
|
b = backgroundANSIColors[DefaultColor]
|
||||||
}
|
}
|
||||||
w.WriteRaw(b)
|
w.WriteRaw(b)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var displayAttributeParameters = map[DisplayAttribute][]byte{
|
var displayAttributeParameters = map[DisplayAttribute][]byte{
|
||||||
|
|
|
@ -28,7 +28,7 @@ func (w *WindowsWriter) Flush() error {
|
||||||
var _ ConsoleWriter = &WindowsWriter{}
|
var _ ConsoleWriter = &WindowsWriter{}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// Deprecated: Please use NewStdoutWriter
|
// NewStandardOutputWriter is Deprecated: Please use NewStdoutWriter
|
||||||
NewStandardOutputWriter = NewStdoutWriter
|
NewStandardOutputWriter = NewStdoutWriter
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -221,7 +221,7 @@ func (p *Prompt) handleKeyBinding(key Key) bool {
|
||||||
func (p *Prompt) handleASCIICodeBinding(b []byte) bool {
|
func (p *Prompt) handleASCIICodeBinding(b []byte) bool {
|
||||||
checked := false
|
checked := false
|
||||||
for _, kb := range p.ASCIICodeBindings {
|
for _, kb := range p.ASCIICodeBindings {
|
||||||
if bytes.Compare(kb.ASCIICode, b) == 0 {
|
if bytes.Equal(kb.ASCIICode, b) {
|
||||||
kb.Fn(p.buf)
|
kb.Fn(p.buf)
|
||||||
checked = true
|
checked = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,14 +75,12 @@ func (r *Render) prepareArea(lines int) {
|
||||||
for i := 0; i < lines; i++ {
|
for i := 0; i < lines; i++ {
|
||||||
r.out.ScrollUp()
|
r.out.ScrollUp()
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateWinSize called when window size is changed.
|
// UpdateWinSize called when window size is changed.
|
||||||
func (r *Render) UpdateWinSize(ws *WinSize) {
|
func (r *Render) UpdateWinSize(ws *WinSize) {
|
||||||
r.row = ws.Row
|
r.row = ws.Row
|
||||||
r.col = ws.Col
|
r.col = ws.Col
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Render) renderWindowTooSmall() {
|
func (r *Render) renderWindowTooSmall() {
|
||||||
|
@ -90,7 +88,6 @@ func (r *Render) renderWindowTooSmall() {
|
||||||
r.out.EraseScreen()
|
r.out.EraseScreen()
|
||||||
r.out.SetColor(DarkRed, White, false)
|
r.out.SetColor(DarkRed, White, false)
|
||||||
r.out.WriteStr("Your console window is too small...")
|
r.out.WriteStr("Your console window is too small...")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Render) renderCompletion(buf *Buffer, completions *CompletionManager) {
|
func (r *Render) renderCompletion(buf *Buffer, completions *CompletionManager) {
|
||||||
|
@ -167,7 +164,6 @@ func (r *Render) renderCompletion(buf *Buffer, completions *CompletionManager) {
|
||||||
|
|
||||||
r.out.CursorUp(windowHeight)
|
r.out.CursorUp(windowHeight)
|
||||||
r.out.SetColor(DefaultColor, DefaultColor, false)
|
r.out.SetColor(DefaultColor, DefaultColor, false)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render renders to the console.
|
// Render renders to the console.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package prompt
|
package prompt
|
||||||
|
|
||||||
func dummyExecutor(in string) { return }
|
func dummyExecutor(in string) {}
|
||||||
|
|
||||||
// Input get the input data from the user and return it.
|
// Input get the input data from the user and return it.
|
||||||
func Input(prefix string, completer Completer, opts ...Option) string {
|
func Input(prefix string, completer Completer, opts ...Option) string {
|
||||||
|
|
Loading…
Reference in New Issue