repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
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 {
... | 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 {
... | [
"func",
"(",
"d",
"*",
"Document",
")",
"FindStartOfPreviousWordUntilSeparatorIgnoreNextToCursor",
"(",
"sep",
"string",
")",
"int",
"{",
"if",
"sep",
"==",
"\"",
"\"",
"{",
"return",
"d",
".",
"FindStartOfPreviousWordWithSpace",
"(",
")",
"\n",
"}",
"\n\n",
"... | // 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\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\n",
"x",
":=",
"d",
".",
"Text... | // 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 {
retu... | 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 {
retu... | [
"func",
"(",
"d",
"*",
"Document",
")",
"FindEndOfCurrentWordUntilSeparatorIgnoreNextToCursor",
"(",
"sep",
"string",
")",
"int",
"{",
"if",
"sep",
"==",
"\"",
"\"",
"{",
"return",
"d",
".",
"FindEndOfCurrentWordWithSpace",
"(",
")",
"\n",
"}",
"\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",
"return",
"s",
"[",
"len",
"(",
"s",
")"... | // 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 cum... | 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 cum... | [
"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",
".",
"Line... | // 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 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",
",",
"\"",
"\"",
"+",
"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, ... | 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, ... | [
"func",
"(",
"p",
"*",
"Prompt",
")",
"Run",
"(",
")",
"{",
"defer",
"debug",
".",
"Teardown",
"(",
")",
"\n",
"debug",
".",
"Log",
"(",
"\"",
"\"",
")",
"\n",
"p",
".",
"setUp",
"(",
")",
"\n",
"defer",
"p",
".",
"tearDown",
"(",
")",
"\n\n"... | // 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... | 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... | [
"func",
"(",
"p",
"*",
"Prompt",
")",
"Input",
"(",
")",
"string",
"{",
"defer",
"debug",
".",
"Teardown",
"(",
")",
"\n",
"debug",
".",
"Log",
"(",
"\"",
"\"",
")",
"\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",
".",
"Flus... | // 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.o... | 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.o... | [
"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 a... | // 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 + "\... | 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 + "\... | [
"func",
"(",
"r",
"*",
"Render",
")",
"BreakLine",
"(",
"buffer",
"*",
"Buffer",
")",
"{",
"// Erasing and Render",
"cursor",
":=",
"runewidth",
".",
"StringWidth",
"(",
"buffer",
".",
"Document",
"(",
")",
".",
"TextBeforeCursor",
"(",
")",
")",
"+",
"r... | // 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\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 | s... | 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 | s... | [
"func",
"SetRaw",
"(",
"fd",
"int",
")",
"error",
"{",
"n",
",",
"err",
":=",
"getOriginalTermios",
"(",
"fd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"n",
".",
"Iflag",
"&^=",
"syscall",
".",
"IGNBRK",
"|",
... | // 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(st... | 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(st... | [
"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{
Tex... | 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{
Tex... | [
"func",
"(",
"b",
"*",
"Buffer",
")",
"DeleteBeforeCursor",
"(",
"count",
"int",
")",
"(",
"deleted",
"string",
")",
"{",
"debug",
".",
"Assert",
"(",
"count",
">=",
"0",
",",
"\"",
"\"",
")",
"\n",
"r",
":=",
"[",
"]",
"rune",
"(",
"b",
".",
"... | // 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",
"\"",
"+",
"b",
".",
"Document",
"(",
")",
".",
"leadingWhitespaceInCurrentLine",
"(",
")",
",",
... | // 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",
"(",
"\"",
"\"",
",",
"syscall",
".",
"O_RDONLY",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n... | // 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 {
... | 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 {
... | [
"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.... | 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.... | [
"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",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\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.Regist... | 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.Regist... | [
"func",
"commandsString",
"(",
"m",
"*",
"Miniredis",
")",
"{",
"m",
".",
"srv",
".",
"Register",
"(",
"\"",
"\"",
",",
"m",
".",
"cmdAppend",
")",
"\n",
"m",
".",
"srv",
".",
"Register",
"(",
"\"",
"\"",
",",
"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",
"/* string getrange symantics */",
")",
"\n",
"return",
... | // 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.sr... | 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.sr... | [
"func",
"commandsHash",
"(",
"m",
"*",
"Miniredis",
")",
"{",
"m",
".",
"srv",
".",
"Register",
"(",
"\"",
"\"",
",",
"m",
".",
"cmdHdel",
")",
"\n",
"m",
".",
"srv",
".",
"Register",
"(",
"\"",
"\"",
",",
"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] == ']' {
... | 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] == ']' {
... | [
"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 |
alicebob/miniredis | direct.go | FlushDB | func (db *RedisDB) FlushDB() {
db.master.Lock()
defer db.master.Unlock()
db.flush()
} | go | func (db *RedisDB) FlushDB() {
db.master.Lock()
defer db.master.Unlock()
db.flush()
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"FlushDB",
"(",
")",
"{",
"db",
".",
"master",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"master",
".",
"Unlock",
"(",
")",
"\n",
"db",
".",
"flush",
"(",
")",
"\n",
"}"
] | // FlushDB removes all keys. | [
"FlushDB",
"removes",
"all",
"keys",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L59-L63 | train |
alicebob/miniredis | direct.go | Get | func (m *Miniredis) Get(k string) (string, error) {
return m.DB(m.selectedDB).Get(k)
} | go | func (m *Miniredis) Get(k string) (string, error) {
return m.DB(m.selectedDB).Get(k)
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"Get",
"(",
"k",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"m",
".",
"DB",
"(",
"m",
".",
"selectedDB",
")",
".",
"Get",
"(",
"k",
")",
"\n",
"}"
] | // Get returns string keys added with SET. | [
"Get",
"returns",
"string",
"keys",
"added",
"with",
"SET",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L66-L68 | train |
alicebob/miniredis | direct.go | Get | func (db *RedisDB) Get(k string) (string, error) {
db.master.Lock()
defer db.master.Unlock()
if !db.exists(k) {
return "", ErrKeyNotFound
}
if db.t(k) != "string" {
return "", ErrWrongType
}
return db.stringGet(k), nil
} | go | func (db *RedisDB) Get(k string) (string, error) {
db.master.Lock()
defer db.master.Unlock()
if !db.exists(k) {
return "", ErrKeyNotFound
}
if db.t(k) != "string" {
return "", ErrWrongType
}
return db.stringGet(k), nil
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"Get",
"(",
"k",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"db",
".",
"master",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"master",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"db",
"."... | // Get returns a string key. | [
"Get",
"returns",
"a",
"string",
"key",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L71-L81 | train |
alicebob/miniredis | direct.go | Set | func (m *Miniredis) Set(k, v string) error {
return m.DB(m.selectedDB).Set(k, v)
} | go | func (m *Miniredis) Set(k, v string) error {
return m.DB(m.selectedDB).Set(k, v)
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"Set",
"(",
"k",
",",
"v",
"string",
")",
"error",
"{",
"return",
"m",
".",
"DB",
"(",
"m",
".",
"selectedDB",
")",
".",
"Set",
"(",
"k",
",",
"v",
")",
"\n",
"}"
] | // Set sets a string key. Removes expire. | [
"Set",
"sets",
"a",
"string",
"key",
".",
"Removes",
"expire",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L84-L86 | train |
alicebob/miniredis | direct.go | Set | func (db *RedisDB) Set(k, v string) error {
db.master.Lock()
defer db.master.Unlock()
if db.exists(k) && db.t(k) != "string" {
return ErrWrongType
}
db.del(k, true) // Remove expire
db.stringSet(k, v)
return nil
} | go | func (db *RedisDB) Set(k, v string) error {
db.master.Lock()
defer db.master.Unlock()
if db.exists(k) && db.t(k) != "string" {
return ErrWrongType
}
db.del(k, true) // Remove expire
db.stringSet(k, v)
return nil
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"Set",
"(",
"k",
",",
"v",
"string",
")",
"error",
"{",
"db",
".",
"master",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"master",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"db",
".",
"exists",
"(",
"... | // Set sets a string key. Removes expire.
// Unlike redis the key can't be an existing non-string key. | [
"Set",
"sets",
"a",
"string",
"key",
".",
"Removes",
"expire",
".",
"Unlike",
"redis",
"the",
"key",
"can",
"t",
"be",
"an",
"existing",
"non",
"-",
"string",
"key",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L90-L100 | train |
alicebob/miniredis | direct.go | Push | func (db *RedisDB) Push(k string, v ...string) (int, error) {
db.master.Lock()
defer db.master.Unlock()
if db.exists(k) && db.t(k) != "list" {
return 0, ErrWrongType
}
return db.listPush(k, v...), nil
} | go | func (db *RedisDB) Push(k string, v ...string) (int, error) {
db.master.Lock()
defer db.master.Unlock()
if db.exists(k) && db.t(k) != "list" {
return 0, ErrWrongType
}
return db.listPush(k, v...), nil
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"Push",
"(",
"k",
"string",
",",
"v",
"...",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"db",
".",
"master",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"master",
".",
"Unlock",
"(",
")",
"... | // Push add element at the end. Is called RPUSH in redis. Returns the new length. | [
"Push",
"add",
"element",
"at",
"the",
"end",
".",
"Is",
"called",
"RPUSH",
"in",
"redis",
".",
"Returns",
"the",
"new",
"length",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L200-L208 | train |
alicebob/miniredis | direct.go | SetTTL | func (m *Miniredis) SetTTL(k string, ttl time.Duration) {
m.DB(m.selectedDB).SetTTL(k, ttl)
} | go | func (m *Miniredis) SetTTL(k string, ttl time.Duration) {
m.DB(m.selectedDB).SetTTL(k, ttl)
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"SetTTL",
"(",
"k",
"string",
",",
"ttl",
"time",
".",
"Duration",
")",
"{",
"m",
".",
"DB",
"(",
"m",
".",
"selectedDB",
")",
".",
"SetTTL",
"(",
"k",
",",
"ttl",
")",
"\n",
"}"
] | // SetTTL sets the TTL of a key. | [
"SetTTL",
"sets",
"the",
"TTL",
"of",
"a",
"key",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L332-L334 | train |
alicebob/miniredis | direct.go | SetTTL | func (db *RedisDB) SetTTL(k string, ttl time.Duration) {
db.master.Lock()
defer db.master.Unlock()
db.ttl[k] = ttl
db.keyVersion[k]++
} | go | func (db *RedisDB) SetTTL(k string, ttl time.Duration) {
db.master.Lock()
defer db.master.Unlock()
db.ttl[k] = ttl
db.keyVersion[k]++
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"SetTTL",
"(",
"k",
"string",
",",
"ttl",
"time",
".",
"Duration",
")",
"{",
"db",
".",
"master",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"master",
".",
"Unlock",
"(",
")",
"\n",
"db",
".",
"ttl"... | // SetTTL sets the time to live of a key. | [
"SetTTL",
"sets",
"the",
"time",
"to",
"live",
"of",
"a",
"key",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L337-L342 | train |
alicebob/miniredis | direct.go | HGet | func (m *Miniredis) HGet(k, f string) string {
return m.DB(m.selectedDB).HGet(k, f)
} | go | func (m *Miniredis) HGet(k, f string) string {
return m.DB(m.selectedDB).HGet(k, f)
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"HGet",
"(",
"k",
",",
"f",
"string",
")",
"string",
"{",
"return",
"m",
".",
"DB",
"(",
"m",
".",
"selectedDB",
")",
".",
"HGet",
"(",
"k",
",",
"f",
")",
"\n",
"}"
] | // HGet returns hash keys added with HSET.
// This will return an empty string if the key is not set. Redis would return
// a nil.
// Returns empty string when the key is of a different type. | [
"HGet",
"returns",
"hash",
"keys",
"added",
"with",
"HSET",
".",
"This",
"will",
"return",
"an",
"empty",
"string",
"if",
"the",
"key",
"is",
"not",
"set",
".",
"Redis",
"would",
"return",
"a",
"nil",
".",
"Returns",
"empty",
"string",
"when",
"the",
"... | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L372-L374 | train |
alicebob/miniredis | direct.go | HGet | func (db *RedisDB) HGet(k, f string) string {
db.master.Lock()
defer db.master.Unlock()
h, ok := db.hashKeys[k]
if !ok {
return ""
}
return h[f]
} | go | func (db *RedisDB) HGet(k, f string) string {
db.master.Lock()
defer db.master.Unlock()
h, ok := db.hashKeys[k]
if !ok {
return ""
}
return h[f]
} | [
"func",
"(",
"db",
"*",
"RedisDB",
")",
"HGet",
"(",
"k",
",",
"f",
"string",
")",
"string",
"{",
"db",
".",
"master",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"master",
".",
"Unlock",
"(",
")",
"\n",
"h",
",",
"ok",
":=",
"db",
".",
... | // HGet returns hash keys added with HSET.
// Returns empty string when the key is of a different type. | [
"HGet",
"returns",
"hash",
"keys",
"added",
"with",
"HSET",
".",
"Returns",
"empty",
"string",
"when",
"the",
"key",
"is",
"of",
"a",
"different",
"type",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L378-L386 | train |
alicebob/miniredis | direct.go | Publish | func (m *Miniredis) Publish(channel, message string) int {
m.Lock()
defer m.Unlock()
return m.publish(channel, message)
} | go | func (m *Miniredis) Publish(channel, message string) int {
m.Lock()
defer m.Unlock()
return m.publish(channel, message)
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"Publish",
"(",
"channel",
",",
"message",
"string",
")",
"int",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n",
"return",
"m",
".",
"publish",
"(",
"channel",
",",
"mes... | // Publish a message to subscribers. Returns the number of receivers. | [
"Publish",
"a",
"message",
"to",
"subscribers",
".",
"Returns",
"the",
"number",
"of",
"receivers",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L552-L556 | train |
alicebob/miniredis | direct.go | PubSubNumPat | func (m *Miniredis) PubSubNumPat() int {
m.Lock()
defer m.Unlock()
return countPsubs(m.allSubscribers())
} | go | func (m *Miniredis) PubSubNumPat() int {
m.Lock()
defer m.Unlock()
return countPsubs(m.allSubscribers())
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"PubSubNumPat",
"(",
")",
"int",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"countPsubs",
"(",
"m",
".",
"allSubscribers",
"(",
")",
")",
"\n",
"}"
] | // PubSubNumPat is "PUBSUB NUMPAT" | [
"PubSubNumPat",
"is",
"PUBSUB",
"NUMPAT"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/direct.go#L583-L588 | train |
alicebob/miniredis | server/proto.go | readArray | func readArray(rd *bufio.Reader) ([]string, error) {
line, err := rd.ReadString('\n')
if err != nil {
return nil, err
}
if len(line) < 3 {
return nil, ErrProtocol
}
switch line[0] {
default:
return nil, ErrProtocol
case '*':
l, err := strconv.Atoi(line[1 : len(line)-2])
if err != nil {
return nil,... | go | func readArray(rd *bufio.Reader) ([]string, error) {
line, err := rd.ReadString('\n')
if err != nil {
return nil, err
}
if len(line) < 3 {
return nil, ErrProtocol
}
switch line[0] {
default:
return nil, ErrProtocol
case '*':
l, err := strconv.Atoi(line[1 : len(line)-2])
if err != nil {
return nil,... | [
"func",
"readArray",
"(",
"rd",
"*",
"bufio",
".",
"Reader",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"line",
",",
"err",
":=",
"rd",
".",
"ReadString",
"(",
"'\\n'",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
... | // client always sends arrays with bulk strings | [
"client",
"always",
"sends",
"arrays",
"with",
"bulk",
"strings"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/server/proto.go#L13-L41 | train |
alicebob/miniredis | pubsub.go | Count | func (s *Subscriber) Count() int {
s.mu.Lock()
defer s.mu.Unlock()
return s.count()
} | go | func (s *Subscriber) Count() int {
s.mu.Lock()
defer s.mu.Unlock()
return s.count()
} | [
"func",
"(",
"s",
"*",
"Subscriber",
")",
"Count",
"(",
")",
"int",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"s",
".",
"count",
"(",
")",
"\n",
"}"
] | // Count the total number of channels and patterns | [
"Count",
"the",
"total",
"number",
"of",
"channels",
"and",
"patterns"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/pubsub.go#L41-L45 | train |
alicebob/miniredis | pubsub.go | Channels | func (s *Subscriber) Channels() []string {
s.mu.Lock()
defer s.mu.Unlock()
var cs []string
for c := range s.channels {
cs = append(cs, c)
}
sort.Strings(cs)
return cs
} | go | func (s *Subscriber) Channels() []string {
s.mu.Lock()
defer s.mu.Unlock()
var cs []string
for c := range s.channels {
cs = append(cs, c)
}
sort.Strings(cs)
return cs
} | [
"func",
"(",
"s",
"*",
"Subscriber",
")",
"Channels",
"(",
")",
"[",
"]",
"string",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"var",
"cs",
"[",
"]",
"string",
"\n",
"for",
"c",... | // List all subscribed channels, in alphabetical order | [
"List",
"all",
"subscribed",
"channels",
"in",
"alphabetical",
"order"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/pubsub.go#L92-L102 | train |
alicebob/miniredis | pubsub.go | Patterns | func (s *Subscriber) Patterns() []string {
s.mu.Lock()
defer s.mu.Unlock()
var ps []string
for p := range s.patterns {
ps = append(ps, p)
}
sort.Strings(ps)
return ps
} | go | func (s *Subscriber) Patterns() []string {
s.mu.Lock()
defer s.mu.Unlock()
var ps []string
for p := range s.patterns {
ps = append(ps, p)
}
sort.Strings(ps)
return ps
} | [
"func",
"(",
"s",
"*",
"Subscriber",
")",
"Patterns",
"(",
")",
"[",
"]",
"string",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"var",
"ps",
"[",
"]",
"string",
"\n",
"for",
"p",... | // List all subscribed patterns, in alphabetical order | [
"List",
"all",
"subscribed",
"patterns",
"in",
"alphabetical",
"order"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/pubsub.go#L105-L115 | train |
alicebob/miniredis | pubsub.go | Publish | func (s *Subscriber) Publish(c, msg string) int {
s.mu.Lock()
defer s.mu.Unlock()
found := 0
subs:
for sub := range s.channels {
if sub == c {
s.publish <- PubsubMessage{c, msg}
found++
break subs
}
}
pats:
for _, pat := range s.patterns {
if pat.MatchString(c) {
s.publish <- PubsubMessage{c,... | go | func (s *Subscriber) Publish(c, msg string) int {
s.mu.Lock()
defer s.mu.Unlock()
found := 0
subs:
for sub := range s.channels {
if sub == c {
s.publish <- PubsubMessage{c, msg}
found++
break subs
}
}
pats:
for _, pat := range s.patterns {
if pat.MatchString(c) {
s.publish <- PubsubMessage{c,... | [
"func",
"(",
"s",
"*",
"Subscriber",
")",
"Publish",
"(",
"c",
",",
"msg",
"string",
")",
"int",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"found",
":=",
"0",
"\n\n",
"subs",
"... | // Publish a message. Will return return how often we sent the message (can be
// a match for a subscription and for a psubscription. | [
"Publish",
"a",
"message",
".",
"Will",
"return",
"return",
"how",
"often",
"we",
"sent",
"the",
"message",
"(",
"can",
"be",
"a",
"match",
"for",
"a",
"subscription",
"and",
"for",
"a",
"psubscription",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/pubsub.go#L119-L144 | train |
alicebob/miniredis | pubsub.go | activeChannels | func activeChannels(subs []*Subscriber, pat string) []string {
channels := map[string]struct{}{}
for _, s := range subs {
for c := range s.channels {
channels[c] = struct{}{}
}
}
var cpat *regexp.Regexp
if pat != "" {
cpat = compileChannelPattern(pat)
}
var cs []string
for k := range channels {
if ... | go | func activeChannels(subs []*Subscriber, pat string) []string {
channels := map[string]struct{}{}
for _, s := range subs {
for c := range s.channels {
channels[c] = struct{}{}
}
}
var cpat *regexp.Regexp
if pat != "" {
cpat = compileChannelPattern(pat)
}
var cs []string
for k := range channels {
if ... | [
"func",
"activeChannels",
"(",
"subs",
"[",
"]",
"*",
"Subscriber",
",",
"pat",
"string",
")",
"[",
"]",
"string",
"{",
"channels",
":=",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"}",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"subs",
... | // List all pubsub channels. If `pat` isn't empty channels names must match the
// pattern. Channels are returned alphabetically. | [
"List",
"all",
"pubsub",
"channels",
".",
"If",
"pat",
"isn",
"t",
"empty",
"channels",
"names",
"must",
"match",
"the",
"pattern",
".",
"Channels",
"are",
"returned",
"alphabetically",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/pubsub.go#L153-L175 | train |
alicebob/miniredis | pubsub.go | countPsubs | func countPsubs(subs []*Subscriber) int {
n := 0
for _, p := range subs {
n += len(p.patterns)
}
return n
} | go | func countPsubs(subs []*Subscriber) int {
n := 0
for _, p := range subs {
n += len(p.patterns)
}
return n
} | [
"func",
"countPsubs",
"(",
"subs",
"[",
"]",
"*",
"Subscriber",
")",
"int",
"{",
"n",
":=",
"0",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"subs",
"{",
"n",
"+=",
"len",
"(",
"p",
".",
"patterns",
")",
"\n",
"}",
"\n",
"return",
"n",
"\n",
"... | // Count the total of all client psubscriptions. | [
"Count",
"the",
"total",
"of",
"all",
"client",
"psubscriptions",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/pubsub.go#L193-L199 | train |
alicebob/miniredis | cmd_scripting.go | requireGlobal | func requireGlobal(l *lua.LState, id, modName string) {
if err := l.CallByParam(lua.P{
Fn: l.GetGlobal("require"),
NRet: 1,
Protect: true,
}, lua.LString(modName)); err != nil {
panic(err)
}
mod := l.Get(-1)
l.Pop(1)
l.SetGlobal(id, mod)
} | go | func requireGlobal(l *lua.LState, id, modName string) {
if err := l.CallByParam(lua.P{
Fn: l.GetGlobal("require"),
NRet: 1,
Protect: true,
}, lua.LString(modName)); err != nil {
panic(err)
}
mod := l.Get(-1)
l.Pop(1)
l.SetGlobal(id, mod)
} | [
"func",
"requireGlobal",
"(",
"l",
"*",
"lua",
".",
"LState",
",",
"id",
",",
"modName",
"string",
")",
"{",
"if",
"err",
":=",
"l",
".",
"CallByParam",
"(",
"lua",
".",
"P",
"{",
"Fn",
":",
"l",
".",
"GetGlobal",
"(",
"\"",
"\"",
")",
",",
"NR... | // requireGlobal imports module modName into the global namespace with the
// identifier id. panics if an error results from the function execution | [
"requireGlobal",
"imports",
"module",
"modName",
"into",
"the",
"global",
"namespace",
"with",
"the",
"identifier",
"id",
".",
"panics",
"if",
"an",
"error",
"results",
"from",
"the",
"function",
"execution"
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/cmd_scripting.go#L218-L230 | train |
alicebob/miniredis | miniredis.go | NewMiniRedis | func NewMiniRedis() *Miniredis {
m := Miniredis{
dbs: map[int]*RedisDB{},
scripts: map[string]string{},
subscribers: map[*Subscriber]struct{}{},
}
m.signal = sync.NewCond(&m)
return &m
} | go | func NewMiniRedis() *Miniredis {
m := Miniredis{
dbs: map[int]*RedisDB{},
scripts: map[string]string{},
subscribers: map[*Subscriber]struct{}{},
}
m.signal = sync.NewCond(&m)
return &m
} | [
"func",
"NewMiniRedis",
"(",
")",
"*",
"Miniredis",
"{",
"m",
":=",
"Miniredis",
"{",
"dbs",
":",
"map",
"[",
"int",
"]",
"*",
"RedisDB",
"{",
"}",
",",
"scripts",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
",",
"subscribers",
":",
"map",
... | // NewMiniRedis makes a new, non-started, Miniredis object. | [
"NewMiniRedis",
"makes",
"a",
"new",
"non",
"-",
"started",
"Miniredis",
"object",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L80-L88 | train |
alicebob/miniredis | miniredis.go | Close | func (m *Miniredis) Close() {
m.Lock()
if m.srv == nil {
m.Unlock()
return
}
srv := m.srv
m.srv = nil
m.Unlock()
// the OnDisconnect callbacks can lock m, so run Close() outside the lock.
srv.Close()
} | go | func (m *Miniredis) Close() {
m.Lock()
if m.srv == nil {
m.Unlock()
return
}
srv := m.srv
m.srv = nil
m.Unlock()
// the OnDisconnect callbacks can lock m, so run Close() outside the lock.
srv.Close()
} | [
"func",
"(",
"m",
"*",
"Miniredis",
")",
"Close",
"(",
")",
"{",
"m",
".",
"Lock",
"(",
")",
"\n\n",
"if",
"m",
".",
"srv",
"==",
"nil",
"{",
"m",
".",
"Unlock",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n",
"srv",
":=",
"m",
".",
"srv",
"\n",... | // Close shuts down a Miniredis. | [
"Close",
"shuts",
"down",
"a",
"Miniredis",
"."
] | 3d7aa1333af56ab862d446678d93aaa6803e0938 | https://github.com/alicebob/miniredis/blob/3d7aa1333af56ab862d446678d93aaa6803e0938/miniredis.go#L159-L173 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.