repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
c-bata/go-prompt
option.go
OptionScrollbarBGColor
func OptionScrollbarBGColor(x Color) Option { return func(p *Prompt) error { p.renderer.scrollbarBGColor = x return nil } }
go
func OptionScrollbarBGColor(x Color) Option { return func(p *Prompt) error { p.renderer.scrollbarBGColor = x return nil } }
[ "func", "OptionScrollbarBGColor", "(", "x", "Color", ")", "Option", "{", "return", "func", "(", "p", "*", "Prompt", ")", "error", "{", "p", ".", "renderer", ".", "scrollbarBGColor", "=", "x", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// OptionScrollbarBGColor to change a background color of scrollbar.
[ "OptionScrollbarBGColor", "to", "change", "a", "background", "color", "of", "scrollbar", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/option.go#L177-L182
train
c-bata/go-prompt
option.go
OptionMaxSuggestion
func OptionMaxSuggestion(x uint16) Option { return func(p *Prompt) error { p.completion.max = x return nil } }
go
func OptionMaxSuggestion(x uint16) Option { return func(p *Prompt) error { p.completion.max = x return nil } }
[ "func", "OptionMaxSuggestion", "(", "x", "uint16", ")", "Option", "{", "return", "func", "(", "p", "*", "Prompt", ")", "error", "{", "p", ".", "completion", ".", "max", "=", "x", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// OptionMaxSuggestion specify the max number of displayed suggestions.
[ "OptionMaxSuggestion", "specify", "the", "max", "number", "of", "displayed", "suggestions", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/option.go#L185-L190
train
c-bata/go-prompt
option.go
OptionHistory
func OptionHistory(x []string) Option { return func(p *Prompt) error { p.history.histories = x p.history.Clear() return nil } }
go
func OptionHistory(x []string) Option { return func(p *Prompt) error { p.history.histories = x p.history.Clear() return nil } }
[ "func", "OptionHistory", "(", "x", "[", "]", "string", ")", "Option", "{", "return", "func", "(", "p", "*", "Prompt", ")", "error", "{", "p", ".", "history", ".", "histories", "=", "x", "\n", "p", ".", "history", ".", "Clear", "(", ")", "\n", "re...
// OptionHistory to set history expressed by string array.
[ "OptionHistory", "to", "set", "history", "expressed", "by", "string", "array", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/option.go#L193-L199
train
c-bata/go-prompt
option.go
OptionSwitchKeyBindMode
func OptionSwitchKeyBindMode(m KeyBindMode) Option { return func(p *Prompt) error { p.keyBindMode = m return nil } }
go
func OptionSwitchKeyBindMode(m KeyBindMode) Option { return func(p *Prompt) error { p.keyBindMode = m return nil } }
[ "func", "OptionSwitchKeyBindMode", "(", "m", "KeyBindMode", ")", "Option", "{", "return", "func", "(", "p", "*", "Prompt", ")", "error", "{", "p", ".", "keyBindMode", "=", "m", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// OptionSwitchKeyBindMode set a key bind mode.
[ "OptionSwitchKeyBindMode", "set", "a", "key", "bind", "mode", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/option.go#L202-L207
train
c-bata/go-prompt
option.go
OptionAddKeyBind
func OptionAddKeyBind(b ...KeyBind) Option { return func(p *Prompt) error { p.keyBindings = append(p.keyBindings, b...) return nil } }
go
func OptionAddKeyBind(b ...KeyBind) Option { return func(p *Prompt) error { p.keyBindings = append(p.keyBindings, b...) return nil } }
[ "func", "OptionAddKeyBind", "(", "b", "...", "KeyBind", ")", "Option", "{", "return", "func", "(", "p", "*", "Prompt", ")", "error", "{", "p", ".", "keyBindings", "=", "append", "(", "p", ".", "keyBindings", ",", "b", "...", ")", "\n", "return", "nil...
// OptionAddKeyBind to set a custom key bind.
[ "OptionAddKeyBind", "to", "set", "a", "custom", "key", "bind", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/option.go#L214-L219
train
c-bata/go-prompt
option.go
OptionAddASCIICodeBind
func OptionAddASCIICodeBind(b ...ASCIICodeBind) Option { return func(p *Prompt) error { p.ASCIICodeBindings = append(p.ASCIICodeBindings, b...) return nil } }
go
func OptionAddASCIICodeBind(b ...ASCIICodeBind) Option { return func(p *Prompt) error { p.ASCIICodeBindings = append(p.ASCIICodeBindings, b...) return nil } }
[ "func", "OptionAddASCIICodeBind", "(", "b", "...", "ASCIICodeBind", ")", "Option", "{", "return", "func", "(", "p", "*", "Prompt", ")", "error", "{", "p", ".", "ASCIICodeBindings", "=", "append", "(", "p", ".", "ASCIICodeBindings", ",", "b", "...", ")", ...
// OptionAddASCIICodeBind to set a custom key bind.
[ "OptionAddASCIICodeBind", "to", "set", "a", "custom", "key", "bind", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/option.go#L222-L227
train
c-bata/go-prompt
option.go
OptionShowCompletionAtStart
func OptionShowCompletionAtStart() Option { return func(p *Prompt) error { p.completion.showAtStart = true return nil } }
go
func OptionShowCompletionAtStart() Option { return func(p *Prompt) error { p.completion.showAtStart = true return nil } }
[ "func", "OptionShowCompletionAtStart", "(", ")", "Option", "{", "return", "func", "(", "p", "*", "Prompt", ")", "error", "{", "p", ".", "completion", ".", "showAtStart", "=", "true", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// OptionShowCompletionAtStart to set completion window is open at start.
[ "OptionShowCompletionAtStart", "to", "set", "completion", "window", "is", "open", "at", "start", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/option.go#L230-L235
train
c-bata/go-prompt
option.go
New
func New(executor Executor, completer Completer, opts ...Option) *Prompt { defaultWriter := NewStdoutWriter() registerConsoleWriter(defaultWriter) pt := &Prompt{ in: NewStandardInputParser(), renderer: &Render{ prefix: "> ", out: defaultWriter, livePrefixCallback: func() (string, bool) { return "", false }, prefixTextColor: Blue, prefixBGColor: DefaultColor, inputTextColor: DefaultColor, inputBGColor: DefaultColor, previewSuggestionTextColor: Green, previewSuggestionBGColor: DefaultColor, suggestionTextColor: White, suggestionBGColor: Cyan, selectedSuggestionTextColor: Black, selectedSuggestionBGColor: Turquoise, descriptionTextColor: Black, descriptionBGColor: Turquoise, selectedDescriptionTextColor: White, selectedDescriptionBGColor: Cyan, scrollbarThumbColor: DarkGray, scrollbarBGColor: Cyan, }, buf: NewBuffer(), executor: executor, history: NewHistory(), completion: NewCompletionManager(completer, 6), keyBindMode: EmacsKeyBind, // All the above assume that bash is running in the default Emacs setting } for _, opt := range opts { if err := opt(pt); err != nil { panic(err) } } return pt }
go
func New(executor Executor, completer Completer, opts ...Option) *Prompt { defaultWriter := NewStdoutWriter() registerConsoleWriter(defaultWriter) pt := &Prompt{ in: NewStandardInputParser(), renderer: &Render{ prefix: "> ", out: defaultWriter, livePrefixCallback: func() (string, bool) { return "", false }, prefixTextColor: Blue, prefixBGColor: DefaultColor, inputTextColor: DefaultColor, inputBGColor: DefaultColor, previewSuggestionTextColor: Green, previewSuggestionBGColor: DefaultColor, suggestionTextColor: White, suggestionBGColor: Cyan, selectedSuggestionTextColor: Black, selectedSuggestionBGColor: Turquoise, descriptionTextColor: Black, descriptionBGColor: Turquoise, selectedDescriptionTextColor: White, selectedDescriptionBGColor: Cyan, scrollbarThumbColor: DarkGray, scrollbarBGColor: Cyan, }, buf: NewBuffer(), executor: executor, history: NewHistory(), completion: NewCompletionManager(completer, 6), keyBindMode: EmacsKeyBind, // All the above assume that bash is running in the default Emacs setting } for _, opt := range opts { if err := opt(pt); err != nil { panic(err) } } return pt }
[ "func", "New", "(", "executor", "Executor", ",", "completer", "Completer", ",", "opts", "...", "Option", ")", "*", "Prompt", "{", "defaultWriter", ":=", "NewStdoutWriter", "(", ")", "\n", "registerConsoleWriter", "(", "defaultWriter", ")", "\n", "pt", ":=", ...
// New returns a Prompt with powerful auto-completion.
[ "New", "returns", "a", "Prompt", "with", "powerful", "auto", "-", "completion", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/option.go#L238-L278
train
c-bata/go-prompt
document.go
GetCharRelativeToCursor
func (d *Document) GetCharRelativeToCursor(offset int) (r rune) { s := d.Text cnt := 0 for len(s) > 0 { cnt++ r, size := utf8.DecodeRuneInString(s) if cnt == d.cursorPosition+offset { return r } s = s[size:] } return 0 }
go
func (d *Document) GetCharRelativeToCursor(offset int) (r rune) { s := d.Text cnt := 0 for len(s) > 0 { cnt++ r, size := utf8.DecodeRuneInString(s) if cnt == d.cursorPosition+offset { return r } s = s[size:] } return 0 }
[ "func", "(", "d", "*", "Document", ")", "GetCharRelativeToCursor", "(", "offset", "int", ")", "(", "r", "rune", ")", "{", "s", ":=", "d", ".", "Text", "\n", "cnt", ":=", "0", "\n", "for", "len", "(", "s", ")", ">", "0", "{", "cnt", "++", "\n", ...
// GetCharRelativeToCursor return character relative to cursor position, or empty string
[ "GetCharRelativeToCursor", "return", "character", "relative", "to", "cursor", "position", "or", "empty", "string" ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L41-L54
train
c-bata/go-prompt
document.go
TextBeforeCursor
func (d *Document) TextBeforeCursor() string { r := []rune(d.Text) return string(r[:d.cursorPosition]) }
go
func (d *Document) TextBeforeCursor() string { r := []rune(d.Text) return string(r[:d.cursorPosition]) }
[ "func", "(", "d", "*", "Document", ")", "TextBeforeCursor", "(", ")", "string", "{", "r", ":=", "[", "]", "rune", "(", "d", ".", "Text", ")", "\n", "return", "string", "(", "r", "[", ":", "d", ".", "cursorPosition", "]", ")", "\n", "}" ]
// TextBeforeCursor returns the text before the cursor.
[ "TextBeforeCursor", "returns", "the", "text", "before", "the", "cursor", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L57-L60
train
c-bata/go-prompt
document.go
TextAfterCursor
func (d *Document) TextAfterCursor() string { r := []rune(d.Text) return string(r[d.cursorPosition:]) }
go
func (d *Document) TextAfterCursor() string { r := []rune(d.Text) return string(r[d.cursorPosition:]) }
[ "func", "(", "d", "*", "Document", ")", "TextAfterCursor", "(", ")", "string", "{", "r", ":=", "[", "]", "rune", "(", "d", ".", "Text", ")", "\n", "return", "string", "(", "r", "[", "d", ".", "cursorPosition", ":", "]", ")", "\n", "}" ]
// TextAfterCursor returns the text after the cursor.
[ "TextAfterCursor", "returns", "the", "text", "after", "the", "cursor", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L63-L66
train
c-bata/go-prompt
document.go
GetWordBeforeCursor
func (d *Document) GetWordBeforeCursor() string { x := d.TextBeforeCursor() return x[d.FindStartOfPreviousWord():] }
go
func (d *Document) GetWordBeforeCursor() string { x := d.TextBeforeCursor() return x[d.FindStartOfPreviousWord():] }
[ "func", "(", "d", "*", "Document", ")", "GetWordBeforeCursor", "(", ")", "string", "{", "x", ":=", "d", ".", "TextBeforeCursor", "(", ")", "\n", "return", "x", "[", "d", ".", "FindStartOfPreviousWord", "(", ")", ":", "]", "\n", "}" ]
// GetWordBeforeCursor returns the word before the cursor. // If we have whitespace before the cursor this returns an empty string.
[ "GetWordBeforeCursor", "returns", "the", "word", "before", "the", "cursor", ".", "If", "we", "have", "whitespace", "before", "the", "cursor", "this", "returns", "an", "empty", "string", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L70-L73
train
c-bata/go-prompt
document.go
GetWordAfterCursor
func (d *Document) GetWordAfterCursor() string { x := d.TextAfterCursor() return x[:d.FindEndOfCurrentWord()] }
go
func (d *Document) GetWordAfterCursor() string { x := d.TextAfterCursor() return x[:d.FindEndOfCurrentWord()] }
[ "func", "(", "d", "*", "Document", ")", "GetWordAfterCursor", "(", ")", "string", "{", "x", ":=", "d", ".", "TextAfterCursor", "(", ")", "\n", "return", "x", "[", ":", "d", ".", "FindEndOfCurrentWord", "(", ")", "]", "\n", "}" ]
// GetWordAfterCursor returns the word after the cursor. // If we have whitespace after the cursor this returns an empty string.
[ "GetWordAfterCursor", "returns", "the", "word", "after", "the", "cursor", ".", "If", "we", "have", "whitespace", "after", "the", "cursor", "this", "returns", "an", "empty", "string", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L77-L80
train
c-bata/go-prompt
document.go
GetWordBeforeCursorWithSpace
func (d *Document) GetWordBeforeCursorWithSpace() string { x := d.TextBeforeCursor() return x[d.FindStartOfPreviousWordWithSpace():] }
go
func (d *Document) GetWordBeforeCursorWithSpace() string { x := d.TextBeforeCursor() return x[d.FindStartOfPreviousWordWithSpace():] }
[ "func", "(", "d", "*", "Document", ")", "GetWordBeforeCursorWithSpace", "(", ")", "string", "{", "x", ":=", "d", ".", "TextBeforeCursor", "(", ")", "\n", "return", "x", "[", "d", ".", "FindStartOfPreviousWordWithSpace", "(", ")", ":", "]", "\n", "}" ]
// GetWordBeforeCursorWithSpace returns the word before the cursor. // Unlike GetWordBeforeCursor, it returns string containing space
[ "GetWordBeforeCursorWithSpace", "returns", "the", "word", "before", "the", "cursor", ".", "Unlike", "GetWordBeforeCursor", "it", "returns", "string", "containing", "space" ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L84-L87
train
c-bata/go-prompt
document.go
GetWordAfterCursorWithSpace
func (d *Document) GetWordAfterCursorWithSpace() string { x := d.TextAfterCursor() return x[:d.FindEndOfCurrentWordWithSpace()] }
go
func (d *Document) GetWordAfterCursorWithSpace() string { x := d.TextAfterCursor() return x[:d.FindEndOfCurrentWordWithSpace()] }
[ "func", "(", "d", "*", "Document", ")", "GetWordAfterCursorWithSpace", "(", ")", "string", "{", "x", ":=", "d", ".", "TextAfterCursor", "(", ")", "\n", "return", "x", "[", ":", "d", ".", "FindEndOfCurrentWordWithSpace", "(", ")", "]", "\n", "}" ]
// GetWordAfterCursorWithSpace returns the word after the cursor. // Unlike GetWordAfterCursor, it returns string containing space
[ "GetWordAfterCursorWithSpace", "returns", "the", "word", "after", "the", "cursor", ".", "Unlike", "GetWordAfterCursor", "it", "returns", "string", "containing", "space" ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L91-L94
train
c-bata/go-prompt
document.go
GetWordBeforeCursorUntilSeparator
func (d *Document) GetWordBeforeCursorUntilSeparator(sep string) string { x := d.TextBeforeCursor() return x[d.FindStartOfPreviousWordUntilSeparator(sep):] }
go
func (d *Document) GetWordBeforeCursorUntilSeparator(sep string) string { x := d.TextBeforeCursor() return x[d.FindStartOfPreviousWordUntilSeparator(sep):] }
[ "func", "(", "d", "*", "Document", ")", "GetWordBeforeCursorUntilSeparator", "(", "sep", "string", ")", "string", "{", "x", ":=", "d", ".", "TextBeforeCursor", "(", ")", "\n", "return", "x", "[", "d", ".", "FindStartOfPreviousWordUntilSeparator", "(", "sep", ...
// GetWordBeforeCursorUntilSeparator returns the text before the cursor until next separator.
[ "GetWordBeforeCursorUntilSeparator", "returns", "the", "text", "before", "the", "cursor", "until", "next", "separator", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L97-L100
train
c-bata/go-prompt
document.go
GetWordAfterCursorUntilSeparator
func (d *Document) GetWordAfterCursorUntilSeparator(sep string) string { x := d.TextAfterCursor() return x[:d.FindEndOfCurrentWordUntilSeparator(sep)] }
go
func (d *Document) GetWordAfterCursorUntilSeparator(sep string) string { x := d.TextAfterCursor() return x[:d.FindEndOfCurrentWordUntilSeparator(sep)] }
[ "func", "(", "d", "*", "Document", ")", "GetWordAfterCursorUntilSeparator", "(", "sep", "string", ")", "string", "{", "x", ":=", "d", ".", "TextAfterCursor", "(", ")", "\n", "return", "x", "[", ":", "d", ".", "FindEndOfCurrentWordUntilSeparator", "(", "sep",...
// GetWordAfterCursorUntilSeparator returns the text after the cursor until next separator.
[ "GetWordAfterCursorUntilSeparator", "returns", "the", "text", "after", "the", "cursor", "until", "next", "separator", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L103-L106
train
c-bata/go-prompt
document.go
GetWordBeforeCursorUntilSeparatorIgnoreNextToCursor
func (d *Document) GetWordBeforeCursorUntilSeparatorIgnoreNextToCursor(sep string) string { x := d.TextBeforeCursor() return x[d.FindStartOfPreviousWordUntilSeparatorIgnoreNextToCursor(sep):] }
go
func (d *Document) GetWordBeforeCursorUntilSeparatorIgnoreNextToCursor(sep string) string { x := d.TextBeforeCursor() return x[d.FindStartOfPreviousWordUntilSeparatorIgnoreNextToCursor(sep):] }
[ "func", "(", "d", "*", "Document", ")", "GetWordBeforeCursorUntilSeparatorIgnoreNextToCursor", "(", "sep", "string", ")", "string", "{", "x", ":=", "d", ".", "TextBeforeCursor", "(", ")", "\n", "return", "x", "[", "d", ".", "FindStartOfPreviousWordUntilSeparatorIg...
// GetWordBeforeCursorUntilSeparatorIgnoreNextToCursor returns the word before the cursor. // Unlike GetWordBeforeCursor, it returns string containing space
[ "GetWordBeforeCursorUntilSeparatorIgnoreNextToCursor", "returns", "the", "word", "before", "the", "cursor", ".", "Unlike", "GetWordBeforeCursor", "it", "returns", "string", "containing", "space" ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L110-L113
train
c-bata/go-prompt
document.go
GetWordAfterCursorUntilSeparatorIgnoreNextToCursor
func (d *Document) GetWordAfterCursorUntilSeparatorIgnoreNextToCursor(sep string) string { x := d.TextAfterCursor() return x[:d.FindEndOfCurrentWordUntilSeparatorIgnoreNextToCursor(sep)] }
go
func (d *Document) GetWordAfterCursorUntilSeparatorIgnoreNextToCursor(sep string) string { x := d.TextAfterCursor() return x[:d.FindEndOfCurrentWordUntilSeparatorIgnoreNextToCursor(sep)] }
[ "func", "(", "d", "*", "Document", ")", "GetWordAfterCursorUntilSeparatorIgnoreNextToCursor", "(", "sep", "string", ")", "string", "{", "x", ":=", "d", ".", "TextAfterCursor", "(", ")", "\n", "return", "x", "[", ":", "d", ".", "FindEndOfCurrentWordUntilSeparator...
// GetWordAfterCursorUntilSeparatorIgnoreNextToCursor returns the word after the cursor. // Unlike GetWordAfterCursor, it returns string containing space
[ "GetWordAfterCursorUntilSeparatorIgnoreNextToCursor", "returns", "the", "word", "after", "the", "cursor", ".", "Unlike", "GetWordAfterCursor", "it", "returns", "string", "containing", "space" ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L117-L120
train
c-bata/go-prompt
document.go
FindStartOfPreviousWord
func (d *Document) FindStartOfPreviousWord() int { x := d.TextBeforeCursor() i := strings.LastIndexByte(x, ' ') if i != -1 { return i + 1 } return 0 }
go
func (d *Document) FindStartOfPreviousWord() int { x := d.TextBeforeCursor() i := strings.LastIndexByte(x, ' ') if i != -1 { return i + 1 } return 0 }
[ "func", "(", "d", "*", "Document", ")", "FindStartOfPreviousWord", "(", ")", "int", "{", "x", ":=", "d", ".", "TextBeforeCursor", "(", ")", "\n", "i", ":=", "strings", ".", "LastIndexByte", "(", "x", ",", "' '", ")", "\n", "if", "i", "!=", "-", "1"...
// FindStartOfPreviousWord returns an index relative to the cursor position // pointing to the start of the previous word. Return 0 if nothing was found.
[ "FindStartOfPreviousWord", "returns", "an", "index", "relative", "to", "the", "cursor", "position", "pointing", "to", "the", "start", "of", "the", "previous", "word", ".", "Return", "0", "if", "nothing", "was", "found", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L124-L131
train
c-bata/go-prompt
document.go
FindStartOfPreviousWordWithSpace
func (d *Document) FindStartOfPreviousWordWithSpace() int { x := d.TextBeforeCursor() end := istrings.LastIndexNotByte(x, ' ') if end == -1 { return 0 } start := strings.LastIndexByte(x[:end], ' ') if start == -1 { return 0 } return start + 1 }
go
func (d *Document) FindStartOfPreviousWordWithSpace() int { x := d.TextBeforeCursor() end := istrings.LastIndexNotByte(x, ' ') if end == -1 { return 0 } start := strings.LastIndexByte(x[:end], ' ') if start == -1 { return 0 } return start + 1 }
[ "func", "(", "d", "*", "Document", ")", "FindStartOfPreviousWordWithSpace", "(", ")", "int", "{", "x", ":=", "d", ".", "TextBeforeCursor", "(", ")", "\n", "end", ":=", "istrings", ".", "LastIndexNotByte", "(", "x", ",", "' '", ")", "\n", "if", "end", "...
// FindStartOfPreviousWordWithSpace is almost the same as FindStartOfPreviousWord. // The only difference is to ignore contiguous spaces.
[ "FindStartOfPreviousWordWithSpace", "is", "almost", "the", "same", "as", "FindStartOfPreviousWord", ".", "The", "only", "difference", "is", "to", "ignore", "contiguous", "spaces", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L135-L147
train
c-bata/go-prompt
document.go
FindStartOfPreviousWordUntilSeparator
func (d *Document) FindStartOfPreviousWordUntilSeparator(sep string) int { if sep == "" { return d.FindStartOfPreviousWord() } x := d.TextBeforeCursor() i := strings.LastIndexAny(x, sep) if i != -1 { return i + 1 } return 0 }
go
func (d *Document) FindStartOfPreviousWordUntilSeparator(sep string) int { if sep == "" { return d.FindStartOfPreviousWord() } x := d.TextBeforeCursor() i := strings.LastIndexAny(x, sep) if i != -1 { return i + 1 } return 0 }
[ "func", "(", "d", "*", "Document", ")", "FindStartOfPreviousWordUntilSeparator", "(", "sep", "string", ")", "int", "{", "if", "sep", "==", "\"\"", "{", "return", "d", ".", "FindStartOfPreviousWord", "(", ")", "\n", "}", "\n", "x", ":=", "d", ".", "TextBe...
// FindStartOfPreviousWordUntilSeparator is almost the same as FindStartOfPreviousWord. // But this can specify Separator. Return 0 if nothing was found.
[ "FindStartOfPreviousWordUntilSeparator", "is", "almost", "the", "same", "as", "FindStartOfPreviousWord", ".", "But", "this", "can", "specify", "Separator", ".", "Return", "0", "if", "nothing", "was", "found", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L151-L162
train
c-bata/go-prompt
document.go
FindStartOfPreviousWordUntilSeparatorIgnoreNextToCursor
func (d *Document) FindStartOfPreviousWordUntilSeparatorIgnoreNextToCursor(sep string) int { if sep == "" { return d.FindStartOfPreviousWordWithSpace() } x := d.TextBeforeCursor() end := istrings.LastIndexNotAny(x, sep) if end == -1 { return 0 } start := strings.LastIndexAny(x[:end], sep) if start == -1 { return 0 } return start + 1 }
go
func (d *Document) FindStartOfPreviousWordUntilSeparatorIgnoreNextToCursor(sep string) int { if sep == "" { return d.FindStartOfPreviousWordWithSpace() } x := d.TextBeforeCursor() end := istrings.LastIndexNotAny(x, sep) if end == -1 { return 0 } start := strings.LastIndexAny(x[:end], sep) if start == -1 { return 0 } return start + 1 }
[ "func", "(", "d", "*", "Document", ")", "FindStartOfPreviousWordUntilSeparatorIgnoreNextToCursor", "(", "sep", "string", ")", "int", "{", "if", "sep", "==", "\"\"", "{", "return", "d", ".", "FindStartOfPreviousWordWithSpace", "(", ")", "\n", "}", "\n", "x", ":...
// FindStartOfPreviousWordUntilSeparatorIgnoreNextToCursor is almost the same as FindStartOfPreviousWordWithSpace. // But this can specify Separator. Return 0 if nothing was found.
[ "FindStartOfPreviousWordUntilSeparatorIgnoreNextToCursor", "is", "almost", "the", "same", "as", "FindStartOfPreviousWordWithSpace", ".", "But", "this", "can", "specify", "Separator", ".", "Return", "0", "if", "nothing", "was", "found", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L166-L181
train
c-bata/go-prompt
document.go
FindEndOfCurrentWord
func (d *Document) FindEndOfCurrentWord() int { x := d.TextAfterCursor() i := strings.IndexByte(x, ' ') if i != -1 { return i } return len(x) }
go
func (d *Document) FindEndOfCurrentWord() int { x := d.TextAfterCursor() i := strings.IndexByte(x, ' ') if i != -1 { return i } return len(x) }
[ "func", "(", "d", "*", "Document", ")", "FindEndOfCurrentWord", "(", ")", "int", "{", "x", ":=", "d", ".", "TextAfterCursor", "(", ")", "\n", "i", ":=", "strings", ".", "IndexByte", "(", "x", ",", "' '", ")", "\n", "if", "i", "!=", "-", "1", "{",...
// FindEndOfCurrentWord returns an index relative to the cursor position. // pointing to the end of the current word. Return 0 if nothing was found.
[ "FindEndOfCurrentWord", "returns", "an", "index", "relative", "to", "the", "cursor", "position", ".", "pointing", "to", "the", "end", "of", "the", "current", "word", ".", "Return", "0", "if", "nothing", "was", "found", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L185-L192
train
c-bata/go-prompt
document.go
FindEndOfCurrentWordWithSpace
func (d *Document) FindEndOfCurrentWordWithSpace() int { x := d.TextAfterCursor() start := istrings.IndexNotByte(x, ' ') if start == -1 { return len(x) } end := strings.IndexByte(x[start:], ' ') if end == -1 { return len(x) } return start + end }
go
func (d *Document) FindEndOfCurrentWordWithSpace() int { x := d.TextAfterCursor() start := istrings.IndexNotByte(x, ' ') if start == -1 { return len(x) } end := strings.IndexByte(x[start:], ' ') if end == -1 { return len(x) } return start + end }
[ "func", "(", "d", "*", "Document", ")", "FindEndOfCurrentWordWithSpace", "(", ")", "int", "{", "x", ":=", "d", ".", "TextAfterCursor", "(", ")", "\n", "start", ":=", "istrings", ".", "IndexNotByte", "(", "x", ",", "' '", ")", "\n", "if", "start", "==",...
// FindEndOfCurrentWordWithSpace is almost the same as FindEndOfCurrentWord. // The only difference is to ignore contiguous spaces.
[ "FindEndOfCurrentWordWithSpace", "is", "almost", "the", "same", "as", "FindEndOfCurrentWord", ".", "The", "only", "difference", "is", "to", "ignore", "contiguous", "spaces", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L196-L210
train
c-bata/go-prompt
document.go
FindEndOfCurrentWordUntilSeparator
func (d *Document) FindEndOfCurrentWordUntilSeparator(sep string) int { if sep == "" { return d.FindEndOfCurrentWord() } x := d.TextAfterCursor() i := strings.IndexAny(x, sep) if i != -1 { return i } return len(x) }
go
func (d *Document) FindEndOfCurrentWordUntilSeparator(sep string) int { if sep == "" { return d.FindEndOfCurrentWord() } x := d.TextAfterCursor() i := strings.IndexAny(x, sep) if i != -1 { return i } return len(x) }
[ "func", "(", "d", "*", "Document", ")", "FindEndOfCurrentWordUntilSeparator", "(", "sep", "string", ")", "int", "{", "if", "sep", "==", "\"\"", "{", "return", "d", ".", "FindEndOfCurrentWord", "(", ")", "\n", "}", "\n", "x", ":=", "d", ".", "TextAfterCur...
// FindEndOfCurrentWordUntilSeparator is almost the same as FindEndOfCurrentWord. // But this can specify Separator. Return 0 if nothing was found.
[ "FindEndOfCurrentWordUntilSeparator", "is", "almost", "the", "same", "as", "FindEndOfCurrentWord", ".", "But", "this", "can", "specify", "Separator", ".", "Return", "0", "if", "nothing", "was", "found", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L214-L225
train
c-bata/go-prompt
document.go
FindEndOfCurrentWordUntilSeparatorIgnoreNextToCursor
func (d *Document) FindEndOfCurrentWordUntilSeparatorIgnoreNextToCursor(sep string) int { if sep == "" { return d.FindEndOfCurrentWordWithSpace() } x := d.TextAfterCursor() start := istrings.IndexNotAny(x, sep) if start == -1 { return len(x) } end := strings.IndexAny(x[start:], sep) if end == -1 { return len(x) } return start + end }
go
func (d *Document) FindEndOfCurrentWordUntilSeparatorIgnoreNextToCursor(sep string) int { if sep == "" { return d.FindEndOfCurrentWordWithSpace() } x := d.TextAfterCursor() start := istrings.IndexNotAny(x, sep) if start == -1 { return len(x) } end := strings.IndexAny(x[start:], sep) if end == -1 { return len(x) } return start + end }
[ "func", "(", "d", "*", "Document", ")", "FindEndOfCurrentWordUntilSeparatorIgnoreNextToCursor", "(", "sep", "string", ")", "int", "{", "if", "sep", "==", "\"\"", "{", "return", "d", ".", "FindEndOfCurrentWordWithSpace", "(", ")", "\n", "}", "\n", "x", ":=", ...
// FindEndOfCurrentWordUntilSeparatorIgnoreNextToCursor is almost the same as FindEndOfCurrentWordWithSpace. // But this can specify Separator. Return 0 if nothing was found.
[ "FindEndOfCurrentWordUntilSeparatorIgnoreNextToCursor", "is", "almost", "the", "same", "as", "FindEndOfCurrentWordWithSpace", ".", "But", "this", "can", "specify", "Separator", ".", "Return", "0", "if", "nothing", "was", "found", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L229-L247
train
c-bata/go-prompt
document.go
CurrentLineBeforeCursor
func (d *Document) CurrentLineBeforeCursor() string { s := strings.Split(d.TextBeforeCursor(), "\n") return s[len(s)-1] }
go
func (d *Document) CurrentLineBeforeCursor() string { s := strings.Split(d.TextBeforeCursor(), "\n") return s[len(s)-1] }
[ "func", "(", "d", "*", "Document", ")", "CurrentLineBeforeCursor", "(", ")", "string", "{", "s", ":=", "strings", ".", "Split", "(", "d", ".", "TextBeforeCursor", "(", ")", ",", "\"\\n\"", ")", "\n", "\\n", "\n", "}" ]
// CurrentLineBeforeCursor returns the text from the start of the line until the cursor.
[ "CurrentLineBeforeCursor", "returns", "the", "text", "from", "the", "start", "of", "the", "line", "until", "the", "cursor", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L250-L253
train
c-bata/go-prompt
document.go
lineStartIndexes
func (d *Document) lineStartIndexes() []int { // TODO: Cache, because this is often reused. // (If it is used, it's often used many times. // And this has to be fast for editing big documents!) lc := d.LineCount() lengths := make([]int, lc) for i, l := range d.Lines() { lengths[i] = len(l) } // Calculate cumulative sums. indexes := make([]int, lc+1) indexes[0] = 0 // https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/document.py#L189 pos := 0 for i, l := range lengths { pos += l + 1 indexes[i+1] = pos } if lc > 1 { // Pop the last item. (This is not a new line.) indexes = indexes[:lc] } return indexes }
go
func (d *Document) lineStartIndexes() []int { // TODO: Cache, because this is often reused. // (If it is used, it's often used many times. // And this has to be fast for editing big documents!) lc := d.LineCount() lengths := make([]int, lc) for i, l := range d.Lines() { lengths[i] = len(l) } // Calculate cumulative sums. indexes := make([]int, lc+1) indexes[0] = 0 // https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/document.py#L189 pos := 0 for i, l := range lengths { pos += l + 1 indexes[i+1] = pos } if lc > 1 { // Pop the last item. (This is not a new line.) indexes = indexes[:lc] } return indexes }
[ "func", "(", "d", "*", "Document", ")", "lineStartIndexes", "(", ")", "[", "]", "int", "{", "lc", ":=", "d", ".", "LineCount", "(", ")", "\n", "lengths", ":=", "make", "(", "[", "]", "int", ",", "lc", ")", "\n", "for", "i", ",", "l", ":=", "r...
// Array pointing to the start indexes of all the lines.
[ "Array", "pointing", "to", "the", "start", "indexes", "of", "all", "the", "lines", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L267-L290
train
c-bata/go-prompt
document.go
findLineStartIndex
func (d *Document) findLineStartIndex(index int) (pos int, lineStartIndex int) { indexes := d.lineStartIndexes() pos = bisect.Right(indexes, index) - 1 lineStartIndex = indexes[pos] return }
go
func (d *Document) findLineStartIndex(index int) (pos int, lineStartIndex int) { indexes := d.lineStartIndexes() pos = bisect.Right(indexes, index) - 1 lineStartIndex = indexes[pos] return }
[ "func", "(", "d", "*", "Document", ")", "findLineStartIndex", "(", "index", "int", ")", "(", "pos", "int", ",", "lineStartIndex", "int", ")", "{", "indexes", ":=", "d", ".", "lineStartIndexes", "(", ")", "\n", "pos", "=", "bisect", ".", "Right", "(", ...
// For the index of a character at a certain line, calculate the index of // the first character on that line.
[ "For", "the", "index", "of", "a", "character", "at", "a", "certain", "line", "calculate", "the", "index", "of", "the", "first", "character", "on", "that", "line", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L294-L299
train
c-bata/go-prompt
document.go
GetCursorLeftPosition
func (d *Document) GetCursorLeftPosition(count int) int { if count < 0 { return d.GetCursorRightPosition(-count) } if d.CursorPositionCol() > count { return -count } return -d.CursorPositionCol() }
go
func (d *Document) GetCursorLeftPosition(count int) int { if count < 0 { return d.GetCursorRightPosition(-count) } if d.CursorPositionCol() > count { return -count } return -d.CursorPositionCol() }
[ "func", "(", "d", "*", "Document", ")", "GetCursorLeftPosition", "(", "count", "int", ")", "int", "{", "if", "count", "<", "0", "{", "return", "d", ".", "GetCursorRightPosition", "(", "-", "count", ")", "\n", "}", "\n", "if", "d", ".", "CursorPositionC...
// GetCursorLeftPosition returns the relative position for cursor left.
[ "GetCursorLeftPosition", "returns", "the", "relative", "position", "for", "cursor", "left", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L317-L325
train
c-bata/go-prompt
document.go
GetCursorRightPosition
func (d *Document) GetCursorRightPosition(count int) int { if count < 0 { return d.GetCursorLeftPosition(-count) } if len(d.CurrentLineAfterCursor()) > count { return count } return len(d.CurrentLineAfterCursor()) }
go
func (d *Document) GetCursorRightPosition(count int) int { if count < 0 { return d.GetCursorLeftPosition(-count) } if len(d.CurrentLineAfterCursor()) > count { return count } return len(d.CurrentLineAfterCursor()) }
[ "func", "(", "d", "*", "Document", ")", "GetCursorRightPosition", "(", "count", "int", ")", "int", "{", "if", "count", "<", "0", "{", "return", "d", ".", "GetCursorLeftPosition", "(", "-", "count", ")", "\n", "}", "\n", "if", "len", "(", "d", ".", ...
// GetCursorRightPosition returns relative position for cursor right.
[ "GetCursorRightPosition", "returns", "relative", "position", "for", "cursor", "right", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/document.go#L328-L336
train
c-bata/go-prompt
history.go
Add
func (h *History) Add(input string) { h.histories = append(h.histories, input) h.Clear() }
go
func (h *History) Add(input string) { h.histories = append(h.histories, input) h.Clear() }
[ "func", "(", "h", "*", "History", ")", "Add", "(", "input", "string", ")", "{", "h", ".", "histories", "=", "append", "(", "h", ".", "histories", ",", "input", ")", "\n", "h", ".", "Clear", "(", ")", "\n", "}" ]
// Add to add text in history.
[ "Add", "to", "add", "text", "in", "history", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/history.go#L11-L14
train
c-bata/go-prompt
history.go
Clear
func (h *History) Clear() { h.tmp = make([]string, len(h.histories)) for i := range h.histories { h.tmp[i] = h.histories[i] } h.tmp = append(h.tmp, "") h.selected = len(h.tmp) - 1 }
go
func (h *History) Clear() { h.tmp = make([]string, len(h.histories)) for i := range h.histories { h.tmp[i] = h.histories[i] } h.tmp = append(h.tmp, "") h.selected = len(h.tmp) - 1 }
[ "func", "(", "h", "*", "History", ")", "Clear", "(", ")", "{", "h", ".", "tmp", "=", "make", "(", "[", "]", "string", ",", "len", "(", "h", ".", "histories", ")", ")", "\n", "for", "i", ":=", "range", "h", ".", "histories", "{", "h", ".", "...
// Clear to clear the history.
[ "Clear", "to", "clear", "the", "history", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/history.go#L17-L24
train
c-bata/go-prompt
history.go
Newer
func (h *History) Newer(buf *Buffer) (new *Buffer, changed bool) { if h.selected >= len(h.tmp)-1 { return buf, false } h.tmp[h.selected] = buf.Text() h.selected++ new = NewBuffer() new.InsertText(h.tmp[h.selected], false, true) return new, true }
go
func (h *History) Newer(buf *Buffer) (new *Buffer, changed bool) { if h.selected >= len(h.tmp)-1 { return buf, false } h.tmp[h.selected] = buf.Text() h.selected++ new = NewBuffer() new.InsertText(h.tmp[h.selected], false, true) return new, true }
[ "func", "(", "h", "*", "History", ")", "Newer", "(", "buf", "*", "Buffer", ")", "(", "new", "*", "Buffer", ",", "changed", "bool", ")", "{", "if", "h", ".", "selected", ">=", "len", "(", "h", ".", "tmp", ")", "-", "1", "{", "return", "buf", "...
// Newer saves a buffer of current line and get a buffer of next line by up-arrow. // The changes of line buffers are stored until new history is created.
[ "Newer", "saves", "a", "buffer", "of", "current", "line", "and", "get", "a", "buffer", "of", "next", "line", "by", "up", "-", "arrow", ".", "The", "changes", "of", "line", "buffers", "are", "stored", "until", "new", "history", "is", "created", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/history.go#L42-L52
train
c-bata/go-prompt
shortcut.go
Input
func Input(prefix string, completer Completer, opts ...Option) string { pt := New(dummyExecutor, completer) pt.renderer.prefixTextColor = DefaultColor pt.renderer.prefix = prefix for _, opt := range opts { if err := opt(pt); err != nil { panic(err) } } return pt.Input() }
go
func Input(prefix string, completer Completer, opts ...Option) string { pt := New(dummyExecutor, completer) pt.renderer.prefixTextColor = DefaultColor pt.renderer.prefix = prefix for _, opt := range opts { if err := opt(pt); err != nil { panic(err) } } return pt.Input() }
[ "func", "Input", "(", "prefix", "string", ",", "completer", "Completer", ",", "opts", "...", "Option", ")", "string", "{", "pt", ":=", "New", "(", "dummyExecutor", ",", "completer", ")", "\n", "pt", ".", "renderer", ".", "prefixTextColor", "=", "DefaultCol...
// Input get the input data from the user and return it.
[ "Input", "get", "the", "input", "data", "from", "the", "user", "and", "return", "it", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/shortcut.go#L6-L17
train
c-bata/go-prompt
key_bind_func.go
GoLineEnd
func GoLineEnd(buf *Buffer) { x := []rune(buf.Document().TextAfterCursor()) buf.CursorRight(len(x)) }
go
func GoLineEnd(buf *Buffer) { x := []rune(buf.Document().TextAfterCursor()) buf.CursorRight(len(x)) }
[ "func", "GoLineEnd", "(", "buf", "*", "Buffer", ")", "{", "x", ":=", "[", "]", "rune", "(", "buf", ".", "Document", "(", ")", ".", "TextAfterCursor", "(", ")", ")", "\n", "buf", ".", "CursorRight", "(", "len", "(", "x", ")", ")", "\n", "}" ]
// GoLineEnd Go to the End of the line
[ "GoLineEnd", "Go", "to", "the", "End", "of", "the", "line" ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/key_bind_func.go#L4-L7
train
c-bata/go-prompt
key_bind_func.go
GoLineBeginning
func GoLineBeginning(buf *Buffer) { x := []rune(buf.Document().TextBeforeCursor()) buf.CursorLeft(len(x)) }
go
func GoLineBeginning(buf *Buffer) { x := []rune(buf.Document().TextBeforeCursor()) buf.CursorLeft(len(x)) }
[ "func", "GoLineBeginning", "(", "buf", "*", "Buffer", ")", "{", "x", ":=", "[", "]", "rune", "(", "buf", ".", "Document", "(", ")", ".", "TextBeforeCursor", "(", ")", ")", "\n", "buf", ".", "CursorLeft", "(", "len", "(", "x", ")", ")", "\n", "}" ...
// GoLineBeginning Go to the beginning of the line
[ "GoLineBeginning", "Go", "to", "the", "beginning", "of", "the", "line" ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/key_bind_func.go#L10-L13
train
c-bata/go-prompt
key_bind_func.go
DeleteWord
func DeleteWord(buf *Buffer) { buf.DeleteBeforeCursor(len([]rune(buf.Document().TextBeforeCursor())) - buf.Document().FindStartOfPreviousWordWithSpace()) }
go
func DeleteWord(buf *Buffer) { buf.DeleteBeforeCursor(len([]rune(buf.Document().TextBeforeCursor())) - buf.Document().FindStartOfPreviousWordWithSpace()) }
[ "func", "DeleteWord", "(", "buf", "*", "Buffer", ")", "{", "buf", ".", "DeleteBeforeCursor", "(", "len", "(", "[", "]", "rune", "(", "buf", ".", "Document", "(", ")", ".", "TextBeforeCursor", "(", ")", ")", ")", "-", "buf", ".", "Document", "(", ")...
// DeleteWord Delete word before the cursor
[ "DeleteWord", "Delete", "word", "before", "the", "cursor" ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/key_bind_func.go#L21-L23
train
c-bata/go-prompt
key_bind_func.go
GoLeftWord
func GoLeftWord(buf *Buffer) { buf.CursorLeft(len([]rune(buf.Document().TextBeforeCursor())) - buf.Document().FindStartOfPreviousWordWithSpace()) }
go
func GoLeftWord(buf *Buffer) { buf.CursorLeft(len([]rune(buf.Document().TextBeforeCursor())) - buf.Document().FindStartOfPreviousWordWithSpace()) }
[ "func", "GoLeftWord", "(", "buf", "*", "Buffer", ")", "{", "buf", ".", "CursorLeft", "(", "len", "(", "[", "]", "rune", "(", "buf", ".", "Document", "(", ")", ".", "TextBeforeCursor", "(", ")", ")", ")", "-", "buf", ".", "Document", "(", ")", "."...
// GoLeftWord Backward one word
[ "GoLeftWord", "Backward", "one", "word" ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/key_bind_func.go#L46-L48
train
c-bata/go-prompt
completion.go
GetSelectedSuggestion
func (c *CompletionManager) GetSelectedSuggestion() (s Suggest, ok bool) { if c.selected == -1 { return Suggest{}, false } else if c.selected < -1 { debug.Assert(false, "must not reach here") c.selected = -1 return Suggest{}, false } return c.tmp[c.selected], true }
go
func (c *CompletionManager) GetSelectedSuggestion() (s Suggest, ok bool) { if c.selected == -1 { return Suggest{}, false } else if c.selected < -1 { debug.Assert(false, "must not reach here") c.selected = -1 return Suggest{}, false } return c.tmp[c.selected], true }
[ "func", "(", "c", "*", "CompletionManager", ")", "GetSelectedSuggestion", "(", ")", "(", "s", "Suggest", ",", "ok", "bool", ")", "{", "if", "c", ".", "selected", "==", "-", "1", "{", "return", "Suggest", "{", "}", ",", "false", "\n", "}", "else", "...
// GetSelectedSuggestion returns the selected item.
[ "GetSelectedSuggestion", "returns", "the", "selected", "item", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/completion.go#L43-L52
train
c-bata/go-prompt
completion.go
Reset
func (c *CompletionManager) Reset() { c.selected = -1 c.verticalScroll = 0 c.Update(*NewDocument()) return }
go
func (c *CompletionManager) Reset() { c.selected = -1 c.verticalScroll = 0 c.Update(*NewDocument()) return }
[ "func", "(", "c", "*", "CompletionManager", ")", "Reset", "(", ")", "{", "c", ".", "selected", "=", "-", "1", "\n", "c", ".", "verticalScroll", "=", "0", "\n", "c", ".", "Update", "(", "*", "NewDocument", "(", ")", ")", "\n", "return", "\n", "}" ...
// Reset to select nothing.
[ "Reset", "to", "select", "nothing", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/completion.go#L60-L65
train
c-bata/go-prompt
completion.go
Update
func (c *CompletionManager) Update(in Document) { c.tmp = c.completer(in) return }
go
func (c *CompletionManager) Update(in Document) { c.tmp = c.completer(in) return }
[ "func", "(", "c", "*", "CompletionManager", ")", "Update", "(", "in", "Document", ")", "{", "c", ".", "tmp", "=", "c", ".", "completer", "(", "in", ")", "\n", "return", "\n", "}" ]
// Update to update the suggestions.
[ "Update", "to", "update", "the", "suggestions", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/completion.go#L68-L71
train
c-bata/go-prompt
completion.go
Previous
func (c *CompletionManager) Previous() { if c.verticalScroll == c.selected && c.selected > 0 { c.verticalScroll-- } c.selected-- c.update() return }
go
func (c *CompletionManager) Previous() { if c.verticalScroll == c.selected && c.selected > 0 { c.verticalScroll-- } c.selected-- c.update() return }
[ "func", "(", "c", "*", "CompletionManager", ")", "Previous", "(", ")", "{", "if", "c", ".", "verticalScroll", "==", "c", ".", "selected", "&&", "c", ".", "selected", ">", "0", "{", "c", ".", "verticalScroll", "--", "\n", "}", "\n", "c", ".", "selec...
// Previous to select the previous suggestion item.
[ "Previous", "to", "select", "the", "previous", "suggestion", "item", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/completion.go#L74-L81
train
c-bata/go-prompt
completion.go
Next
func (c *CompletionManager) Next() { if c.verticalScroll+int(c.max)-1 == c.selected { c.verticalScroll++ } c.selected++ c.update() return }
go
func (c *CompletionManager) Next() { if c.verticalScroll+int(c.max)-1 == c.selected { c.verticalScroll++ } c.selected++ c.update() return }
[ "func", "(", "c", "*", "CompletionManager", ")", "Next", "(", ")", "{", "if", "c", ".", "verticalScroll", "+", "int", "(", "c", ".", "max", ")", "-", "1", "==", "c", ".", "selected", "{", "c", ".", "verticalScroll", "++", "\n", "}", "\n", "c", ...
// Next to select the next suggestion item.
[ "Next", "to", "select", "the", "next", "suggestion", "item", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/completion.go#L84-L91
train
c-bata/go-prompt
completion.go
NewCompletionManager
func NewCompletionManager(completer Completer, max uint16) *CompletionManager { return &CompletionManager{ selected: -1, max: max, completer: completer, verticalScroll: 0, } }
go
func NewCompletionManager(completer Completer, max uint16) *CompletionManager { return &CompletionManager{ selected: -1, max: max, completer: completer, verticalScroll: 0, } }
[ "func", "NewCompletionManager", "(", "completer", "Completer", ",", "max", "uint16", ")", "*", "CompletionManager", "{", "return", "&", "CompletionManager", "{", "selected", ":", "-", "1", ",", "max", ":", "max", ",", "completer", ":", "completer", ",", "ver...
// NewCompletionManager returns initialized CompletionManager object.
[ "NewCompletionManager", "returns", "initialized", "CompletionManager", "object", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/completion.go#L186-L194
train
c-bata/go-prompt
input.go
GetKey
func GetKey(b []byte) Key { for _, k := range ASCIISequences { if bytes.Equal(k.ASCIICode, b) { return k.Key } } return NotDefined }
go
func GetKey(b []byte) Key { for _, k := range ASCIISequences { if bytes.Equal(k.ASCIICode, b) { return k.Key } } return NotDefined }
[ "func", "GetKey", "(", "b", "[", "]", "byte", ")", "Key", "{", "for", "_", ",", "k", ":=", "range", "ASCIISequences", "{", "if", "bytes", ".", "Equal", "(", "k", ".", "ASCIICode", ",", "b", ")", "{", "return", "k", ".", "Key", "\n", "}", "\n", ...
// GetKey returns Key correspond to input byte codes.
[ "GetKey", "returns", "Key", "correspond", "to", "input", "byte", "codes", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/input.go#L24-L31
train
c-bata/go-prompt
internal/debug/assert.go
Assert
func Assert(cond bool, msg interface{}) { if cond { return } if enableAssert { panic(msg) } writeWithSync(2, "[ASSERT] "+toString(msg)) }
go
func Assert(cond bool, msg interface{}) { if cond { return } if enableAssert { panic(msg) } writeWithSync(2, "[ASSERT] "+toString(msg)) }
[ "func", "Assert", "(", "cond", "bool", ",", "msg", "interface", "{", "}", ")", "{", "if", "cond", "{", "return", "\n", "}", "\n", "if", "enableAssert", "{", "panic", "(", "msg", ")", "\n", "}", "\n", "writeWithSync", "(", "2", ",", "\"[ASSERT] \"", ...
// Assert ensures expected condition.
[ "Assert", "ensures", "expected", "condition", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/internal/debug/assert.go#L23-L31
train
c-bata/go-prompt
internal/debug/assert.go
AssertNoError
func AssertNoError(err error) { if err == nil { return } if enableAssert { panic(err) } writeWithSync(2, "[ASSERT] "+err.Error()) }
go
func AssertNoError(err error) { if err == nil { return } if enableAssert { panic(err) } writeWithSync(2, "[ASSERT] "+err.Error()) }
[ "func", "AssertNoError", "(", "err", "error", ")", "{", "if", "err", "==", "nil", "{", "return", "\n", "}", "\n", "if", "enableAssert", "{", "panic", "(", "err", ")", "\n", "}", "\n", "writeWithSync", "(", "2", ",", "\"[ASSERT] \"", "+", "err", ".", ...
// AssertNoError ensures err is nil.
[ "AssertNoError", "ensures", "err", "is", "nil", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/internal/debug/assert.go#L47-L55
train
c-bata/go-prompt
prompt.go
Run
func (p *Prompt) Run() { defer debug.Teardown() debug.Log("start prompt") p.setUp() defer p.tearDown() if p.completion.showAtStart { p.completion.Update(*p.buf.Document()) } p.renderer.Render(p.buf, p.completion) bufCh := make(chan []byte, 128) stopReadBufCh := make(chan struct{}) go p.readBuffer(bufCh, stopReadBufCh) exitCh := make(chan int) winSizeCh := make(chan *WinSize) stopHandleSignalCh := make(chan struct{}) go p.handleSignals(exitCh, winSizeCh, stopHandleSignalCh) for { select { case b := <-bufCh: if shouldExit, e := p.feed(b); shouldExit { p.renderer.BreakLine(p.buf) stopReadBufCh <- struct{}{} stopHandleSignalCh <- struct{}{} return } else if e != nil { // Stop goroutine to run readBuffer function stopReadBufCh <- struct{}{} stopHandleSignalCh <- struct{}{} // Unset raw mode // Reset to Blocking mode because returned EAGAIN when still set non-blocking mode. debug.AssertNoError(p.in.TearDown()) p.executor(e.input) p.completion.Update(*p.buf.Document()) p.renderer.Render(p.buf, p.completion) // Set raw mode debug.AssertNoError(p.in.Setup()) go p.readBuffer(bufCh, stopReadBufCh) go p.handleSignals(exitCh, winSizeCh, stopHandleSignalCh) } else { p.completion.Update(*p.buf.Document()) p.renderer.Render(p.buf, p.completion) } case w := <-winSizeCh: p.renderer.UpdateWinSize(w) p.renderer.Render(p.buf, p.completion) case code := <-exitCh: p.renderer.BreakLine(p.buf) p.tearDown() os.Exit(code) default: time.Sleep(10 * time.Millisecond) } } }
go
func (p *Prompt) Run() { defer debug.Teardown() debug.Log("start prompt") p.setUp() defer p.tearDown() if p.completion.showAtStart { p.completion.Update(*p.buf.Document()) } p.renderer.Render(p.buf, p.completion) bufCh := make(chan []byte, 128) stopReadBufCh := make(chan struct{}) go p.readBuffer(bufCh, stopReadBufCh) exitCh := make(chan int) winSizeCh := make(chan *WinSize) stopHandleSignalCh := make(chan struct{}) go p.handleSignals(exitCh, winSizeCh, stopHandleSignalCh) for { select { case b := <-bufCh: if shouldExit, e := p.feed(b); shouldExit { p.renderer.BreakLine(p.buf) stopReadBufCh <- struct{}{} stopHandleSignalCh <- struct{}{} return } else if e != nil { // Stop goroutine to run readBuffer function stopReadBufCh <- struct{}{} stopHandleSignalCh <- struct{}{} // Unset raw mode // Reset to Blocking mode because returned EAGAIN when still set non-blocking mode. debug.AssertNoError(p.in.TearDown()) p.executor(e.input) p.completion.Update(*p.buf.Document()) p.renderer.Render(p.buf, p.completion) // Set raw mode debug.AssertNoError(p.in.Setup()) go p.readBuffer(bufCh, stopReadBufCh) go p.handleSignals(exitCh, winSizeCh, stopHandleSignalCh) } else { p.completion.Update(*p.buf.Document()) p.renderer.Render(p.buf, p.completion) } case w := <-winSizeCh: p.renderer.UpdateWinSize(w) p.renderer.Render(p.buf, p.completion) case code := <-exitCh: p.renderer.BreakLine(p.buf) p.tearDown() os.Exit(code) default: time.Sleep(10 * time.Millisecond) } } }
[ "func", "(", "p", "*", "Prompt", ")", "Run", "(", ")", "{", "defer", "debug", ".", "Teardown", "(", ")", "\n", "debug", ".", "Log", "(", "\"start prompt\"", ")", "\n", "p", ".", "setUp", "(", ")", "\n", "defer", "p", ".", "tearDown", "(", ")", ...
// Run starts prompt.
[ "Run", "starts", "prompt", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/prompt.go#L36-L97
train
c-bata/go-prompt
prompt.go
Input
func (p *Prompt) Input() string { defer debug.Teardown() debug.Log("start prompt") p.setUp() defer p.tearDown() if p.completion.showAtStart { p.completion.Update(*p.buf.Document()) } p.renderer.Render(p.buf, p.completion) bufCh := make(chan []byte, 128) stopReadBufCh := make(chan struct{}) go p.readBuffer(bufCh, stopReadBufCh) for { select { case b := <-bufCh: if shouldExit, e := p.feed(b); shouldExit { p.renderer.BreakLine(p.buf) stopReadBufCh <- struct{}{} return "" } else if e != nil { // Stop goroutine to run readBuffer function stopReadBufCh <- struct{}{} return e.input } else { p.completion.Update(*p.buf.Document()) p.renderer.Render(p.buf, p.completion) } default: time.Sleep(10 * time.Millisecond) } } }
go
func (p *Prompt) Input() string { defer debug.Teardown() debug.Log("start prompt") p.setUp() defer p.tearDown() if p.completion.showAtStart { p.completion.Update(*p.buf.Document()) } p.renderer.Render(p.buf, p.completion) bufCh := make(chan []byte, 128) stopReadBufCh := make(chan struct{}) go p.readBuffer(bufCh, stopReadBufCh) for { select { case b := <-bufCh: if shouldExit, e := p.feed(b); shouldExit { p.renderer.BreakLine(p.buf) stopReadBufCh <- struct{}{} return "" } else if e != nil { // Stop goroutine to run readBuffer function stopReadBufCh <- struct{}{} return e.input } else { p.completion.Update(*p.buf.Document()) p.renderer.Render(p.buf, p.completion) } default: time.Sleep(10 * time.Millisecond) } } }
[ "func", "(", "p", "*", "Prompt", ")", "Input", "(", ")", "string", "{", "defer", "debug", ".", "Teardown", "(", ")", "\n", "debug", ".", "Log", "(", "\"start prompt\"", ")", "\n", "p", ".", "setUp", "(", ")", "\n", "defer", "p", ".", "tearDown", ...
// Input just returns user input text.
[ "Input", "just", "returns", "user", "input", "text", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/prompt.go#L212-L246
train
c-bata/go-prompt
render.go
Setup
func (r *Render) Setup() { if r.title != "" { r.out.SetTitle(r.title) debug.AssertNoError(r.out.Flush()) } }
go
func (r *Render) Setup() { if r.title != "" { r.out.SetTitle(r.title) debug.AssertNoError(r.out.Flush()) } }
[ "func", "(", "r", "*", "Render", ")", "Setup", "(", ")", "{", "if", "r", ".", "title", "!=", "\"\"", "{", "r", ".", "out", ".", "SetTitle", "(", "r", ".", "title", ")", "\n", "debug", ".", "AssertNoError", "(", "r", ".", "out", ".", "Flush", ...
// Setup to initialize console output.
[ "Setup", "to", "initialize", "console", "output", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/render.go#L41-L46
train
c-bata/go-prompt
render.go
getCurrentPrefix
func (r *Render) getCurrentPrefix() string { if prefix, ok := r.livePrefixCallback(); ok { return prefix } return r.prefix }
go
func (r *Render) getCurrentPrefix() string { if prefix, ok := r.livePrefixCallback(); ok { return prefix } return r.prefix }
[ "func", "(", "r", "*", "Render", ")", "getCurrentPrefix", "(", ")", "string", "{", "if", "prefix", ",", "ok", ":=", "r", ".", "livePrefixCallback", "(", ")", ";", "ok", "{", "return", "prefix", "\n", "}", "\n", "return", "r", ".", "prefix", "\n", "...
// getCurrentPrefix to get current prefix. // If live-prefix is enabled, return live-prefix.
[ "getCurrentPrefix", "to", "get", "current", "prefix", ".", "If", "live", "-", "prefix", "is", "enabled", "return", "live", "-", "prefix", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/render.go#L50-L55
train
c-bata/go-prompt
render.go
TearDown
func (r *Render) TearDown() { r.out.ClearTitle() r.out.EraseDown() debug.AssertNoError(r.out.Flush()) }
go
func (r *Render) TearDown() { r.out.ClearTitle() r.out.EraseDown() debug.AssertNoError(r.out.Flush()) }
[ "func", "(", "r", "*", "Render", ")", "TearDown", "(", ")", "{", "r", ".", "out", ".", "ClearTitle", "(", ")", "\n", "r", ".", "out", ".", "EraseDown", "(", ")", "\n", "debug", ".", "AssertNoError", "(", "r", ".", "out", ".", "Flush", "(", ")",...
// TearDown to clear title and erasing.
[ "TearDown", "to", "clear", "title", "and", "erasing", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/render.go#L64-L68
train
c-bata/go-prompt
render.go
UpdateWinSize
func (r *Render) UpdateWinSize(ws *WinSize) { r.row = ws.Row r.col = ws.Col return }
go
func (r *Render) UpdateWinSize(ws *WinSize) { r.row = ws.Row r.col = ws.Col return }
[ "func", "(", "r", "*", "Render", ")", "UpdateWinSize", "(", "ws", "*", "WinSize", ")", "{", "r", ".", "row", "=", "ws", ".", "Row", "\n", "r", ".", "col", "=", "ws", ".", "Col", "\n", "return", "\n", "}" ]
// UpdateWinSize called when window size is changed.
[ "UpdateWinSize", "called", "when", "window", "size", "is", "changed", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/render.go#L81-L85
train
c-bata/go-prompt
render.go
Render
func (r *Render) Render(buffer *Buffer, completion *CompletionManager) { // In situations where a pseudo tty is allocated (e.g. within a docker container), // window size via TIOCGWINSZ is not immediately available and will result in 0,0 dimensions. if r.col == 0 { return } defer func() { debug.AssertNoError(r.out.Flush()) }() r.move(r.previousCursor, 0) line := buffer.Text() prefix := r.getCurrentPrefix() cursor := runewidth.StringWidth(prefix) + runewidth.StringWidth(line) // prepare area _, y := r.toPos(cursor) h := y + 1 + int(completion.max) if h > int(r.row) || completionMargin > int(r.col) { r.renderWindowTooSmall() return } // Rendering r.out.HideCursor() defer r.out.ShowCursor() r.renderPrefix() r.out.SetColor(r.inputTextColor, r.inputBGColor, false) r.out.WriteStr(line) r.out.SetColor(DefaultColor, DefaultColor, false) r.lineWrap(cursor) r.out.EraseDown() cursor = r.backward(cursor, runewidth.StringWidth(line)-buffer.DisplayCursorPosition()) r.renderCompletion(buffer, completion) if suggest, ok := completion.GetSelectedSuggestion(); ok { cursor = r.backward(cursor, runewidth.StringWidth(buffer.Document().GetWordBeforeCursorUntilSeparator(completion.wordSeparator))) r.out.SetColor(r.previewSuggestionTextColor, r.previewSuggestionBGColor, false) r.out.WriteStr(suggest.Text) r.out.SetColor(DefaultColor, DefaultColor, false) cursor += runewidth.StringWidth(suggest.Text) rest := buffer.Document().TextAfterCursor() r.out.WriteStr(rest) cursor += runewidth.StringWidth(rest) r.lineWrap(cursor) cursor = r.backward(cursor, runewidth.StringWidth(rest)) } r.previousCursor = cursor }
go
func (r *Render) Render(buffer *Buffer, completion *CompletionManager) { // In situations where a pseudo tty is allocated (e.g. within a docker container), // window size via TIOCGWINSZ is not immediately available and will result in 0,0 dimensions. if r.col == 0 { return } defer func() { debug.AssertNoError(r.out.Flush()) }() r.move(r.previousCursor, 0) line := buffer.Text() prefix := r.getCurrentPrefix() cursor := runewidth.StringWidth(prefix) + runewidth.StringWidth(line) // prepare area _, y := r.toPos(cursor) h := y + 1 + int(completion.max) if h > int(r.row) || completionMargin > int(r.col) { r.renderWindowTooSmall() return } // Rendering r.out.HideCursor() defer r.out.ShowCursor() r.renderPrefix() r.out.SetColor(r.inputTextColor, r.inputBGColor, false) r.out.WriteStr(line) r.out.SetColor(DefaultColor, DefaultColor, false) r.lineWrap(cursor) r.out.EraseDown() cursor = r.backward(cursor, runewidth.StringWidth(line)-buffer.DisplayCursorPosition()) r.renderCompletion(buffer, completion) if suggest, ok := completion.GetSelectedSuggestion(); ok { cursor = r.backward(cursor, runewidth.StringWidth(buffer.Document().GetWordBeforeCursorUntilSeparator(completion.wordSeparator))) r.out.SetColor(r.previewSuggestionTextColor, r.previewSuggestionBGColor, false) r.out.WriteStr(suggest.Text) r.out.SetColor(DefaultColor, DefaultColor, false) cursor += runewidth.StringWidth(suggest.Text) rest := buffer.Document().TextAfterCursor() r.out.WriteStr(rest) cursor += runewidth.StringWidth(rest) r.lineWrap(cursor) cursor = r.backward(cursor, runewidth.StringWidth(rest)) } r.previousCursor = cursor }
[ "func", "(", "r", "*", "Render", ")", "Render", "(", "buffer", "*", "Buffer", ",", "completion", "*", "CompletionManager", ")", "{", "if", "r", ".", "col", "==", "0", "{", "return", "\n", "}", "\n", "defer", "func", "(", ")", "{", "debug", ".", "...
// Render renders to the console.
[ "Render", "renders", "to", "the", "console", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/render.go#L173-L226
train
c-bata/go-prompt
render.go
BreakLine
func (r *Render) BreakLine(buffer *Buffer) { // Erasing and Render cursor := runewidth.StringWidth(buffer.Document().TextBeforeCursor()) + runewidth.StringWidth(r.getCurrentPrefix()) r.clear(cursor) r.renderPrefix() r.out.SetColor(r.inputTextColor, r.inputBGColor, false) r.out.WriteStr(buffer.Document().Text + "\n") r.out.SetColor(DefaultColor, DefaultColor, false) debug.AssertNoError(r.out.Flush()) r.previousCursor = 0 }
go
func (r *Render) BreakLine(buffer *Buffer) { // Erasing and Render cursor := runewidth.StringWidth(buffer.Document().TextBeforeCursor()) + runewidth.StringWidth(r.getCurrentPrefix()) r.clear(cursor) r.renderPrefix() r.out.SetColor(r.inputTextColor, r.inputBGColor, false) r.out.WriteStr(buffer.Document().Text + "\n") r.out.SetColor(DefaultColor, DefaultColor, false) debug.AssertNoError(r.out.Flush()) r.previousCursor = 0 }
[ "func", "(", "r", "*", "Render", ")", "BreakLine", "(", "buffer", "*", "Buffer", ")", "{", "cursor", ":=", "runewidth", ".", "StringWidth", "(", "buffer", ".", "Document", "(", ")", ".", "TextBeforeCursor", "(", ")", ")", "+", "runewidth", ".", "String...
// BreakLine to break line.
[ "BreakLine", "to", "break", "line", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/render.go#L229-L240
train
c-bata/go-prompt
render.go
clear
func (r *Render) clear(cursor int) { r.move(cursor, 0) r.out.EraseDown() }
go
func (r *Render) clear(cursor int) { r.move(cursor, 0) r.out.EraseDown() }
[ "func", "(", "r", "*", "Render", ")", "clear", "(", "cursor", "int", ")", "{", "r", ".", "move", "(", "cursor", ",", "0", ")", "\n", "r", ".", "out", ".", "EraseDown", "(", ")", "\n", "}" ]
// clear erases the screen from a beginning of input // even if there is line break which means input length exceeds a window's width.
[ "clear", "erases", "the", "screen", "from", "a", "beginning", "of", "input", "even", "if", "there", "is", "line", "break", "which", "means", "input", "length", "exceeds", "a", "window", "s", "width", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/render.go#L244-L247
train
c-bata/go-prompt
render.go
backward
func (r *Render) backward(from, n int) int { return r.move(from, from-n) }
go
func (r *Render) backward(from, n int) int { return r.move(from, from-n) }
[ "func", "(", "r", "*", "Render", ")", "backward", "(", "from", ",", "n", "int", ")", "int", "{", "return", "r", ".", "move", "(", "from", ",", "from", "-", "n", ")", "\n", "}" ]
// backward moves cursor to backward from a current cursor position // regardless there is a line break.
[ "backward", "moves", "cursor", "to", "backward", "from", "a", "current", "cursor", "position", "regardless", "there", "is", "a", "line", "break", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/render.go#L251-L253
train
c-bata/go-prompt
render.go
move
func (r *Render) move(from, to int) int { fromX, fromY := r.toPos(from) toX, toY := r.toPos(to) r.out.CursorUp(fromY - toY) r.out.CursorBackward(fromX - toX) return to }
go
func (r *Render) move(from, to int) int { fromX, fromY := r.toPos(from) toX, toY := r.toPos(to) r.out.CursorUp(fromY - toY) r.out.CursorBackward(fromX - toX) return to }
[ "func", "(", "r", "*", "Render", ")", "move", "(", "from", ",", "to", "int", ")", "int", "{", "fromX", ",", "fromY", ":=", "r", ".", "toPos", "(", "from", ")", "\n", "toX", ",", "toY", ":=", "r", ".", "toPos", "(", "to", ")", "\n", "r", "."...
// move moves cursor to specified position from the beginning of input // even if there is a line break.
[ "move", "moves", "cursor", "to", "specified", "position", "from", "the", "beginning", "of", "input", "even", "if", "there", "is", "a", "line", "break", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/render.go#L257-L264
train
c-bata/go-prompt
render.go
toPos
func (r *Render) toPos(cursor int) (x, y int) { col := int(r.col) return cursor % col, cursor / col }
go
func (r *Render) toPos(cursor int) (x, y int) { col := int(r.col) return cursor % col, cursor / col }
[ "func", "(", "r", "*", "Render", ")", "toPos", "(", "cursor", "int", ")", "(", "x", ",", "y", "int", ")", "{", "col", ":=", "int", "(", "r", ".", "col", ")", "\n", "return", "cursor", "%", "col", ",", "cursor", "/", "col", "\n", "}" ]
// toPos returns the relative position from the beginning of the string.
[ "toPos", "returns", "the", "relative", "position", "from", "the", "beginning", "of", "the", "string", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/render.go#L267-L270
train
c-bata/go-prompt
filter.go
FilterHasPrefix
func FilterHasPrefix(completions []Suggest, sub string, ignoreCase bool) []Suggest { return filterSuggestions(completions, sub, ignoreCase, strings.HasPrefix) }
go
func FilterHasPrefix(completions []Suggest, sub string, ignoreCase bool) []Suggest { return filterSuggestions(completions, sub, ignoreCase, strings.HasPrefix) }
[ "func", "FilterHasPrefix", "(", "completions", "[", "]", "Suggest", ",", "sub", "string", ",", "ignoreCase", "bool", ")", "[", "]", "Suggest", "{", "return", "filterSuggestions", "(", "completions", ",", "sub", ",", "ignoreCase", ",", "strings", ".", "HasPre...
// FilterHasPrefix checks whether the string completions.Text begins with sub.
[ "FilterHasPrefix", "checks", "whether", "the", "string", "completions", ".", "Text", "begins", "with", "sub", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/filter.go#L9-L11
train
c-bata/go-prompt
filter.go
FilterHasSuffix
func FilterHasSuffix(completions []Suggest, sub string, ignoreCase bool) []Suggest { return filterSuggestions(completions, sub, ignoreCase, strings.HasSuffix) }
go
func FilterHasSuffix(completions []Suggest, sub string, ignoreCase bool) []Suggest { return filterSuggestions(completions, sub, ignoreCase, strings.HasSuffix) }
[ "func", "FilterHasSuffix", "(", "completions", "[", "]", "Suggest", ",", "sub", "string", ",", "ignoreCase", "bool", ")", "[", "]", "Suggest", "{", "return", "filterSuggestions", "(", "completions", ",", "sub", ",", "ignoreCase", ",", "strings", ".", "HasSuf...
// FilterHasSuffix checks whether the completion.Text ends with sub.
[ "FilterHasSuffix", "checks", "whether", "the", "completion", ".", "Text", "ends", "with", "sub", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/filter.go#L14-L16
train
c-bata/go-prompt
filter.go
FilterContains
func FilterContains(completions []Suggest, sub string, ignoreCase bool) []Suggest { return filterSuggestions(completions, sub, ignoreCase, strings.Contains) }
go
func FilterContains(completions []Suggest, sub string, ignoreCase bool) []Suggest { return filterSuggestions(completions, sub, ignoreCase, strings.Contains) }
[ "func", "FilterContains", "(", "completions", "[", "]", "Suggest", ",", "sub", "string", ",", "ignoreCase", "bool", ")", "[", "]", "Suggest", "{", "return", "filterSuggestions", "(", "completions", ",", "sub", ",", "ignoreCase", ",", "strings", ".", "Contain...
// FilterContains checks whether the completion.Text contains sub.
[ "FilterContains", "checks", "whether", "the", "completion", ".", "Text", "contains", "sub", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/filter.go#L19-L21
train
c-bata/go-prompt
internal/term/raw.go
SetRaw
func SetRaw(fd int) error { n, err := getOriginalTermios(fd) if err != nil { return err } n.Iflag &^= syscall.IGNBRK | syscall.BRKINT | syscall.PARMRK | syscall.ISTRIP | syscall.INLCR | syscall.IGNCR | syscall.ICRNL | syscall.IXON n.Lflag &^= syscall.ECHO | syscall.ICANON | syscall.IEXTEN | syscall.ISIG | syscall.ECHONL n.Cflag &^= syscall.CSIZE | syscall.PARENB n.Cc[syscall.VMIN] = 1 n.Cc[syscall.VTIME] = 0 return termios.Tcsetattr(uintptr(fd), termios.TCSANOW, (*syscall.Termios)(&n)) }
go
func SetRaw(fd int) error { n, err := getOriginalTermios(fd) if err != nil { return err } n.Iflag &^= syscall.IGNBRK | syscall.BRKINT | syscall.PARMRK | syscall.ISTRIP | syscall.INLCR | syscall.IGNCR | syscall.ICRNL | syscall.IXON n.Lflag &^= syscall.ECHO | syscall.ICANON | syscall.IEXTEN | syscall.ISIG | syscall.ECHONL n.Cflag &^= syscall.CSIZE | syscall.PARENB n.Cc[syscall.VMIN] = 1 n.Cc[syscall.VTIME] = 0 return termios.Tcsetattr(uintptr(fd), termios.TCSANOW, (*syscall.Termios)(&n)) }
[ "func", "SetRaw", "(", "fd", "int", ")", "error", "{", "n", ",", "err", ":=", "getOriginalTermios", "(", "fd", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "n", ".", "Iflag", "&^=", "syscall", ".", "IGNBRK", "|", "s...
// SetRaw put terminal into a raw mode
[ "SetRaw", "put", "terminal", "into", "a", "raw", "mode" ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/internal/term/raw.go#L12-L26
train
c-bata/go-prompt
buffer.go
Document
func (b *Buffer) Document() (d *Document) { if b.cacheDocument == nil || b.cacheDocument.Text != b.Text() || b.cacheDocument.cursorPosition != b.cursorPosition { b.cacheDocument = &Document{ Text: b.Text(), cursorPosition: b.cursorPosition, } } return b.cacheDocument }
go
func (b *Buffer) Document() (d *Document) { if b.cacheDocument == nil || b.cacheDocument.Text != b.Text() || b.cacheDocument.cursorPosition != b.cursorPosition { b.cacheDocument = &Document{ Text: b.Text(), cursorPosition: b.cursorPosition, } } return b.cacheDocument }
[ "func", "(", "b", "*", "Buffer", ")", "Document", "(", ")", "(", "d", "*", "Document", ")", "{", "if", "b", ".", "cacheDocument", "==", "nil", "||", "b", ".", "cacheDocument", ".", "Text", "!=", "b", ".", "Text", "(", ")", "||", "b", ".", "cach...
// Document method to return document instance from the current text and cursor position.
[ "Document", "method", "to", "return", "document", "instance", "from", "the", "current", "text", "and", "cursor", "position", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/buffer.go#L24-L34
train
c-bata/go-prompt
buffer.go
InsertText
func (b *Buffer) InsertText(v string, overwrite bool, moveCursor bool) { or := []rune(b.Text()) oc := b.cursorPosition if overwrite { overwritten := string(or[oc : oc+len(v)]) if strings.Contains(overwritten, "\n") { i := strings.IndexAny(overwritten, "\n") overwritten = overwritten[:i] } b.setText(string(or[:oc]) + v + string(or[oc+len(overwritten):])) } else { b.setText(string(or[:oc]) + v + string(or[oc:])) } if moveCursor { b.cursorPosition += len([]rune(v)) } }
go
func (b *Buffer) InsertText(v string, overwrite bool, moveCursor bool) { or := []rune(b.Text()) oc := b.cursorPosition if overwrite { overwritten := string(or[oc : oc+len(v)]) if strings.Contains(overwritten, "\n") { i := strings.IndexAny(overwritten, "\n") overwritten = overwritten[:i] } b.setText(string(or[:oc]) + v + string(or[oc+len(overwritten):])) } else { b.setText(string(or[:oc]) + v + string(or[oc:])) } if moveCursor { b.cursorPosition += len([]rune(v)) } }
[ "func", "(", "b", "*", "Buffer", ")", "InsertText", "(", "v", "string", ",", "overwrite", "bool", ",", "moveCursor", "bool", ")", "{", "or", ":=", "[", "]", "rune", "(", "b", ".", "Text", "(", ")", ")", "\n", "oc", ":=", "b", ".", "cursorPosition...
// InsertText insert string from current line.
[ "InsertText", "insert", "string", "from", "current", "line", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/buffer.go#L43-L61
train
c-bata/go-prompt
buffer.go
setCursorPosition
func (b *Buffer) setCursorPosition(p int) { o := b.cursorPosition if p > 0 { b.cursorPosition = p } else { b.cursorPosition = 0 } if p != o { // Cursor position is changed. // TODO: Call a onCursorPositionChanged function. } }
go
func (b *Buffer) setCursorPosition(p int) { o := b.cursorPosition if p > 0 { b.cursorPosition = p } else { b.cursorPosition = 0 } if p != o { // Cursor position is changed. // TODO: Call a onCursorPositionChanged function. } }
[ "func", "(", "b", "*", "Buffer", ")", "setCursorPosition", "(", "p", "int", ")", "{", "o", ":=", "b", ".", "cursorPosition", "\n", "if", "p", ">", "0", "{", "b", ".", "cursorPosition", "=", "p", "\n", "}", "else", "{", "b", ".", "cursorPosition", ...
// Set cursor position. Return whether it changed.
[ "Set", "cursor", "position", ".", "Return", "whether", "it", "changed", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/buffer.go#L79-L90
train
c-bata/go-prompt
buffer.go
CursorLeft
func (b *Buffer) CursorLeft(count int) { l := b.Document().GetCursorLeftPosition(count) b.cursorPosition += l return }
go
func (b *Buffer) CursorLeft(count int) { l := b.Document().GetCursorLeftPosition(count) b.cursorPosition += l return }
[ "func", "(", "b", "*", "Buffer", ")", "CursorLeft", "(", "count", "int", ")", "{", "l", ":=", "b", ".", "Document", "(", ")", ".", "GetCursorLeftPosition", "(", "count", ")", "\n", "b", ".", "cursorPosition", "+=", "l", "\n", "return", "\n", "}" ]
// CursorLeft move to left on the current line.
[ "CursorLeft", "move", "to", "left", "on", "the", "current", "line", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/buffer.go#L99-L103
train
c-bata/go-prompt
buffer.go
CursorRight
func (b *Buffer) CursorRight(count int) { l := b.Document().GetCursorRightPosition(count) b.cursorPosition += l return }
go
func (b *Buffer) CursorRight(count int) { l := b.Document().GetCursorRightPosition(count) b.cursorPosition += l return }
[ "func", "(", "b", "*", "Buffer", ")", "CursorRight", "(", "count", "int", ")", "{", "l", ":=", "b", ".", "Document", "(", ")", ".", "GetCursorRightPosition", "(", "count", ")", "\n", "b", ".", "cursorPosition", "+=", "l", "\n", "return", "\n", "}" ]
// CursorRight move to right on the current line.
[ "CursorRight", "move", "to", "right", "on", "the", "current", "line", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/buffer.go#L106-L110
train
c-bata/go-prompt
buffer.go
DeleteBeforeCursor
func (b *Buffer) DeleteBeforeCursor(count int) (deleted string) { debug.Assert(count >= 0, "count should be positive") r := []rune(b.Text()) if b.cursorPosition > 0 { start := b.cursorPosition - count if start < 0 { start = 0 } deleted = string(r[start:b.cursorPosition]) b.setDocument(&Document{ Text: string(r[:start]) + string(r[b.cursorPosition:]), cursorPosition: b.cursorPosition - len([]rune(deleted)), }) } return }
go
func (b *Buffer) DeleteBeforeCursor(count int) (deleted string) { debug.Assert(count >= 0, "count should be positive") r := []rune(b.Text()) if b.cursorPosition > 0 { start := b.cursorPosition - count if start < 0 { start = 0 } deleted = string(r[start:b.cursorPosition]) b.setDocument(&Document{ Text: string(r[:start]) + string(r[b.cursorPosition:]), cursorPosition: b.cursorPosition - len([]rune(deleted)), }) } return }
[ "func", "(", "b", "*", "Buffer", ")", "DeleteBeforeCursor", "(", "count", "int", ")", "(", "deleted", "string", ")", "{", "debug", ".", "Assert", "(", "count", ">=", "0", ",", "\"count should be positive\"", ")", "\n", "r", ":=", "[", "]", "rune", "(",...
// DeleteBeforeCursor delete specified number of characters before cursor and return the deleted text.
[ "DeleteBeforeCursor", "delete", "specified", "number", "of", "characters", "before", "cursor", "and", "return", "the", "deleted", "text", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/buffer.go#L139-L155
train
c-bata/go-prompt
buffer.go
NewLine
func (b *Buffer) NewLine(copyMargin bool) { if copyMargin { b.InsertText("\n"+b.Document().leadingWhitespaceInCurrentLine(), false, true) } else { b.InsertText("\n", false, true) } }
go
func (b *Buffer) NewLine(copyMargin bool) { if copyMargin { b.InsertText("\n"+b.Document().leadingWhitespaceInCurrentLine(), false, true) } else { b.InsertText("\n", false, true) } }
[ "func", "(", "b", "*", "Buffer", ")", "NewLine", "(", "copyMargin", "bool", ")", "{", "if", "copyMargin", "{", "b", ".", "InsertText", "(", "\"\\n\"", "+", "\\n", ",", "false", ",", "true", ")", "\n", "}", "else", "b", ".", "Document", "(", ")", ...
// NewLine means CR.
[ "NewLine", "means", "CR", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/buffer.go#L158-L164
train
c-bata/go-prompt
buffer.go
Delete
func (b *Buffer) Delete(count int) (deleted string) { r := []rune(b.Text()) if b.cursorPosition < len(r) { deleted = b.Document().TextAfterCursor()[:count] b.setText(string(r[:b.cursorPosition]) + string(r[b.cursorPosition+len(deleted):])) } return }
go
func (b *Buffer) Delete(count int) (deleted string) { r := []rune(b.Text()) if b.cursorPosition < len(r) { deleted = b.Document().TextAfterCursor()[:count] b.setText(string(r[:b.cursorPosition]) + string(r[b.cursorPosition+len(deleted):])) } return }
[ "func", "(", "b", "*", "Buffer", ")", "Delete", "(", "count", "int", ")", "(", "deleted", "string", ")", "{", "r", ":=", "[", "]", "rune", "(", "b", ".", "Text", "(", ")", ")", "\n", "if", "b", ".", "cursorPosition", "<", "len", "(", "r", ")"...
// Delete specified number of characters and Return the deleted text.
[ "Delete", "specified", "number", "of", "characters", "and", "Return", "the", "deleted", "text", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/buffer.go#L167-L174
train
c-bata/go-prompt
buffer.go
JoinNextLine
func (b *Buffer) JoinNextLine(separator string) { if !b.Document().OnLastLine() { b.cursorPosition += b.Document().GetEndOfLinePosition() b.Delete(1) // Remove spaces b.setText(b.Document().TextBeforeCursor() + separator + strings.TrimLeft(b.Document().TextAfterCursor(), " ")) } }
go
func (b *Buffer) JoinNextLine(separator string) { if !b.Document().OnLastLine() { b.cursorPosition += b.Document().GetEndOfLinePosition() b.Delete(1) // Remove spaces b.setText(b.Document().TextBeforeCursor() + separator + strings.TrimLeft(b.Document().TextAfterCursor(), " ")) } }
[ "func", "(", "b", "*", "Buffer", ")", "JoinNextLine", "(", "separator", "string", ")", "{", "if", "!", "b", ".", "Document", "(", ")", ".", "OnLastLine", "(", ")", "{", "b", ".", "cursorPosition", "+=", "b", ".", "Document", "(", ")", ".", "GetEndO...
// JoinNextLine joins the next line to the current one by deleting the line ending after the current line.
[ "JoinNextLine", "joins", "the", "next", "line", "to", "the", "current", "one", "by", "deleting", "the", "line", "ending", "after", "the", "current", "line", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/buffer.go#L177-L184
train
c-bata/go-prompt
buffer.go
SwapCharactersBeforeCursor
func (b *Buffer) SwapCharactersBeforeCursor() { if b.cursorPosition >= 2 { x := b.Text()[b.cursorPosition-2 : b.cursorPosition-1] y := b.Text()[b.cursorPosition-1 : b.cursorPosition] b.setText(b.Text()[:b.cursorPosition-2] + y + x + b.Text()[b.cursorPosition:]) } }
go
func (b *Buffer) SwapCharactersBeforeCursor() { if b.cursorPosition >= 2 { x := b.Text()[b.cursorPosition-2 : b.cursorPosition-1] y := b.Text()[b.cursorPosition-1 : b.cursorPosition] b.setText(b.Text()[:b.cursorPosition-2] + y + x + b.Text()[b.cursorPosition:]) } }
[ "func", "(", "b", "*", "Buffer", ")", "SwapCharactersBeforeCursor", "(", ")", "{", "if", "b", ".", "cursorPosition", ">=", "2", "{", "x", ":=", "b", ".", "Text", "(", ")", "[", "b", ".", "cursorPosition", "-", "2", ":", "b", ".", "cursorPosition", ...
// SwapCharactersBeforeCursor swaps the last two characters before the cursor.
[ "SwapCharactersBeforeCursor", "swaps", "the", "last", "two", "characters", "before", "the", "cursor", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/buffer.go#L187-L193
train
c-bata/go-prompt
input_posix.go
TearDown
func (t *PosixParser) TearDown() error { if err := syscall.SetNonblock(t.fd, false); err != nil { return err } if err := term.Restore(); err != nil { return err } return nil }
go
func (t *PosixParser) TearDown() error { if err := syscall.SetNonblock(t.fd, false); err != nil { return err } if err := term.Restore(); err != nil { return err } return nil }
[ "func", "(", "t", "*", "PosixParser", ")", "TearDown", "(", ")", "error", "{", "if", "err", ":=", "syscall", ".", "SetNonblock", "(", "t", ".", "fd", ",", "false", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", ...
// TearDown should be called after stopping input
[ "TearDown", "should", "be", "called", "after", "stopping", "input" ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/input_posix.go#L33-L41
train
c-bata/go-prompt
input_posix.go
NewStandardInputParser
func NewStandardInputParser() *PosixParser { in, err := syscall.Open("/dev/tty", syscall.O_RDONLY, 0) if err != nil { panic(err) } return &PosixParser{ fd: in, } }
go
func NewStandardInputParser() *PosixParser { in, err := syscall.Open("/dev/tty", syscall.O_RDONLY, 0) if err != nil { panic(err) } return &PosixParser{ fd: in, } }
[ "func", "NewStandardInputParser", "(", ")", "*", "PosixParser", "{", "in", ",", "err", ":=", "syscall", ".", "Open", "(", "\"/dev/tty\"", ",", "syscall", ".", "O_RDONLY", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "...
// NewStandardInputParser returns ConsoleParser object to read from stdin.
[ "NewStandardInputParser", "returns", "ConsoleParser", "object", "to", "read", "from", "stdin", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/input_posix.go#L82-L91
train
c-bata/go-prompt
internal/strings/strings.go
IndexNotByte
func IndexNotByte(s string, c byte) int { n := len(s) for i := 0; i < n; i++ { if s[i] != c { return i } } return -1 }
go
func IndexNotByte(s string, c byte) int { n := len(s) for i := 0; i < n; i++ { if s[i] != c { return i } } return -1 }
[ "func", "IndexNotByte", "(", "s", "string", ",", "c", "byte", ")", "int", "{", "n", ":=", "len", "(", "s", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "n", ";", "i", "++", "{", "if", "s", "[", "i", "]", "!=", "c", "{", "return", "i",...
// IndexNotByte is similar with strings.IndexByte but showing the opposite behavior.
[ "IndexNotByte", "is", "similar", "with", "strings", ".", "IndexByte", "but", "showing", "the", "opposite", "behavior", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/internal/strings/strings.go#L6-L14
train
c-bata/go-prompt
internal/strings/strings.go
LastIndexNotByte
func LastIndexNotByte(s string, c byte) int { for i := len(s) - 1; i >= 0; i-- { if s[i] != c { return i } } return -1 }
go
func LastIndexNotByte(s string, c byte) int { for i := len(s) - 1; i >= 0; i-- { if s[i] != c { return i } } return -1 }
[ "func", "LastIndexNotByte", "(", "s", "string", ",", "c", "byte", ")", "int", "{", "for", "i", ":=", "len", "(", "s", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "if", "s", "[", "i", "]", "!=", "c", "{", "return", "i", "\n", ...
// LastIndexNotByte is similar with strings.LastIndexByte but showing the opposite behavior.
[ "LastIndexNotByte", "is", "similar", "with", "strings", ".", "LastIndexByte", "but", "showing", "the", "opposite", "behavior", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/internal/strings/strings.go#L17-L24
train
c-bata/go-prompt
internal/strings/strings.go
IndexNotAny
func IndexNotAny(s, chars string) int { if len(chars) > 0 { if len(s) > 8 { if as, isASCII := makeASCIISet(chars); isASCII { for i := 0; i < len(s); i++ { if as.notContains(s[i]) { return i } } return -1 } } LabelFirstLoop: for i, c := range s { for j, m := range chars { if c != m && j == len(chars)-1 { return i } else if c != m { continue } else { continue LabelFirstLoop } } } } return -1 }
go
func IndexNotAny(s, chars string) int { if len(chars) > 0 { if len(s) > 8 { if as, isASCII := makeASCIISet(chars); isASCII { for i := 0; i < len(s); i++ { if as.notContains(s[i]) { return i } } return -1 } } LabelFirstLoop: for i, c := range s { for j, m := range chars { if c != m && j == len(chars)-1 { return i } else if c != m { continue } else { continue LabelFirstLoop } } } } return -1 }
[ "func", "IndexNotAny", "(", "s", ",", "chars", "string", ")", "int", "{", "if", "len", "(", "chars", ")", ">", "0", "{", "if", "len", "(", "s", ")", ">", "8", "{", "if", "as", ",", "isASCII", ":=", "makeASCIISet", "(", "chars", ")", ";", "isASC...
// IndexNotAny is similar with strings.IndexAny but showing the opposite behavior.
[ "IndexNotAny", "is", "similar", "with", "strings", ".", "IndexAny", "but", "showing", "the", "opposite", "behavior", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/internal/strings/strings.go#L44-L71
train
c-bata/go-prompt
internal/strings/strings.go
LastIndexNotAny
func LastIndexNotAny(s, chars string) int { if len(chars) > 0 { if len(s) > 8 { if as, isASCII := makeASCIISet(chars); isASCII { for i := len(s) - 1; i >= 0; i-- { if as.notContains(s[i]) { return i } } return -1 } } LabelFirstLoop: for i := len(s); i > 0; { r, size := utf8.DecodeLastRuneInString(s[:i]) i -= size for j, m := range chars { if r != m && j == len(chars)-1 { return i } else if r != m { continue } else { continue LabelFirstLoop } } } } return -1 }
go
func LastIndexNotAny(s, chars string) int { if len(chars) > 0 { if len(s) > 8 { if as, isASCII := makeASCIISet(chars); isASCII { for i := len(s) - 1; i >= 0; i-- { if as.notContains(s[i]) { return i } } return -1 } } LabelFirstLoop: for i := len(s); i > 0; { r, size := utf8.DecodeLastRuneInString(s[:i]) i -= size for j, m := range chars { if r != m && j == len(chars)-1 { return i } else if r != m { continue } else { continue LabelFirstLoop } } } } return -1 }
[ "func", "LastIndexNotAny", "(", "s", ",", "chars", "string", ")", "int", "{", "if", "len", "(", "chars", ")", ">", "0", "{", "if", "len", "(", "s", ")", ">", "8", "{", "if", "as", ",", "isASCII", ":=", "makeASCIISet", "(", "chars", ")", ";", "i...
// LastIndexNotAny is similar with strings.LastIndexAny but showing the opposite behavior.
[ "LastIndexNotAny", "is", "similar", "with", "strings", ".", "LastIndexAny", "but", "showing", "the", "opposite", "behavior", "." ]
c8c75cc295ca66affff899dba2c452667e65b9e5
https://github.com/c-bata/go-prompt/blob/c8c75cc295ca66affff899dba2c452667e65b9e5/internal/strings/strings.go#L74-L102
train
alicebob/miniredis
integration/ephemeral.go
arbitraryPort
func arbitraryPort() int { l, err := net.Listen("tcp", "127.0.0.1:0") if err != nil { panic(err) } defer l.Close() addr := l.Addr().String() _, port, err := net.SplitHostPort(addr) if err != nil { panic(err) } p, _ := strconv.Atoi(port) return p }
go
func arbitraryPort() int { l, err := net.Listen("tcp", "127.0.0.1:0") if err != nil { panic(err) } defer l.Close() addr := l.Addr().String() _, port, err := net.SplitHostPort(addr) if err != nil { panic(err) } p, _ := strconv.Atoi(port) return p }
[ "func", "arbitraryPort", "(", ")", "int", "{", "l", ",", "err", ":=", "net", ".", "Listen", "(", "\"tcp\"", ",", "\"127.0.0.1:0\"", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "defer", "l", ".", "Close", "...
// arbitraryPort returns a non-used port.
[ "arbitraryPort", "returns", "a", "non", "-", "used", "port", "." ]
3d7aa1333af56ab862d446678d93aaa6803e0938
https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/integration/ephemeral.go#L75-L89
train
alicebob/miniredis
server/server.go
Addr
func (s *Server) Addr() *net.TCPAddr { s.mu.Lock() defer s.mu.Unlock() if s.l == nil { return nil } return s.l.Addr().(*net.TCPAddr) }
go
func (s *Server) Addr() *net.TCPAddr { s.mu.Lock() defer s.mu.Unlock() if s.l == nil { return nil } return s.l.Addr().(*net.TCPAddr) }
[ "func", "(", "s", "*", "Server", ")", "Addr", "(", ")", "*", "net", ".", "TCPAddr", "{", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "mu", ".", "Unlock", "(", ")", "\n", "if", "s", ".", "l", "==", "nil", "{", "return", ...
// Addr has the net.Addr struct
[ "Addr", "has", "the", "net", ".", "Addr", "struct" ]
3d7aa1333af56ab862d446678d93aaa6803e0938
https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/server/server.go#L90-L97
train
alicebob/miniredis
server/server.go
Close
func (s *Server) Close() { s.mu.Lock() if s.l != nil { s.l.Close() } s.l = nil for c := range s.peers { c.Close() } s.mu.Unlock() s.wg.Wait() }
go
func (s *Server) Close() { s.mu.Lock() if s.l != nil { s.l.Close() } s.l = nil for c := range s.peers { c.Close() } s.mu.Unlock() s.wg.Wait() }
[ "func", "(", "s", "*", "Server", ")", "Close", "(", ")", "{", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "if", "s", ".", "l", "!=", "nil", "{", "s", ".", "l", ".", "Close", "(", ")", "\n", "}", "\n", "s", ".", "l", "=", "nil", "\n", ...
// Close a server started with NewServer. It will wait until all clients are // closed.
[ "Close", "a", "server", "started", "with", "NewServer", ".", "It", "will", "wait", "until", "all", "clients", "are", "closed", "." ]
3d7aa1333af56ab862d446678d93aaa6803e0938
https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/server/server.go#L101-L112
train
alicebob/miniredis
server/server.go
Register
func (s *Server) Register(cmd string, f Cmd) error { s.mu.Lock() defer s.mu.Unlock() cmd = strings.ToUpper(cmd) if _, ok := s.cmds[cmd]; ok { return fmt.Errorf("command already registered: %s", cmd) } s.cmds[cmd] = f return nil }
go
func (s *Server) Register(cmd string, f Cmd) error { s.mu.Lock() defer s.mu.Unlock() cmd = strings.ToUpper(cmd) if _, ok := s.cmds[cmd]; ok { return fmt.Errorf("command already registered: %s", cmd) } s.cmds[cmd] = f return nil }
[ "func", "(", "s", "*", "Server", ")", "Register", "(", "cmd", "string", ",", "f", "Cmd", ")", "error", "{", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "mu", ".", "Unlock", "(", ")", "\n", "cmd", "=", "strings", ".", "ToUp...
// Register a command. It can't have been registered before. Safe to call on a // running server.
[ "Register", "a", "command", ".", "It", "can", "t", "have", "been", "registered", "before", ".", "Safe", "to", "call", "on", "a", "running", "server", "." ]
3d7aa1333af56ab862d446678d93aaa6803e0938
https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/server/server.go#L116-L125
train
alicebob/miniredis
server/server.go
ClientsLen
func (s *Server) ClientsLen() int { s.mu.Lock() defer s.mu.Unlock() return len(s.peers) }
go
func (s *Server) ClientsLen() int { s.mu.Lock() defer s.mu.Unlock() return len(s.peers) }
[ "func", "(", "s", "*", "Server", ")", "ClientsLen", "(", ")", "int", "{", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "len", "(", "s", ".", "peers", ")", "\n", "}" ]
// ClientsLen gives the number of connected clients right now
[ "ClientsLen", "gives", "the", "number", "of", "connected", "clients", "right", "now" ]
3d7aa1333af56ab862d446678d93aaa6803e0938
https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/server/server.go#L179-L183
train
alicebob/miniredis
server/server.go
TotalConnections
func (s *Server) TotalConnections() int { s.mu.Lock() defer s.mu.Unlock() return s.infoConns }
go
func (s *Server) TotalConnections() int { s.mu.Lock() defer s.mu.Unlock() return s.infoConns }
[ "func", "(", "s", "*", "Server", ")", "TotalConnections", "(", ")", "int", "{", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "s", ".", "infoConns", "\n", "}" ]
// TotalConnections give the number of clients connected since the server // started, including the currently connected ones
[ "TotalConnections", "give", "the", "number", "of", "clients", "connected", "since", "the", "server", "started", "including", "the", "currently", "connected", "ones" ]
3d7aa1333af56ab862d446678d93aaa6803e0938
https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/server/server.go#L187-L191
train
alicebob/miniredis
server/server.go
Flush
func (c *Peer) Flush() { c.mu.Lock() defer c.mu.Unlock() c.w.Flush() }
go
func (c *Peer) Flush() { c.mu.Lock() defer c.mu.Unlock() c.w.Flush() }
[ "func", "(", "c", "*", "Peer", ")", "Flush", "(", ")", "{", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "Unlock", "(", ")", "\n", "c", ".", "w", ".", "Flush", "(", ")", "\n", "}" ]
// Flush the write buffer. Called automatically after every redis command
[ "Flush", "the", "write", "buffer", ".", "Called", "automatically", "after", "every", "redis", "command" ]
3d7aa1333af56ab862d446678d93aaa6803e0938
https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/server/server.go#L203-L207
train
alicebob/miniredis
server/server.go
Close
func (c *Peer) Close() { c.mu.Lock() defer c.mu.Unlock() c.closed = true }
go
func (c *Peer) Close() { c.mu.Lock() defer c.mu.Unlock() c.closed = true }
[ "func", "(", "c", "*", "Peer", ")", "Close", "(", ")", "{", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "Unlock", "(", ")", "\n", "c", ".", "closed", "=", "true", "\n", "}" ]
// Close the client connection after the current command is done.
[ "Close", "the", "client", "connection", "after", "the", "current", "command", "is", "done", "." ]
3d7aa1333af56ab862d446678d93aaa6803e0938
https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/server/server.go#L210-L214
train
alicebob/miniredis
server/server.go
OnDisconnect
func (c *Peer) OnDisconnect(f func()) { c.onDisconnect = append(c.onDisconnect, f) }
go
func (c *Peer) OnDisconnect(f func()) { c.onDisconnect = append(c.onDisconnect, f) }
[ "func", "(", "c", "*", "Peer", ")", "OnDisconnect", "(", "f", "func", "(", ")", ")", "{", "c", ".", "onDisconnect", "=", "append", "(", "c", ".", "onDisconnect", ",", "f", ")", "\n", "}" ]
// Register a function to execute on disconnect. There can be multiple // functions registered.
[ "Register", "a", "function", "to", "execute", "on", "disconnect", ".", "There", "can", "be", "multiple", "functions", "registered", "." ]
3d7aa1333af56ab862d446678d93aaa6803e0938
https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/server/server.go#L218-L220
train
alicebob/miniredis
server/server.go
Block
func (c *Peer) Block(f func(*Writer)) { c.mu.Lock() defer c.mu.Unlock() f(&Writer{c.w}) }
go
func (c *Peer) Block(f func(*Writer)) { c.mu.Lock() defer c.mu.Unlock() f(&Writer{c.w}) }
[ "func", "(", "c", "*", "Peer", ")", "Block", "(", "f", "func", "(", "*", "Writer", ")", ")", "{", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "Unlock", "(", ")", "\n", "f", "(", "&", "Writer", "{", "c", ".",...
// issue multiple calls, guarded with a mutex
[ "issue", "multiple", "calls", "guarded", "with", "a", "mutex" ]
3d7aa1333af56ab862d446678d93aaa6803e0938
https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/server/server.go#L223-L227
train
alicebob/miniredis
server/server.go
WriteLen
func (c *Peer) WriteLen(n int) { c.Block(func(w *Writer) { w.WriteLen(n) }) }
go
func (c *Peer) WriteLen(n int) { c.Block(func(w *Writer) { w.WriteLen(n) }) }
[ "func", "(", "c", "*", "Peer", ")", "WriteLen", "(", "n", "int", ")", "{", "c", ".", "Block", "(", "func", "(", "w", "*", "Writer", ")", "{", "w", ".", "WriteLen", "(", "n", ")", "\n", "}", ")", "\n", "}" ]
// WriteLen starts an array with the given length
[ "WriteLen", "starts", "an", "array", "with", "the", "given", "length" ]
3d7aa1333af56ab862d446678d93aaa6803e0938
https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/server/server.go#L263-L267
train
alicebob/miniredis
cmd_string.go
commandsString
func commandsString(m *Miniredis) { m.srv.Register("APPEND", m.cmdAppend) m.srv.Register("BITCOUNT", m.cmdBitcount) m.srv.Register("BITOP", m.cmdBitop) m.srv.Register("BITPOS", m.cmdBitpos) m.srv.Register("DECRBY", m.cmdDecrby) m.srv.Register("DECR", m.cmdDecr) m.srv.Register("GETBIT", m.cmdGetbit) m.srv.Register("GET", m.cmdGet) m.srv.Register("GETRANGE", m.cmdGetrange) m.srv.Register("GETSET", m.cmdGetset) m.srv.Register("INCRBYFLOAT", m.cmdIncrbyfloat) m.srv.Register("INCRBY", m.cmdIncrby) m.srv.Register("INCR", m.cmdIncr) m.srv.Register("MGET", m.cmdMget) m.srv.Register("MSET", m.cmdMset) m.srv.Register("MSETNX", m.cmdMsetnx) m.srv.Register("PSETEX", m.cmdPsetex) m.srv.Register("SETBIT", m.cmdSetbit) m.srv.Register("SETEX", m.cmdSetex) m.srv.Register("SET", m.cmdSet) m.srv.Register("SETNX", m.cmdSetnx) m.srv.Register("SETRANGE", m.cmdSetrange) m.srv.Register("STRLEN", m.cmdStrlen) }
go
func commandsString(m *Miniredis) { m.srv.Register("APPEND", m.cmdAppend) m.srv.Register("BITCOUNT", m.cmdBitcount) m.srv.Register("BITOP", m.cmdBitop) m.srv.Register("BITPOS", m.cmdBitpos) m.srv.Register("DECRBY", m.cmdDecrby) m.srv.Register("DECR", m.cmdDecr) m.srv.Register("GETBIT", m.cmdGetbit) m.srv.Register("GET", m.cmdGet) m.srv.Register("GETRANGE", m.cmdGetrange) m.srv.Register("GETSET", m.cmdGetset) m.srv.Register("INCRBYFLOAT", m.cmdIncrbyfloat) m.srv.Register("INCRBY", m.cmdIncrby) m.srv.Register("INCR", m.cmdIncr) m.srv.Register("MGET", m.cmdMget) m.srv.Register("MSET", m.cmdMset) m.srv.Register("MSETNX", m.cmdMsetnx) m.srv.Register("PSETEX", m.cmdPsetex) m.srv.Register("SETBIT", m.cmdSetbit) m.srv.Register("SETEX", m.cmdSetex) m.srv.Register("SET", m.cmdSet) m.srv.Register("SETNX", m.cmdSetnx) m.srv.Register("SETRANGE", m.cmdSetrange) m.srv.Register("STRLEN", m.cmdStrlen) }
[ "func", "commandsString", "(", "m", "*", "Miniredis", ")", "{", "m", ".", "srv", ".", "Register", "(", "\"APPEND\"", ",", "m", ".", "cmdAppend", ")", "\n", "m", ".", "srv", ".", "Register", "(", "\"BITCOUNT\"", ",", "m", ".", "cmdBitcount", ")", "\n"...
// commandsString handles all string value operations.
[ "commandsString", "handles", "all", "string", "value", "operations", "." ]
3d7aa1333af56ab862d446678d93aaa6803e0938
https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/cmd_string.go#L14-L38
train
alicebob/miniredis
cmd_string.go
withRange
func withRange(v string, start, end int) string { s, e := redisRange(len(v), start, end, true /* string getrange symantics */) return v[s:e] }
go
func withRange(v string, start, end int) string { s, e := redisRange(len(v), start, end, true /* string getrange symantics */) return v[s:e] }
[ "func", "withRange", "(", "v", "string", ",", "start", ",", "end", "int", ")", "string", "{", "s", ",", "e", ":=", "redisRange", "(", "len", "(", "v", ")", ",", "start", ",", "end", ",", "true", ")", "\n", "return", "v", "[", "s", ":", "e", "...
// Redis range. both start and end can be negative.
[ "Redis", "range", ".", "both", "start", "and", "end", "can", "be", "negative", "." ]
3d7aa1333af56ab862d446678d93aaa6803e0938
https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/cmd_string.go#L1089-L1092
train
alicebob/miniredis
cmd_string.go
sliceBinOp
func sliceBinOp(f func(a, b byte) byte, a, b []byte) []byte { maxl := len(a) if len(b) > maxl { maxl = len(b) } lA := make([]byte, maxl) copy(lA, a) lB := make([]byte, maxl) copy(lB, b) res := make([]byte, maxl) for i := range res { res[i] = f(lA[i], lB[i]) } return res }
go
func sliceBinOp(f func(a, b byte) byte, a, b []byte) []byte { maxl := len(a) if len(b) > maxl { maxl = len(b) } lA := make([]byte, maxl) copy(lA, a) lB := make([]byte, maxl) copy(lB, b) res := make([]byte, maxl) for i := range res { res[i] = f(lA[i], lB[i]) } return res }
[ "func", "sliceBinOp", "(", "f", "func", "(", "a", ",", "b", "byte", ")", "byte", ",", "a", ",", "b", "[", "]", "byte", ")", "[", "]", "byte", "{", "maxl", ":=", "len", "(", "a", ")", "\n", "if", "len", "(", "b", ")", ">", "maxl", "{", "ma...
// sliceBinOp applies an operator to all slice elements, with Redis string // padding logic.
[ "sliceBinOp", "applies", "an", "operator", "to", "all", "slice", "elements", "with", "Redis", "string", "padding", "logic", "." ]
3d7aa1333af56ab862d446678d93aaa6803e0938
https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/cmd_string.go#L1107-L1121
train
alicebob/miniredis
cmd_string.go
toBits
func toBits(s byte) [8]bool { r := [8]bool{} for i := range r { if s&(uint8(1)<<uint8(7-i)) != 0 { r[i] = true } } return r }
go
func toBits(s byte) [8]bool { r := [8]bool{} for i := range r { if s&(uint8(1)<<uint8(7-i)) != 0 { r[i] = true } } return r }
[ "func", "toBits", "(", "s", "byte", ")", "[", "8", "]", "bool", "{", "r", ":=", "[", "8", "]", "bool", "{", "}", "\n", "for", "i", ":=", "range", "r", "{", "if", "s", "&", "(", "uint8", "(", "1", ")", "<<", "uint8", "(", "7", "-", "i", ...
// toBits changes a byte in 8 bools.
[ "toBits", "changes", "a", "byte", "in", "8", "bools", "." ]
3d7aa1333af56ab862d446678d93aaa6803e0938
https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/cmd_string.go#L1136-L1144
train
alicebob/miniredis
cmd_hash.go
commandsHash
func commandsHash(m *Miniredis) { m.srv.Register("HDEL", m.cmdHdel) m.srv.Register("HEXISTS", m.cmdHexists) m.srv.Register("HGET", m.cmdHget) m.srv.Register("HGETALL", m.cmdHgetall) m.srv.Register("HINCRBY", m.cmdHincrby) m.srv.Register("HINCRBYFLOAT", m.cmdHincrbyfloat) m.srv.Register("HKEYS", m.cmdHkeys) m.srv.Register("HLEN", m.cmdHlen) m.srv.Register("HMGET", m.cmdHmget) m.srv.Register("HMSET", m.cmdHmset) m.srv.Register("HSET", m.cmdHset) m.srv.Register("HSETNX", m.cmdHsetnx) m.srv.Register("HVALS", m.cmdHvals) m.srv.Register("HSCAN", m.cmdHscan) }
go
func commandsHash(m *Miniredis) { m.srv.Register("HDEL", m.cmdHdel) m.srv.Register("HEXISTS", m.cmdHexists) m.srv.Register("HGET", m.cmdHget) m.srv.Register("HGETALL", m.cmdHgetall) m.srv.Register("HINCRBY", m.cmdHincrby) m.srv.Register("HINCRBYFLOAT", m.cmdHincrbyfloat) m.srv.Register("HKEYS", m.cmdHkeys) m.srv.Register("HLEN", m.cmdHlen) m.srv.Register("HMGET", m.cmdHmget) m.srv.Register("HMSET", m.cmdHmset) m.srv.Register("HSET", m.cmdHset) m.srv.Register("HSETNX", m.cmdHsetnx) m.srv.Register("HVALS", m.cmdHvals) m.srv.Register("HSCAN", m.cmdHscan) }
[ "func", "commandsHash", "(", "m", "*", "Miniredis", ")", "{", "m", ".", "srv", ".", "Register", "(", "\"HDEL\"", ",", "m", ".", "cmdHdel", ")", "\n", "m", ".", "srv", ".", "Register", "(", "\"HEXISTS\"", ",", "m", ".", "cmdHexists", ")", "\n", "m",...
// commandsHash handles all hash value operations.
[ "commandsHash", "handles", "all", "hash", "value", "operations", "." ]
3d7aa1333af56ab862d446678d93aaa6803e0938
https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/cmd_hash.go#L13-L28
train
alicebob/miniredis
keys.go
patternRE
func patternRE(k string) *regexp.Regexp { re := bytes.Buffer{} re.WriteString(`^\Q`) for i := 0; i < len(k); i++ { p := k[i] switch p { case '*': re.WriteString(`\E.*\Q`) case '?': re.WriteString(`\E.\Q`) case '[': charClass := bytes.Buffer{} i++ for ; i < len(k); i++ { if k[i] == ']' { break } if k[i] == '\\' { if i == len(k)-1 { // Ends with a '\'. U-huh. return nil } charClass.WriteByte(k[i]) i++ charClass.WriteByte(k[i]) continue } charClass.WriteByte(k[i]) } if charClass.Len() == 0 { // '[]' is valid in Redis, but matches nothing. return nil } re.WriteString(`\E[`) re.Write(charClass.Bytes()) re.WriteString(`]\Q`) case '\\': if i == len(k)-1 { // Ends with a '\'. U-huh. return nil } // Forget the \, keep the next char. i++ re.WriteByte(k[i]) continue default: re.WriteByte(p) } } re.WriteString(`\E$`) return regexp.MustCompile(re.String()) }
go
func patternRE(k string) *regexp.Regexp { re := bytes.Buffer{} re.WriteString(`^\Q`) for i := 0; i < len(k); i++ { p := k[i] switch p { case '*': re.WriteString(`\E.*\Q`) case '?': re.WriteString(`\E.\Q`) case '[': charClass := bytes.Buffer{} i++ for ; i < len(k); i++ { if k[i] == ']' { break } if k[i] == '\\' { if i == len(k)-1 { // Ends with a '\'. U-huh. return nil } charClass.WriteByte(k[i]) i++ charClass.WriteByte(k[i]) continue } charClass.WriteByte(k[i]) } if charClass.Len() == 0 { // '[]' is valid in Redis, but matches nothing. return nil } re.WriteString(`\E[`) re.Write(charClass.Bytes()) re.WriteString(`]\Q`) case '\\': if i == len(k)-1 { // Ends with a '\'. U-huh. return nil } // Forget the \, keep the next char. i++ re.WriteByte(k[i]) continue default: re.WriteByte(p) } } re.WriteString(`\E$`) return regexp.MustCompile(re.String()) }
[ "func", "patternRE", "(", "k", "string", ")", "*", "regexp", ".", "Regexp", "{", "re", ":=", "bytes", ".", "Buffer", "{", "}", "\n", "re", ".", "WriteString", "(", "`^\\Q`", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "k", ")",...
// patternRE compiles a KEYS argument to a regexp. Returns nil if the given // pattern will never match anything. // The general strategy is to sandwich all non-meta characters between \Q...\E.
[ "patternRE", "compiles", "a", "KEYS", "argument", "to", "a", "regexp", ".", "Returns", "nil", "if", "the", "given", "pattern", "will", "never", "match", "anything", ".", "The", "general", "strategy", "is", "to", "sandwich", "all", "non", "-", "meta", "char...
3d7aa1333af56ab862d446678d93aaa6803e0938
https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/keys.go#L13-L65
train
alicebob/miniredis
direct.go
Select
func (m *Miniredis) Select(i int) { m.Lock() defer m.Unlock() m.selectedDB = i }
go
func (m *Miniredis) Select(i int) { m.Lock() defer m.Unlock() m.selectedDB = i }
[ "func", "(", "m", "*", "Miniredis", ")", "Select", "(", "i", "int", ")", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n", "m", ".", "selectedDB", "=", "i", "\n", "}" ]
// Select sets the DB id for all direct commands.
[ "Select", "sets", "the", "DB", "id", "for", "all", "direct", "commands", "." ]
3d7aa1333af56ab862d446678d93aaa6803e0938
https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L22-L26
train
alicebob/miniredis
direct.go
Keys
func (db *RedisDB) Keys() []string { db.master.Lock() defer db.master.Unlock() return db.allKeys() }
go
func (db *RedisDB) Keys() []string { db.master.Lock() defer db.master.Unlock() return db.allKeys() }
[ "func", "(", "db", "*", "RedisDB", ")", "Keys", "(", ")", "[", "]", "string", "{", "db", ".", "master", ".", "Lock", "(", ")", "\n", "defer", "db", ".", "master", ".", "Unlock", "(", ")", "\n", "return", "db", ".", "allKeys", "(", ")", "\n", ...
// Keys returns all keys, sorted.
[ "Keys", "returns", "all", "keys", "sorted", "." ]
3d7aa1333af56ab862d446678d93aaa6803e0938
https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L34-L38
train