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
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
jroimartin/gocui
keybinding.go
matchKeypress
func (kb *keybinding) matchKeypress(key Key, ch rune, mod Modifier) bool { return kb.key == key && kb.ch == ch && kb.mod == mod }
go
func (kb *keybinding) matchKeypress(key Key, ch rune, mod Modifier) bool { return kb.key == key && kb.ch == ch && kb.mod == mod }
[ "func", "(", "kb", "*", "keybinding", ")", "matchKeypress", "(", "key", "Key", ",", "ch", "rune", ",", "mod", "Modifier", ")", "bool", "{", "return", "kb", ".", "key", "==", "key", "&&", "kb", ".", "ch", "==", "ch", "&&", "kb", ".", "mod", "==", "mod", "\n", "}" ]
// matchKeypress returns if the keybinding matches the keypress.
[ "matchKeypress", "returns", "if", "the", "keybinding", "matches", "the", "keypress", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/keybinding.go#L31-L33
train
jroimartin/gocui
keybinding.go
matchView
func (kb *keybinding) matchView(v *View) bool { if kb.viewName == "" { return true } return v != nil && kb.viewName == v.name }
go
func (kb *keybinding) matchView(v *View) bool { if kb.viewName == "" { return true } return v != nil && kb.viewName == v.name }
[ "func", "(", "kb", "*", "keybinding", ")", "matchView", "(", "v", "*", "View", ")", "bool", "{", "if", "kb", ".", "viewName", "==", "\"", "\"", "{", "return", "true", "\n", "}", "\n", "return", "v", "!=", "nil", "&&", "kb", ".", "viewName", "==", "v", ".", "name", "\n", "}" ]
// matchView returns if the keybinding matches the current view.
[ "matchView", "returns", "if", "the", "keybinding", "matches", "the", "current", "view", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/keybinding.go#L36-L41
train
jroimartin/gocui
view.go
String
func (l lineType) String() string { str := "" for _, c := range l { str += string(c.chr) } return str }
go
func (l lineType) String() string { str := "" for _, c := range l { str += string(c.chr) } return str }
[ "func", "(", "l", "lineType", ")", "String", "(", ")", "string", "{", "str", ":=", "\"", "\"", "\n", "for", "_", ",", "c", ":=", "range", "l", "{", "str", "+=", "string", "(", "c", ".", "chr", ")", "\n", "}", "\n", "return", "str", "\n", "}" ]
// String returns a string from a given cell slice.
[ "String", "returns", "a", "string", "from", "a", "given", "cell", "slice", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L89-L95
train
jroimartin/gocui
view.go
newView
func newView(name string, x0, y0, x1, y1 int, mode OutputMode) *View { v := &View{ name: name, x0: x0, y0: y0, x1: x1, y1: y1, Frame: true, Editor: DefaultEditor, tainted: true, ei: newEscapeInterpreter(mode), } return v }
go
func newView(name string, x0, y0, x1, y1 int, mode OutputMode) *View { v := &View{ name: name, x0: x0, y0: y0, x1: x1, y1: y1, Frame: true, Editor: DefaultEditor, tainted: true, ei: newEscapeInterpreter(mode), } return v }
[ "func", "newView", "(", "name", "string", ",", "x0", ",", "y0", ",", "x1", ",", "y1", "int", ",", "mode", "OutputMode", ")", "*", "View", "{", "v", ":=", "&", "View", "{", "name", ":", "name", ",", "x0", ":", "x0", ",", "y0", ":", "y0", ",", "x1", ":", "x1", ",", "y1", ":", "y1", ",", "Frame", ":", "true", ",", "Editor", ":", "DefaultEditor", ",", "tainted", ":", "true", ",", "ei", ":", "newEscapeInterpreter", "(", "mode", ")", ",", "}", "\n", "return", "v", "\n", "}" ]
// newView returns a new View object.
[ "newView", "returns", "a", "new", "View", "object", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L98-L111
train
jroimartin/gocui
view.go
Size
func (v *View) Size() (x, y int) { return v.x1 - v.x0 - 1, v.y1 - v.y0 - 1 }
go
func (v *View) Size() (x, y int) { return v.x1 - v.x0 - 1, v.y1 - v.y0 - 1 }
[ "func", "(", "v", "*", "View", ")", "Size", "(", ")", "(", "x", ",", "y", "int", ")", "{", "return", "v", ".", "x1", "-", "v", ".", "x0", "-", "1", ",", "v", ".", "y1", "-", "v", ".", "y0", "-", "1", "\n", "}" ]
// Size returns the number of visible columns and rows in the View.
[ "Size", "returns", "the", "number", "of", "visible", "columns", "and", "rows", "in", "the", "View", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L114-L116
train
jroimartin/gocui
view.go
setRune
func (v *View) setRune(x, y int, ch rune, fgColor, bgColor Attribute) error { maxX, maxY := v.Size() if x < 0 || x >= maxX || y < 0 || y >= maxY { return errors.New("invalid point") } var ( ry, rcy int err error ) if v.Highlight { _, ry, err = v.realPosition(x, y) if err != nil { return err } _, rcy, err = v.realPosition(v.cx, v.cy) if err != nil { return err } } if v.Mask != 0 { fgColor = v.FgColor bgColor = v.BgColor ch = v.Mask } else if v.Highlight && ry == rcy { fgColor = v.SelFgColor bgColor = v.SelBgColor } termbox.SetCell(v.x0+x+1, v.y0+y+1, ch, termbox.Attribute(fgColor), termbox.Attribute(bgColor)) return nil }
go
func (v *View) setRune(x, y int, ch rune, fgColor, bgColor Attribute) error { maxX, maxY := v.Size() if x < 0 || x >= maxX || y < 0 || y >= maxY { return errors.New("invalid point") } var ( ry, rcy int err error ) if v.Highlight { _, ry, err = v.realPosition(x, y) if err != nil { return err } _, rcy, err = v.realPosition(v.cx, v.cy) if err != nil { return err } } if v.Mask != 0 { fgColor = v.FgColor bgColor = v.BgColor ch = v.Mask } else if v.Highlight && ry == rcy { fgColor = v.SelFgColor bgColor = v.SelBgColor } termbox.SetCell(v.x0+x+1, v.y0+y+1, ch, termbox.Attribute(fgColor), termbox.Attribute(bgColor)) return nil }
[ "func", "(", "v", "*", "View", ")", "setRune", "(", "x", ",", "y", "int", ",", "ch", "rune", ",", "fgColor", ",", "bgColor", "Attribute", ")", "error", "{", "maxX", ",", "maxY", ":=", "v", ".", "Size", "(", ")", "\n", "if", "x", "<", "0", "||", "x", ">=", "maxX", "||", "y", "<", "0", "||", "y", ">=", "maxY", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "var", "(", "ry", ",", "rcy", "int", "\n", "err", "error", "\n", ")", "\n", "if", "v", ".", "Highlight", "{", "_", ",", "ry", ",", "err", "=", "v", ".", "realPosition", "(", "x", ",", "y", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "_", ",", "rcy", ",", "err", "=", "v", ".", "realPosition", "(", "v", ".", "cx", ",", "v", ".", "cy", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "if", "v", ".", "Mask", "!=", "0", "{", "fgColor", "=", "v", ".", "FgColor", "\n", "bgColor", "=", "v", ".", "BgColor", "\n", "ch", "=", "v", ".", "Mask", "\n", "}", "else", "if", "v", ".", "Highlight", "&&", "ry", "==", "rcy", "{", "fgColor", "=", "v", ".", "SelFgColor", "\n", "bgColor", "=", "v", ".", "SelBgColor", "\n", "}", "\n\n", "termbox", ".", "SetCell", "(", "v", ".", "x0", "+", "x", "+", "1", ",", "v", ".", "y0", "+", "y", "+", "1", ",", "ch", ",", "termbox", ".", "Attribute", "(", "fgColor", ")", ",", "termbox", ".", "Attribute", "(", "bgColor", ")", ")", "\n\n", "return", "nil", "\n", "}" ]
// setRune sets a rune at the given point relative to the view. It applies the // specified colors, taking into account if the cell must be highlighted. Also, // it checks if the position is valid.
[ "setRune", "sets", "a", "rune", "at", "the", "given", "point", "relative", "to", "the", "view", ".", "It", "applies", "the", "specified", "colors", "taking", "into", "account", "if", "the", "cell", "must", "be", "highlighted", ".", "Also", "it", "checks", "if", "the", "position", "is", "valid", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L126-L160
train
jroimartin/gocui
view.go
SetCursor
func (v *View) SetCursor(x, y int) error { maxX, maxY := v.Size() if x < 0 || x >= maxX || y < 0 || y >= maxY { return errors.New("invalid point") } v.cx = x v.cy = y return nil }
go
func (v *View) SetCursor(x, y int) error { maxX, maxY := v.Size() if x < 0 || x >= maxX || y < 0 || y >= maxY { return errors.New("invalid point") } v.cx = x v.cy = y return nil }
[ "func", "(", "v", "*", "View", ")", "SetCursor", "(", "x", ",", "y", "int", ")", "error", "{", "maxX", ",", "maxY", ":=", "v", ".", "Size", "(", ")", "\n", "if", "x", "<", "0", "||", "x", ">=", "maxX", "||", "y", "<", "0", "||", "y", ">=", "maxY", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "v", ".", "cx", "=", "x", "\n", "v", ".", "cy", "=", "y", "\n", "return", "nil", "\n", "}" ]
// SetCursor sets the cursor position of the view at the given point, // relative to the view. It checks if the position is valid.
[ "SetCursor", "sets", "the", "cursor", "position", "of", "the", "view", "at", "the", "given", "point", "relative", "to", "the", "view", ".", "It", "checks", "if", "the", "position", "is", "valid", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L164-L172
train
jroimartin/gocui
view.go
Cursor
func (v *View) Cursor() (x, y int) { return v.cx, v.cy }
go
func (v *View) Cursor() (x, y int) { return v.cx, v.cy }
[ "func", "(", "v", "*", "View", ")", "Cursor", "(", ")", "(", "x", ",", "y", "int", ")", "{", "return", "v", ".", "cx", ",", "v", ".", "cy", "\n", "}" ]
// Cursor returns the cursor position of the view.
[ "Cursor", "returns", "the", "cursor", "position", "of", "the", "view", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L175-L177
train
jroimartin/gocui
view.go
SetOrigin
func (v *View) SetOrigin(x, y int) error { if x < 0 || y < 0 { return errors.New("invalid point") } v.ox = x v.oy = y return nil }
go
func (v *View) SetOrigin(x, y int) error { if x < 0 || y < 0 { return errors.New("invalid point") } v.ox = x v.oy = y return nil }
[ "func", "(", "v", "*", "View", ")", "SetOrigin", "(", "x", ",", "y", "int", ")", "error", "{", "if", "x", "<", "0", "||", "y", "<", "0", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "v", ".", "ox", "=", "x", "\n", "v", ".", "oy", "=", "y", "\n", "return", "nil", "\n", "}" ]
// SetOrigin sets the origin position of the view's internal buffer, // so the buffer starts to be printed from this point, which means that // it is linked with the origin point of view. It can be used to // implement Horizontal and Vertical scrolling with just incrementing // or decrementing ox and oy.
[ "SetOrigin", "sets", "the", "origin", "position", "of", "the", "view", "s", "internal", "buffer", "so", "the", "buffer", "starts", "to", "be", "printed", "from", "this", "point", "which", "means", "that", "it", "is", "linked", "with", "the", "origin", "point", "of", "view", ".", "It", "can", "be", "used", "to", "implement", "Horizontal", "and", "Vertical", "scrolling", "with", "just", "incrementing", "or", "decrementing", "ox", "and", "oy", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L184-L191
train
jroimartin/gocui
view.go
Origin
func (v *View) Origin() (x, y int) { return v.ox, v.oy }
go
func (v *View) Origin() (x, y int) { return v.ox, v.oy }
[ "func", "(", "v", "*", "View", ")", "Origin", "(", ")", "(", "x", ",", "y", "int", ")", "{", "return", "v", ".", "ox", ",", "v", ".", "oy", "\n", "}" ]
// Origin returns the origin position of the view.
[ "Origin", "returns", "the", "origin", "position", "of", "the", "view", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L194-L196
train
jroimartin/gocui
view.go
Write
func (v *View) Write(p []byte) (n int, err error) { v.tainted = true for _, ch := range bytes.Runes(p) { switch ch { case '\n': v.lines = append(v.lines, nil) case '\r': nl := len(v.lines) if nl > 0 { v.lines[nl-1] = nil } else { v.lines = make([][]cell, 1) } default: cells := v.parseInput(ch) if cells == nil { continue } nl := len(v.lines) if nl > 0 { v.lines[nl-1] = append(v.lines[nl-1], cells...) } else { v.lines = append(v.lines, cells) } } } return len(p), nil }
go
func (v *View) Write(p []byte) (n int, err error) { v.tainted = true for _, ch := range bytes.Runes(p) { switch ch { case '\n': v.lines = append(v.lines, nil) case '\r': nl := len(v.lines) if nl > 0 { v.lines[nl-1] = nil } else { v.lines = make([][]cell, 1) } default: cells := v.parseInput(ch) if cells == nil { continue } nl := len(v.lines) if nl > 0 { v.lines[nl-1] = append(v.lines[nl-1], cells...) } else { v.lines = append(v.lines, cells) } } } return len(p), nil }
[ "func", "(", "v", "*", "View", ")", "Write", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "v", ".", "tainted", "=", "true", "\n\n", "for", "_", ",", "ch", ":=", "range", "bytes", ".", "Runes", "(", "p", ")", "{", "switch", "ch", "{", "case", "'\\n'", ":", "v", ".", "lines", "=", "append", "(", "v", ".", "lines", ",", "nil", ")", "\n", "case", "'\\r'", ":", "nl", ":=", "len", "(", "v", ".", "lines", ")", "\n", "if", "nl", ">", "0", "{", "v", ".", "lines", "[", "nl", "-", "1", "]", "=", "nil", "\n", "}", "else", "{", "v", ".", "lines", "=", "make", "(", "[", "]", "[", "]", "cell", ",", "1", ")", "\n", "}", "\n", "default", ":", "cells", ":=", "v", ".", "parseInput", "(", "ch", ")", "\n", "if", "cells", "==", "nil", "{", "continue", "\n", "}", "\n\n", "nl", ":=", "len", "(", "v", ".", "lines", ")", "\n", "if", "nl", ">", "0", "{", "v", ".", "lines", "[", "nl", "-", "1", "]", "=", "append", "(", "v", ".", "lines", "[", "nl", "-", "1", "]", ",", "cells", "...", ")", "\n", "}", "else", "{", "v", ".", "lines", "=", "append", "(", "v", ".", "lines", ",", "cells", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "len", "(", "p", ")", ",", "nil", "\n", "}" ]
// Write appends a byte slice into the view's internal buffer. Because // View implements the io.Writer interface, it can be passed as parameter // of functions like fmt.Fprintf, fmt.Fprintln, io.Copy, etc. Clear must // be called to clear the view's buffer.
[ "Write", "appends", "a", "byte", "slice", "into", "the", "view", "s", "internal", "buffer", ".", "Because", "View", "implements", "the", "io", ".", "Writer", "interface", "it", "can", "be", "passed", "as", "parameter", "of", "functions", "like", "fmt", ".", "Fprintf", "fmt", ".", "Fprintln", "io", ".", "Copy", "etc", ".", "Clear", "must", "be", "called", "to", "clear", "the", "view", "s", "buffer", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L202-L231
train
jroimartin/gocui
view.go
parseInput
func (v *View) parseInput(ch rune) []cell { cells := []cell{} isEscape, err := v.ei.parseOne(ch) if err != nil { for _, r := range v.ei.runes() { c := cell{ fgColor: v.FgColor, bgColor: v.BgColor, chr: r, } cells = append(cells, c) } v.ei.reset() } else { if isEscape { return nil } c := cell{ fgColor: v.ei.curFgColor, bgColor: v.ei.curBgColor, chr: ch, } cells = append(cells, c) } return cells }
go
func (v *View) parseInput(ch rune) []cell { cells := []cell{} isEscape, err := v.ei.parseOne(ch) if err != nil { for _, r := range v.ei.runes() { c := cell{ fgColor: v.FgColor, bgColor: v.BgColor, chr: r, } cells = append(cells, c) } v.ei.reset() } else { if isEscape { return nil } c := cell{ fgColor: v.ei.curFgColor, bgColor: v.ei.curBgColor, chr: ch, } cells = append(cells, c) } return cells }
[ "func", "(", "v", "*", "View", ")", "parseInput", "(", "ch", "rune", ")", "[", "]", "cell", "{", "cells", ":=", "[", "]", "cell", "{", "}", "\n\n", "isEscape", ",", "err", ":=", "v", ".", "ei", ".", "parseOne", "(", "ch", ")", "\n", "if", "err", "!=", "nil", "{", "for", "_", ",", "r", ":=", "range", "v", ".", "ei", ".", "runes", "(", ")", "{", "c", ":=", "cell", "{", "fgColor", ":", "v", ".", "FgColor", ",", "bgColor", ":", "v", ".", "BgColor", ",", "chr", ":", "r", ",", "}", "\n", "cells", "=", "append", "(", "cells", ",", "c", ")", "\n", "}", "\n", "v", ".", "ei", ".", "reset", "(", ")", "\n", "}", "else", "{", "if", "isEscape", "{", "return", "nil", "\n", "}", "\n", "c", ":=", "cell", "{", "fgColor", ":", "v", ".", "ei", ".", "curFgColor", ",", "bgColor", ":", "v", ".", "ei", ".", "curBgColor", ",", "chr", ":", "ch", ",", "}", "\n", "cells", "=", "append", "(", "cells", ",", "c", ")", "\n", "}", "\n\n", "return", "cells", "\n", "}" ]
// parseInput parses char by char the input written to the View. It returns nil // while processing ESC sequences. Otherwise, it returns a cell slice that // contains the processed data.
[ "parseInput", "parses", "char", "by", "char", "the", "input", "written", "to", "the", "View", ".", "It", "returns", "nil", "while", "processing", "ESC", "sequences", ".", "Otherwise", "it", "returns", "a", "cell", "slice", "that", "contains", "the", "processed", "data", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L236-L263
train
jroimartin/gocui
view.go
draw
func (v *View) draw() error { maxX, maxY := v.Size() if v.Wrap { if maxX == 0 { return errors.New("X size of the view cannot be 0") } v.ox = 0 } if v.tainted { v.viewLines = nil for i, line := range v.lines { if v.Wrap { if len(line) < maxX { vline := viewLine{linesX: 0, linesY: i, line: line} v.viewLines = append(v.viewLines, vline) continue } else { for n := 0; n <= len(line); n += maxX { if len(line[n:]) <= maxX { vline := viewLine{linesX: n, linesY: i, line: line[n:]} v.viewLines = append(v.viewLines, vline) } else { vline := viewLine{linesX: n, linesY: i, line: line[n : n+maxX]} v.viewLines = append(v.viewLines, vline) } } } } else { vline := viewLine{linesX: 0, linesY: i, line: line} v.viewLines = append(v.viewLines, vline) } } v.tainted = false } if v.Autoscroll && len(v.viewLines) > maxY { v.oy = len(v.viewLines) - maxY } y := 0 for i, vline := range v.viewLines { if i < v.oy { continue } if y >= maxY { break } x := 0 for j, c := range vline.line { if j < v.ox { continue } if x >= maxX { break } fgColor := c.fgColor if fgColor == ColorDefault { fgColor = v.FgColor } bgColor := c.bgColor if bgColor == ColorDefault { bgColor = v.BgColor } if err := v.setRune(x, y, c.chr, fgColor, bgColor); err != nil { return err } x++ } y++ } return nil }
go
func (v *View) draw() error { maxX, maxY := v.Size() if v.Wrap { if maxX == 0 { return errors.New("X size of the view cannot be 0") } v.ox = 0 } if v.tainted { v.viewLines = nil for i, line := range v.lines { if v.Wrap { if len(line) < maxX { vline := viewLine{linesX: 0, linesY: i, line: line} v.viewLines = append(v.viewLines, vline) continue } else { for n := 0; n <= len(line); n += maxX { if len(line[n:]) <= maxX { vline := viewLine{linesX: n, linesY: i, line: line[n:]} v.viewLines = append(v.viewLines, vline) } else { vline := viewLine{linesX: n, linesY: i, line: line[n : n+maxX]} v.viewLines = append(v.viewLines, vline) } } } } else { vline := viewLine{linesX: 0, linesY: i, line: line} v.viewLines = append(v.viewLines, vline) } } v.tainted = false } if v.Autoscroll && len(v.viewLines) > maxY { v.oy = len(v.viewLines) - maxY } y := 0 for i, vline := range v.viewLines { if i < v.oy { continue } if y >= maxY { break } x := 0 for j, c := range vline.line { if j < v.ox { continue } if x >= maxX { break } fgColor := c.fgColor if fgColor == ColorDefault { fgColor = v.FgColor } bgColor := c.bgColor if bgColor == ColorDefault { bgColor = v.BgColor } if err := v.setRune(x, y, c.chr, fgColor, bgColor); err != nil { return err } x++ } y++ } return nil }
[ "func", "(", "v", "*", "View", ")", "draw", "(", ")", "error", "{", "maxX", ",", "maxY", ":=", "v", ".", "Size", "(", ")", "\n\n", "if", "v", ".", "Wrap", "{", "if", "maxX", "==", "0", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "v", ".", "ox", "=", "0", "\n", "}", "\n", "if", "v", ".", "tainted", "{", "v", ".", "viewLines", "=", "nil", "\n", "for", "i", ",", "line", ":=", "range", "v", ".", "lines", "{", "if", "v", ".", "Wrap", "{", "if", "len", "(", "line", ")", "<", "maxX", "{", "vline", ":=", "viewLine", "{", "linesX", ":", "0", ",", "linesY", ":", "i", ",", "line", ":", "line", "}", "\n", "v", ".", "viewLines", "=", "append", "(", "v", ".", "viewLines", ",", "vline", ")", "\n", "continue", "\n", "}", "else", "{", "for", "n", ":=", "0", ";", "n", "<=", "len", "(", "line", ")", ";", "n", "+=", "maxX", "{", "if", "len", "(", "line", "[", "n", ":", "]", ")", "<=", "maxX", "{", "vline", ":=", "viewLine", "{", "linesX", ":", "n", ",", "linesY", ":", "i", ",", "line", ":", "line", "[", "n", ":", "]", "}", "\n", "v", ".", "viewLines", "=", "append", "(", "v", ".", "viewLines", ",", "vline", ")", "\n", "}", "else", "{", "vline", ":=", "viewLine", "{", "linesX", ":", "n", ",", "linesY", ":", "i", ",", "line", ":", "line", "[", "n", ":", "n", "+", "maxX", "]", "}", "\n", "v", ".", "viewLines", "=", "append", "(", "v", ".", "viewLines", ",", "vline", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "else", "{", "vline", ":=", "viewLine", "{", "linesX", ":", "0", ",", "linesY", ":", "i", ",", "line", ":", "line", "}", "\n", "v", ".", "viewLines", "=", "append", "(", "v", ".", "viewLines", ",", "vline", ")", "\n", "}", "\n", "}", "\n", "v", ".", "tainted", "=", "false", "\n", "}", "\n\n", "if", "v", ".", "Autoscroll", "&&", "len", "(", "v", ".", "viewLines", ")", ">", "maxY", "{", "v", ".", "oy", "=", "len", "(", "v", ".", "viewLines", ")", "-", "maxY", "\n", "}", "\n", "y", ":=", "0", "\n", "for", "i", ",", "vline", ":=", "range", "v", ".", "viewLines", "{", "if", "i", "<", "v", ".", "oy", "{", "continue", "\n", "}", "\n", "if", "y", ">=", "maxY", "{", "break", "\n", "}", "\n", "x", ":=", "0", "\n", "for", "j", ",", "c", ":=", "range", "vline", ".", "line", "{", "if", "j", "<", "v", ".", "ox", "{", "continue", "\n", "}", "\n", "if", "x", ">=", "maxX", "{", "break", "\n", "}", "\n\n", "fgColor", ":=", "c", ".", "fgColor", "\n", "if", "fgColor", "==", "ColorDefault", "{", "fgColor", "=", "v", ".", "FgColor", "\n", "}", "\n", "bgColor", ":=", "c", ".", "bgColor", "\n", "if", "bgColor", "==", "ColorDefault", "{", "bgColor", "=", "v", ".", "BgColor", "\n", "}", "\n\n", "if", "err", ":=", "v", ".", "setRune", "(", "x", ",", "y", ",", "c", ".", "chr", ",", "fgColor", ",", "bgColor", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "x", "++", "\n", "}", "\n", "y", "++", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// draw re-draws the view's contents.
[ "draw", "re", "-", "draws", "the", "view", "s", "contents", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L288-L361
train
jroimartin/gocui
view.go
Clear
func (v *View) Clear() { v.tainted = true v.lines = nil v.viewLines = nil v.readOffset = 0 v.clearRunes() }
go
func (v *View) Clear() { v.tainted = true v.lines = nil v.viewLines = nil v.readOffset = 0 v.clearRunes() }
[ "func", "(", "v", "*", "View", ")", "Clear", "(", ")", "{", "v", ".", "tainted", "=", "true", "\n\n", "v", ".", "lines", "=", "nil", "\n", "v", ".", "viewLines", "=", "nil", "\n", "v", ".", "readOffset", "=", "0", "\n", "v", ".", "clearRunes", "(", ")", "\n", "}" ]
// Clear empties the view's internal buffer.
[ "Clear", "empties", "the", "view", "s", "internal", "buffer", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L391-L398
train
jroimartin/gocui
view.go
clearRunes
func (v *View) clearRunes() { maxX, maxY := v.Size() for x := 0; x < maxX; x++ { for y := 0; y < maxY; y++ { termbox.SetCell(v.x0+x+1, v.y0+y+1, ' ', termbox.Attribute(v.FgColor), termbox.Attribute(v.BgColor)) } } }
go
func (v *View) clearRunes() { maxX, maxY := v.Size() for x := 0; x < maxX; x++ { for y := 0; y < maxY; y++ { termbox.SetCell(v.x0+x+1, v.y0+y+1, ' ', termbox.Attribute(v.FgColor), termbox.Attribute(v.BgColor)) } } }
[ "func", "(", "v", "*", "View", ")", "clearRunes", "(", ")", "{", "maxX", ",", "maxY", ":=", "v", ".", "Size", "(", ")", "\n", "for", "x", ":=", "0", ";", "x", "<", "maxX", ";", "x", "++", "{", "for", "y", ":=", "0", ";", "y", "<", "maxY", ";", "y", "++", "{", "termbox", ".", "SetCell", "(", "v", ".", "x0", "+", "x", "+", "1", ",", "v", ".", "y0", "+", "y", "+", "1", ",", "' '", ",", "termbox", ".", "Attribute", "(", "v", ".", "FgColor", ")", ",", "termbox", ".", "Attribute", "(", "v", ".", "BgColor", ")", ")", "\n", "}", "\n", "}", "\n", "}" ]
// clearRunes erases all the cells in the view.
[ "clearRunes", "erases", "all", "the", "cells", "in", "the", "view", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L401-L409
train
jroimartin/gocui
view.go
BufferLines
func (v *View) BufferLines() []string { lines := make([]string, len(v.lines)) for i, l := range v.lines { str := lineType(l).String() str = strings.Replace(str, "\x00", " ", -1) lines[i] = str } return lines }
go
func (v *View) BufferLines() []string { lines := make([]string, len(v.lines)) for i, l := range v.lines { str := lineType(l).String() str = strings.Replace(str, "\x00", " ", -1) lines[i] = str } return lines }
[ "func", "(", "v", "*", "View", ")", "BufferLines", "(", ")", "[", "]", "string", "{", "lines", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "v", ".", "lines", ")", ")", "\n", "for", "i", ",", "l", ":=", "range", "v", ".", "lines", "{", "str", ":=", "lineType", "(", "l", ")", ".", "String", "(", ")", "\n", "str", "=", "strings", ".", "Replace", "(", "str", ",", "\"", "\\x00", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "lines", "[", "i", "]", "=", "str", "\n", "}", "\n", "return", "lines", "\n", "}" ]
// BufferLines returns the lines in the view's internal // buffer.
[ "BufferLines", "returns", "the", "lines", "in", "the", "view", "s", "internal", "buffer", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L413-L421
train
jroimartin/gocui
view.go
Buffer
func (v *View) Buffer() string { str := "" for _, l := range v.lines { str += lineType(l).String() + "\n" } return strings.Replace(str, "\x00", " ", -1) }
go
func (v *View) Buffer() string { str := "" for _, l := range v.lines { str += lineType(l).String() + "\n" } return strings.Replace(str, "\x00", " ", -1) }
[ "func", "(", "v", "*", "View", ")", "Buffer", "(", ")", "string", "{", "str", ":=", "\"", "\"", "\n", "for", "_", ",", "l", ":=", "range", "v", ".", "lines", "{", "str", "+=", "lineType", "(", "l", ")", ".", "String", "(", ")", "+", "\"", "\\n", "\"", "\n", "}", "\n", "return", "strings", ".", "Replace", "(", "str", ",", "\"", "\\x00", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "}" ]
// Buffer returns a string with the contents of the view's internal // buffer.
[ "Buffer", "returns", "a", "string", "with", "the", "contents", "of", "the", "view", "s", "internal", "buffer", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L425-L431
train
jroimartin/gocui
view.go
ViewBufferLines
func (v *View) ViewBufferLines() []string { lines := make([]string, len(v.viewLines)) for i, l := range v.viewLines { str := lineType(l.line).String() str = strings.Replace(str, "\x00", " ", -1) lines[i] = str } return lines }
go
func (v *View) ViewBufferLines() []string { lines := make([]string, len(v.viewLines)) for i, l := range v.viewLines { str := lineType(l.line).String() str = strings.Replace(str, "\x00", " ", -1) lines[i] = str } return lines }
[ "func", "(", "v", "*", "View", ")", "ViewBufferLines", "(", ")", "[", "]", "string", "{", "lines", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "v", ".", "viewLines", ")", ")", "\n", "for", "i", ",", "l", ":=", "range", "v", ".", "viewLines", "{", "str", ":=", "lineType", "(", "l", ".", "line", ")", ".", "String", "(", ")", "\n", "str", "=", "strings", ".", "Replace", "(", "str", ",", "\"", "\\x00", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "lines", "[", "i", "]", "=", "str", "\n", "}", "\n", "return", "lines", "\n", "}" ]
// ViewBufferLines returns the lines in the view's internal // buffer that is shown to the user.
[ "ViewBufferLines", "returns", "the", "lines", "in", "the", "view", "s", "internal", "buffer", "that", "is", "shown", "to", "the", "user", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L435-L443
train
jroimartin/gocui
view.go
ViewBuffer
func (v *View) ViewBuffer() string { str := "" for _, l := range v.viewLines { str += lineType(l.line).String() + "\n" } return strings.Replace(str, "\x00", " ", -1) }
go
func (v *View) ViewBuffer() string { str := "" for _, l := range v.viewLines { str += lineType(l.line).String() + "\n" } return strings.Replace(str, "\x00", " ", -1) }
[ "func", "(", "v", "*", "View", ")", "ViewBuffer", "(", ")", "string", "{", "str", ":=", "\"", "\"", "\n", "for", "_", ",", "l", ":=", "range", "v", ".", "viewLines", "{", "str", "+=", "lineType", "(", "l", ".", "line", ")", ".", "String", "(", ")", "+", "\"", "\\n", "\"", "\n", "}", "\n", "return", "strings", ".", "Replace", "(", "str", ",", "\"", "\\x00", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "}" ]
// ViewBuffer returns a string with the contents of the view's buffer that is // shown to the user.
[ "ViewBuffer", "returns", "a", "string", "with", "the", "contents", "of", "the", "view", "s", "buffer", "that", "is", "shown", "to", "the", "user", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L447-L453
train
jroimartin/gocui
escape.go
runes
func (ei *escapeInterpreter) runes() []rune { switch ei.state { case stateNone: return []rune{0x1b} case stateEscape: return []rune{0x1b, ei.curch} case stateCSI: return []rune{0x1b, '[', ei.curch} case stateParams: ret := []rune{0x1b, '['} for _, s := range ei.csiParam { ret = append(ret, []rune(s)...) ret = append(ret, ';') } return append(ret, ei.curch) } return nil }
go
func (ei *escapeInterpreter) runes() []rune { switch ei.state { case stateNone: return []rune{0x1b} case stateEscape: return []rune{0x1b, ei.curch} case stateCSI: return []rune{0x1b, '[', ei.curch} case stateParams: ret := []rune{0x1b, '['} for _, s := range ei.csiParam { ret = append(ret, []rune(s)...) ret = append(ret, ';') } return append(ret, ei.curch) } return nil }
[ "func", "(", "ei", "*", "escapeInterpreter", ")", "runes", "(", ")", "[", "]", "rune", "{", "switch", "ei", ".", "state", "{", "case", "stateNone", ":", "return", "[", "]", "rune", "{", "0x1b", "}", "\n", "case", "stateEscape", ":", "return", "[", "]", "rune", "{", "0x1b", ",", "ei", ".", "curch", "}", "\n", "case", "stateCSI", ":", "return", "[", "]", "rune", "{", "0x1b", ",", "'['", ",", "ei", ".", "curch", "}", "\n", "case", "stateParams", ":", "ret", ":=", "[", "]", "rune", "{", "0x1b", ",", "'['", "}", "\n", "for", "_", ",", "s", ":=", "range", "ei", ".", "csiParam", "{", "ret", "=", "append", "(", "ret", ",", "[", "]", "rune", "(", "s", ")", "...", ")", "\n", "ret", "=", "append", "(", "ret", ",", "';'", ")", "\n", "}", "\n", "return", "append", "(", "ret", ",", "ei", ".", "curch", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// runes in case of error will output the non-parsed runes as a string.
[ "runes", "in", "case", "of", "error", "will", "output", "the", "non", "-", "parsed", "runes", "as", "a", "string", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/escape.go#L36-L53
train
jroimartin/gocui
escape.go
newEscapeInterpreter
func newEscapeInterpreter(mode OutputMode) *escapeInterpreter { ei := &escapeInterpreter{ state: stateNone, curFgColor: ColorDefault, curBgColor: ColorDefault, mode: mode, } return ei }
go
func newEscapeInterpreter(mode OutputMode) *escapeInterpreter { ei := &escapeInterpreter{ state: stateNone, curFgColor: ColorDefault, curBgColor: ColorDefault, mode: mode, } return ei }
[ "func", "newEscapeInterpreter", "(", "mode", "OutputMode", ")", "*", "escapeInterpreter", "{", "ei", ":=", "&", "escapeInterpreter", "{", "state", ":", "stateNone", ",", "curFgColor", ":", "ColorDefault", ",", "curBgColor", ":", "ColorDefault", ",", "mode", ":", "mode", ",", "}", "\n", "return", "ei", "\n", "}" ]
// newEscapeInterpreter returns an escapeInterpreter that will be able to parse // terminal escape sequences.
[ "newEscapeInterpreter", "returns", "an", "escapeInterpreter", "that", "will", "be", "able", "to", "parse", "terminal", "escape", "sequences", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/escape.go#L57-L65
train
jroimartin/gocui
escape.go
reset
func (ei *escapeInterpreter) reset() { ei.state = stateNone ei.curFgColor = ColorDefault ei.curBgColor = ColorDefault ei.csiParam = nil }
go
func (ei *escapeInterpreter) reset() { ei.state = stateNone ei.curFgColor = ColorDefault ei.curBgColor = ColorDefault ei.csiParam = nil }
[ "func", "(", "ei", "*", "escapeInterpreter", ")", "reset", "(", ")", "{", "ei", ".", "state", "=", "stateNone", "\n", "ei", ".", "curFgColor", "=", "ColorDefault", "\n", "ei", ".", "curBgColor", "=", "ColorDefault", "\n", "ei", ".", "csiParam", "=", "nil", "\n", "}" ]
// reset sets the escapeInterpreter in initial state.
[ "reset", "sets", "the", "escapeInterpreter", "in", "initial", "state", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/escape.go#L68-L73
train
jroimartin/gocui
escape.go
parseOne
func (ei *escapeInterpreter) parseOne(ch rune) (isEscape bool, err error) { // Sanity checks if len(ei.csiParam) > 20 { return false, errCSITooLong } if len(ei.csiParam) > 0 && len(ei.csiParam[len(ei.csiParam)-1]) > 255 { return false, errCSITooLong } ei.curch = ch switch ei.state { case stateNone: if ch == 0x1b { ei.state = stateEscape return true, nil } return false, nil case stateEscape: if ch == '[' { ei.state = stateCSI return true, nil } return false, errNotCSI case stateCSI: switch { case ch >= '0' && ch <= '9': ei.csiParam = append(ei.csiParam, "") case ch == 'm': ei.csiParam = append(ei.csiParam, "0") default: return false, errCSIParseError } ei.state = stateParams fallthrough case stateParams: switch { case ch >= '0' && ch <= '9': ei.csiParam[len(ei.csiParam)-1] += string(ch) return true, nil case ch == ';': ei.csiParam = append(ei.csiParam, "") return true, nil case ch == 'm': var err error switch ei.mode { case OutputNormal: err = ei.outputNormal() case Output256: err = ei.output256() } if err != nil { return false, errCSIParseError } ei.state = stateNone ei.csiParam = nil return true, nil default: return false, errCSIParseError } } return false, nil }
go
func (ei *escapeInterpreter) parseOne(ch rune) (isEscape bool, err error) { // Sanity checks if len(ei.csiParam) > 20 { return false, errCSITooLong } if len(ei.csiParam) > 0 && len(ei.csiParam[len(ei.csiParam)-1]) > 255 { return false, errCSITooLong } ei.curch = ch switch ei.state { case stateNone: if ch == 0x1b { ei.state = stateEscape return true, nil } return false, nil case stateEscape: if ch == '[' { ei.state = stateCSI return true, nil } return false, errNotCSI case stateCSI: switch { case ch >= '0' && ch <= '9': ei.csiParam = append(ei.csiParam, "") case ch == 'm': ei.csiParam = append(ei.csiParam, "0") default: return false, errCSIParseError } ei.state = stateParams fallthrough case stateParams: switch { case ch >= '0' && ch <= '9': ei.csiParam[len(ei.csiParam)-1] += string(ch) return true, nil case ch == ';': ei.csiParam = append(ei.csiParam, "") return true, nil case ch == 'm': var err error switch ei.mode { case OutputNormal: err = ei.outputNormal() case Output256: err = ei.output256() } if err != nil { return false, errCSIParseError } ei.state = stateNone ei.csiParam = nil return true, nil default: return false, errCSIParseError } } return false, nil }
[ "func", "(", "ei", "*", "escapeInterpreter", ")", "parseOne", "(", "ch", "rune", ")", "(", "isEscape", "bool", ",", "err", "error", ")", "{", "// Sanity checks", "if", "len", "(", "ei", ".", "csiParam", ")", ">", "20", "{", "return", "false", ",", "errCSITooLong", "\n", "}", "\n", "if", "len", "(", "ei", ".", "csiParam", ")", ">", "0", "&&", "len", "(", "ei", ".", "csiParam", "[", "len", "(", "ei", ".", "csiParam", ")", "-", "1", "]", ")", ">", "255", "{", "return", "false", ",", "errCSITooLong", "\n", "}", "\n\n", "ei", ".", "curch", "=", "ch", "\n\n", "switch", "ei", ".", "state", "{", "case", "stateNone", ":", "if", "ch", "==", "0x1b", "{", "ei", ".", "state", "=", "stateEscape", "\n", "return", "true", ",", "nil", "\n", "}", "\n", "return", "false", ",", "nil", "\n", "case", "stateEscape", ":", "if", "ch", "==", "'['", "{", "ei", ".", "state", "=", "stateCSI", "\n", "return", "true", ",", "nil", "\n", "}", "\n", "return", "false", ",", "errNotCSI", "\n", "case", "stateCSI", ":", "switch", "{", "case", "ch", ">=", "'0'", "&&", "ch", "<=", "'9'", ":", "ei", ".", "csiParam", "=", "append", "(", "ei", ".", "csiParam", ",", "\"", "\"", ")", "\n", "case", "ch", "==", "'m'", ":", "ei", ".", "csiParam", "=", "append", "(", "ei", ".", "csiParam", ",", "\"", "\"", ")", "\n", "default", ":", "return", "false", ",", "errCSIParseError", "\n", "}", "\n", "ei", ".", "state", "=", "stateParams", "\n", "fallthrough", "\n", "case", "stateParams", ":", "switch", "{", "case", "ch", ">=", "'0'", "&&", "ch", "<=", "'9'", ":", "ei", ".", "csiParam", "[", "len", "(", "ei", ".", "csiParam", ")", "-", "1", "]", "+=", "string", "(", "ch", ")", "\n", "return", "true", ",", "nil", "\n", "case", "ch", "==", "';'", ":", "ei", ".", "csiParam", "=", "append", "(", "ei", ".", "csiParam", ",", "\"", "\"", ")", "\n", "return", "true", ",", "nil", "\n", "case", "ch", "==", "'m'", ":", "var", "err", "error", "\n", "switch", "ei", ".", "mode", "{", "case", "OutputNormal", ":", "err", "=", "ei", ".", "outputNormal", "(", ")", "\n", "case", "Output256", ":", "err", "=", "ei", ".", "output256", "(", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "errCSIParseError", "\n", "}", "\n\n", "ei", ".", "state", "=", "stateNone", "\n", "ei", ".", "csiParam", "=", "nil", "\n", "return", "true", ",", "nil", "\n", "default", ":", "return", "false", ",", "errCSIParseError", "\n", "}", "\n", "}", "\n", "return", "false", ",", "nil", "\n", "}" ]
// parseOne parses a rune. If isEscape is true, it means that the rune is part // of an escape sequence, and as such should not be printed verbatim. Otherwise, // it's not an escape sequence.
[ "parseOne", "parses", "a", "rune", ".", "If", "isEscape", "is", "true", "it", "means", "that", "the", "rune", "is", "part", "of", "an", "escape", "sequence", "and", "as", "such", "should", "not", "be", "printed", "verbatim", ".", "Otherwise", "it", "s", "not", "an", "escape", "sequence", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/escape.go#L78-L141
train
jroimartin/gocui
gui.go
NewGui
func NewGui(mode OutputMode) (*Gui, error) { if err := termbox.Init(); err != nil { return nil, err } g := &Gui{} g.outputMode = mode termbox.SetOutputMode(termbox.OutputMode(mode)) g.tbEvents = make(chan termbox.Event, 20) g.userEvents = make(chan userEvent, 20) g.maxX, g.maxY = termbox.Size() g.BgColor, g.FgColor = ColorDefault, ColorDefault g.SelBgColor, g.SelFgColor = ColorDefault, ColorDefault return g, nil }
go
func NewGui(mode OutputMode) (*Gui, error) { if err := termbox.Init(); err != nil { return nil, err } g := &Gui{} g.outputMode = mode termbox.SetOutputMode(termbox.OutputMode(mode)) g.tbEvents = make(chan termbox.Event, 20) g.userEvents = make(chan userEvent, 20) g.maxX, g.maxY = termbox.Size() g.BgColor, g.FgColor = ColorDefault, ColorDefault g.SelBgColor, g.SelFgColor = ColorDefault, ColorDefault return g, nil }
[ "func", "NewGui", "(", "mode", "OutputMode", ")", "(", "*", "Gui", ",", "error", ")", "{", "if", "err", ":=", "termbox", ".", "Init", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "g", ":=", "&", "Gui", "{", "}", "\n\n", "g", ".", "outputMode", "=", "mode", "\n", "termbox", ".", "SetOutputMode", "(", "termbox", ".", "OutputMode", "(", "mode", ")", ")", "\n\n", "g", ".", "tbEvents", "=", "make", "(", "chan", "termbox", ".", "Event", ",", "20", ")", "\n", "g", ".", "userEvents", "=", "make", "(", "chan", "userEvent", ",", "20", ")", "\n\n", "g", ".", "maxX", ",", "g", ".", "maxY", "=", "termbox", ".", "Size", "(", ")", "\n\n", "g", ".", "BgColor", ",", "g", ".", "FgColor", "=", "ColorDefault", ",", "ColorDefault", "\n", "g", ".", "SelBgColor", ",", "g", ".", "SelFgColor", "=", "ColorDefault", ",", "ColorDefault", "\n\n", "return", "g", ",", "nil", "\n", "}" ]
// NewGui returns a new Gui object with a given output mode.
[ "NewGui", "returns", "a", "new", "Gui", "object", "with", "a", "given", "output", "mode", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L72-L91
train
jroimartin/gocui
gui.go
Size
func (g *Gui) Size() (x, y int) { return g.maxX, g.maxY }
go
func (g *Gui) Size() (x, y int) { return g.maxX, g.maxY }
[ "func", "(", "g", "*", "Gui", ")", "Size", "(", ")", "(", "x", ",", "y", "int", ")", "{", "return", "g", ".", "maxX", ",", "g", ".", "maxY", "\n", "}" ]
// Size returns the terminal's size.
[ "Size", "returns", "the", "terminal", "s", "size", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L100-L102
train
jroimartin/gocui
gui.go
SetRune
func (g *Gui) SetRune(x, y int, ch rune, fgColor, bgColor Attribute) error { if x < 0 || y < 0 || x >= g.maxX || y >= g.maxY { return errors.New("invalid point") } termbox.SetCell(x, y, ch, termbox.Attribute(fgColor), termbox.Attribute(bgColor)) return nil }
go
func (g *Gui) SetRune(x, y int, ch rune, fgColor, bgColor Attribute) error { if x < 0 || y < 0 || x >= g.maxX || y >= g.maxY { return errors.New("invalid point") } termbox.SetCell(x, y, ch, termbox.Attribute(fgColor), termbox.Attribute(bgColor)) return nil }
[ "func", "(", "g", "*", "Gui", ")", "SetRune", "(", "x", ",", "y", "int", ",", "ch", "rune", ",", "fgColor", ",", "bgColor", "Attribute", ")", "error", "{", "if", "x", "<", "0", "||", "y", "<", "0", "||", "x", ">=", "g", ".", "maxX", "||", "y", ">=", "g", ".", "maxY", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "termbox", ".", "SetCell", "(", "x", ",", "y", ",", "ch", ",", "termbox", ".", "Attribute", "(", "fgColor", ")", ",", "termbox", ".", "Attribute", "(", "bgColor", ")", ")", "\n", "return", "nil", "\n", "}" ]
// SetRune writes a rune at the given point, relative to the top-left // corner of the terminal. It checks if the position is valid and applies // the given colors.
[ "SetRune", "writes", "a", "rune", "at", "the", "given", "point", "relative", "to", "the", "top", "-", "left", "corner", "of", "the", "terminal", ".", "It", "checks", "if", "the", "position", "is", "valid", "and", "applies", "the", "given", "colors", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L107-L113
train
jroimartin/gocui
gui.go
Rune
func (g *Gui) Rune(x, y int) (rune, error) { if x < 0 || y < 0 || x >= g.maxX || y >= g.maxY { return ' ', errors.New("invalid point") } c := termbox.CellBuffer()[y*g.maxX+x] return c.Ch, nil }
go
func (g *Gui) Rune(x, y int) (rune, error) { if x < 0 || y < 0 || x >= g.maxX || y >= g.maxY { return ' ', errors.New("invalid point") } c := termbox.CellBuffer()[y*g.maxX+x] return c.Ch, nil }
[ "func", "(", "g", "*", "Gui", ")", "Rune", "(", "x", ",", "y", "int", ")", "(", "rune", ",", "error", ")", "{", "if", "x", "<", "0", "||", "y", "<", "0", "||", "x", ">=", "g", ".", "maxX", "||", "y", ">=", "g", ".", "maxY", "{", "return", "' '", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "c", ":=", "termbox", ".", "CellBuffer", "(", ")", "[", "y", "*", "g", ".", "maxX", "+", "x", "]", "\n", "return", "c", ".", "Ch", ",", "nil", "\n", "}" ]
// Rune returns the rune contained in the cell at the given position. // It checks if the position is valid.
[ "Rune", "returns", "the", "rune", "contained", "in", "the", "cell", "at", "the", "given", "position", ".", "It", "checks", "if", "the", "position", "is", "valid", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L117-L123
train
jroimartin/gocui
gui.go
SetViewOnTop
func (g *Gui) SetViewOnTop(name string) (*View, error) { for i, v := range g.views { if v.name == name { s := append(g.views[:i], g.views[i+1:]...) g.views = append(s, v) return v, nil } } return nil, ErrUnknownView }
go
func (g *Gui) SetViewOnTop(name string) (*View, error) { for i, v := range g.views { if v.name == name { s := append(g.views[:i], g.views[i+1:]...) g.views = append(s, v) return v, nil } } return nil, ErrUnknownView }
[ "func", "(", "g", "*", "Gui", ")", "SetViewOnTop", "(", "name", "string", ")", "(", "*", "View", ",", "error", ")", "{", "for", "i", ",", "v", ":=", "range", "g", ".", "views", "{", "if", "v", ".", "name", "==", "name", "{", "s", ":=", "append", "(", "g", ".", "views", "[", ":", "i", "]", ",", "g", ".", "views", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "g", ".", "views", "=", "append", "(", "s", ",", "v", ")", "\n", "return", "v", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "ErrUnknownView", "\n", "}" ]
// SetViewOnTop sets the given view on top of the existing ones.
[ "SetViewOnTop", "sets", "the", "given", "view", "on", "top", "of", "the", "existing", "ones", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L155-L164
train
jroimartin/gocui
gui.go
View
func (g *Gui) View(name string) (*View, error) { for _, v := range g.views { if v.name == name { return v, nil } } return nil, ErrUnknownView }
go
func (g *Gui) View(name string) (*View, error) { for _, v := range g.views { if v.name == name { return v, nil } } return nil, ErrUnknownView }
[ "func", "(", "g", "*", "Gui", ")", "View", "(", "name", "string", ")", "(", "*", "View", ",", "error", ")", "{", "for", "_", ",", "v", ":=", "range", "g", ".", "views", "{", "if", "v", ".", "name", "==", "name", "{", "return", "v", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "ErrUnknownView", "\n", "}" ]
// View returns a pointer to the view with the given name, or error // ErrUnknownView if a view with that name does not exist.
[ "View", "returns", "a", "pointer", "to", "the", "view", "with", "the", "given", "name", "or", "error", "ErrUnknownView", "if", "a", "view", "with", "that", "name", "does", "not", "exist", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L185-L192
train
jroimartin/gocui
gui.go
ViewByPosition
func (g *Gui) ViewByPosition(x, y int) (*View, error) { // traverse views in reverse order checking top views first for i := len(g.views); i > 0; i-- { v := g.views[i-1] if x > v.x0 && x < v.x1 && y > v.y0 && y < v.y1 { return v, nil } } return nil, ErrUnknownView }
go
func (g *Gui) ViewByPosition(x, y int) (*View, error) { // traverse views in reverse order checking top views first for i := len(g.views); i > 0; i-- { v := g.views[i-1] if x > v.x0 && x < v.x1 && y > v.y0 && y < v.y1 { return v, nil } } return nil, ErrUnknownView }
[ "func", "(", "g", "*", "Gui", ")", "ViewByPosition", "(", "x", ",", "y", "int", ")", "(", "*", "View", ",", "error", ")", "{", "// traverse views in reverse order checking top views first", "for", "i", ":=", "len", "(", "g", ".", "views", ")", ";", "i", ">", "0", ";", "i", "--", "{", "v", ":=", "g", ".", "views", "[", "i", "-", "1", "]", "\n", "if", "x", ">", "v", ".", "x0", "&&", "x", "<", "v", ".", "x1", "&&", "y", ">", "v", ".", "y0", "&&", "y", "<", "v", ".", "y1", "{", "return", "v", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "ErrUnknownView", "\n", "}" ]
// ViewByPosition returns a pointer to a view matching the given position, or // error ErrUnknownView if a view in that position does not exist.
[ "ViewByPosition", "returns", "a", "pointer", "to", "a", "view", "matching", "the", "given", "position", "or", "error", "ErrUnknownView", "if", "a", "view", "in", "that", "position", "does", "not", "exist", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L196-L205
train
jroimartin/gocui
gui.go
ViewPosition
func (g *Gui) ViewPosition(name string) (x0, y0, x1, y1 int, err error) { for _, v := range g.views { if v.name == name { return v.x0, v.y0, v.x1, v.y1, nil } } return 0, 0, 0, 0, ErrUnknownView }
go
func (g *Gui) ViewPosition(name string) (x0, y0, x1, y1 int, err error) { for _, v := range g.views { if v.name == name { return v.x0, v.y0, v.x1, v.y1, nil } } return 0, 0, 0, 0, ErrUnknownView }
[ "func", "(", "g", "*", "Gui", ")", "ViewPosition", "(", "name", "string", ")", "(", "x0", ",", "y0", ",", "x1", ",", "y1", "int", ",", "err", "error", ")", "{", "for", "_", ",", "v", ":=", "range", "g", ".", "views", "{", "if", "v", ".", "name", "==", "name", "{", "return", "v", ".", "x0", ",", "v", ".", "y0", ",", "v", ".", "x1", ",", "v", ".", "y1", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "0", ",", "0", ",", "0", ",", "0", ",", "ErrUnknownView", "\n", "}" ]
// ViewPosition returns the coordinates of the view with the given name, or // error ErrUnknownView if a view with that name does not exist.
[ "ViewPosition", "returns", "the", "coordinates", "of", "the", "view", "with", "the", "given", "name", "or", "error", "ErrUnknownView", "if", "a", "view", "with", "that", "name", "does", "not", "exist", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L209-L216
train
jroimartin/gocui
gui.go
DeleteView
func (g *Gui) DeleteView(name string) error { for i, v := range g.views { if v.name == name { g.views = append(g.views[:i], g.views[i+1:]...) return nil } } return ErrUnknownView }
go
func (g *Gui) DeleteView(name string) error { for i, v := range g.views { if v.name == name { g.views = append(g.views[:i], g.views[i+1:]...) return nil } } return ErrUnknownView }
[ "func", "(", "g", "*", "Gui", ")", "DeleteView", "(", "name", "string", ")", "error", "{", "for", "i", ",", "v", ":=", "range", "g", ".", "views", "{", "if", "v", ".", "name", "==", "name", "{", "g", ".", "views", "=", "append", "(", "g", ".", "views", "[", ":", "i", "]", ",", "g", ".", "views", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "return", "nil", "\n", "}", "\n", "}", "\n", "return", "ErrUnknownView", "\n", "}" ]
// DeleteView deletes a view by name.
[ "DeleteView", "deletes", "a", "view", "by", "name", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L219-L227
train
jroimartin/gocui
gui.go
DeleteKeybinding
func (g *Gui) DeleteKeybinding(viewname string, key interface{}, mod Modifier) error { k, ch, err := getKey(key) if err != nil { return err } for i, kb := range g.keybindings { if kb.viewName == viewname && kb.ch == ch && kb.key == k && kb.mod == mod { g.keybindings = append(g.keybindings[:i], g.keybindings[i+1:]...) return nil } } return errors.New("keybinding not found") }
go
func (g *Gui) DeleteKeybinding(viewname string, key interface{}, mod Modifier) error { k, ch, err := getKey(key) if err != nil { return err } for i, kb := range g.keybindings { if kb.viewName == viewname && kb.ch == ch && kb.key == k && kb.mod == mod { g.keybindings = append(g.keybindings[:i], g.keybindings[i+1:]...) return nil } } return errors.New("keybinding not found") }
[ "func", "(", "g", "*", "Gui", ")", "DeleteKeybinding", "(", "viewname", "string", ",", "key", "interface", "{", "}", ",", "mod", "Modifier", ")", "error", "{", "k", ",", "ch", ",", "err", ":=", "getKey", "(", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "for", "i", ",", "kb", ":=", "range", "g", ".", "keybindings", "{", "if", "kb", ".", "viewName", "==", "viewname", "&&", "kb", ".", "ch", "==", "ch", "&&", "kb", ".", "key", "==", "k", "&&", "kb", ".", "mod", "==", "mod", "{", "g", ".", "keybindings", "=", "append", "(", "g", ".", "keybindings", "[", ":", "i", "]", ",", "g", ".", "keybindings", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "return", "nil", "\n", "}", "\n", "}", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}" ]
// DeleteKeybinding deletes a keybinding.
[ "DeleteKeybinding", "deletes", "a", "keybinding", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L262-L275
train
jroimartin/gocui
gui.go
DeleteKeybindings
func (g *Gui) DeleteKeybindings(viewname string) { var s []*keybinding for _, kb := range g.keybindings { if kb.viewName != viewname { s = append(s, kb) } } g.keybindings = s }
go
func (g *Gui) DeleteKeybindings(viewname string) { var s []*keybinding for _, kb := range g.keybindings { if kb.viewName != viewname { s = append(s, kb) } } g.keybindings = s }
[ "func", "(", "g", "*", "Gui", ")", "DeleteKeybindings", "(", "viewname", "string", ")", "{", "var", "s", "[", "]", "*", "keybinding", "\n", "for", "_", ",", "kb", ":=", "range", "g", ".", "keybindings", "{", "if", "kb", ".", "viewName", "!=", "viewname", "{", "s", "=", "append", "(", "s", ",", "kb", ")", "\n", "}", "\n", "}", "\n", "g", ".", "keybindings", "=", "s", "\n", "}" ]
// DeleteKeybindings deletes all keybindings of view.
[ "DeleteKeybindings", "deletes", "all", "keybindings", "of", "view", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L278-L286
train
jroimartin/gocui
gui.go
getKey
func getKey(key interface{}) (Key, rune, error) { switch t := key.(type) { case Key: return t, 0, nil case rune: return 0, t, nil default: return 0, 0, errors.New("unknown type") } }
go
func getKey(key interface{}) (Key, rune, error) { switch t := key.(type) { case Key: return t, 0, nil case rune: return 0, t, nil default: return 0, 0, errors.New("unknown type") } }
[ "func", "getKey", "(", "key", "interface", "{", "}", ")", "(", "Key", ",", "rune", ",", "error", ")", "{", "switch", "t", ":=", "key", ".", "(", "type", ")", "{", "case", "Key", ":", "return", "t", ",", "0", ",", "nil", "\n", "case", "rune", ":", "return", "0", ",", "t", ",", "nil", "\n", "default", ":", "return", "0", ",", "0", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// getKey takes an empty interface with a key and returns the corresponding // typed Key or rune.
[ "getKey", "takes", "an", "empty", "interface", "with", "a", "key", "and", "returns", "the", "corresponding", "typed", "Key", "or", "rune", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L290-L299
train
jroimartin/gocui
gui.go
Update
func (g *Gui) Update(f func(*Gui) error) { go func() { g.userEvents <- userEvent{f: f} }() }
go
func (g *Gui) Update(f func(*Gui) error) { go func() { g.userEvents <- userEvent{f: f} }() }
[ "func", "(", "g", "*", "Gui", ")", "Update", "(", "f", "func", "(", "*", "Gui", ")", "error", ")", "{", "go", "func", "(", ")", "{", "g", ".", "userEvents", "<-", "userEvent", "{", "f", ":", "f", "}", "}", "(", ")", "\n", "}" ]
// Update executes the passed function. This method can be called safely from a // goroutine in order to update the GUI. It is important to note that the // passed function won't be executed immediately, instead it will be added to // the user events queue. Given that Update spawns a goroutine, the order in // which the user events will be handled is not guaranteed.
[ "Update", "executes", "the", "passed", "function", ".", "This", "method", "can", "be", "called", "safely", "from", "a", "goroutine", "in", "order", "to", "update", "the", "GUI", ".", "It", "is", "important", "to", "note", "that", "the", "passed", "function", "won", "t", "be", "executed", "immediately", "instead", "it", "will", "be", "added", "to", "the", "user", "events", "queue", ".", "Given", "that", "Update", "spawns", "a", "goroutine", "the", "order", "in", "which", "the", "user", "events", "will", "be", "handled", "is", "not", "guaranteed", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L311-L313
train
jroimartin/gocui
gui.go
SetManager
func (g *Gui) SetManager(managers ...Manager) { g.managers = managers g.currentView = nil g.views = nil g.keybindings = nil go func() { g.tbEvents <- termbox.Event{Type: termbox.EventResize} }() }
go
func (g *Gui) SetManager(managers ...Manager) { g.managers = managers g.currentView = nil g.views = nil g.keybindings = nil go func() { g.tbEvents <- termbox.Event{Type: termbox.EventResize} }() }
[ "func", "(", "g", "*", "Gui", ")", "SetManager", "(", "managers", "...", "Manager", ")", "{", "g", ".", "managers", "=", "managers", "\n", "g", ".", "currentView", "=", "nil", "\n", "g", ".", "views", "=", "nil", "\n", "g", ".", "keybindings", "=", "nil", "\n\n", "go", "func", "(", ")", "{", "g", ".", "tbEvents", "<-", "termbox", ".", "Event", "{", "Type", ":", "termbox", ".", "EventResize", "}", "}", "(", ")", "\n", "}" ]
// SetManager sets the given GUI managers. It deletes all views and // keybindings.
[ "SetManager", "sets", "the", "given", "GUI", "managers", ".", "It", "deletes", "all", "views", "and", "keybindings", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L334-L341
train
jroimartin/gocui
gui.go
SetManagerFunc
func (g *Gui) SetManagerFunc(manager func(*Gui) error) { g.SetManager(ManagerFunc(manager)) }
go
func (g *Gui) SetManagerFunc(manager func(*Gui) error) { g.SetManager(ManagerFunc(manager)) }
[ "func", "(", "g", "*", "Gui", ")", "SetManagerFunc", "(", "manager", "func", "(", "*", "Gui", ")", "error", ")", "{", "g", ".", "SetManager", "(", "ManagerFunc", "(", "manager", ")", ")", "\n", "}" ]
// SetManagerFunc sets the given manager function. It deletes all views and // keybindings.
[ "SetManagerFunc", "sets", "the", "given", "manager", "function", ".", "It", "deletes", "all", "views", "and", "keybindings", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L345-L347
train
jroimartin/gocui
gui.go
MainLoop
func (g *Gui) MainLoop() error { go func() { for { g.tbEvents <- termbox.PollEvent() } }() inputMode := termbox.InputAlt if g.InputEsc { inputMode = termbox.InputEsc } if g.Mouse { inputMode |= termbox.InputMouse } termbox.SetInputMode(inputMode) if err := g.flush(); err != nil { return err } for { select { case ev := <-g.tbEvents: if err := g.handleEvent(&ev); err != nil { return err } case ev := <-g.userEvents: if err := ev.f(g); err != nil { return err } } if err := g.consumeevents(); err != nil { return err } if err := g.flush(); err != nil { return err } } }
go
func (g *Gui) MainLoop() error { go func() { for { g.tbEvents <- termbox.PollEvent() } }() inputMode := termbox.InputAlt if g.InputEsc { inputMode = termbox.InputEsc } if g.Mouse { inputMode |= termbox.InputMouse } termbox.SetInputMode(inputMode) if err := g.flush(); err != nil { return err } for { select { case ev := <-g.tbEvents: if err := g.handleEvent(&ev); err != nil { return err } case ev := <-g.userEvents: if err := ev.f(g); err != nil { return err } } if err := g.consumeevents(); err != nil { return err } if err := g.flush(); err != nil { return err } } }
[ "func", "(", "g", "*", "Gui", ")", "MainLoop", "(", ")", "error", "{", "go", "func", "(", ")", "{", "for", "{", "g", ".", "tbEvents", "<-", "termbox", ".", "PollEvent", "(", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "inputMode", ":=", "termbox", ".", "InputAlt", "\n", "if", "g", ".", "InputEsc", "{", "inputMode", "=", "termbox", ".", "InputEsc", "\n", "}", "\n", "if", "g", ".", "Mouse", "{", "inputMode", "|=", "termbox", ".", "InputMouse", "\n", "}", "\n", "termbox", ".", "SetInputMode", "(", "inputMode", ")", "\n\n", "if", "err", ":=", "g", ".", "flush", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "{", "select", "{", "case", "ev", ":=", "<-", "g", ".", "tbEvents", ":", "if", "err", ":=", "g", ".", "handleEvent", "(", "&", "ev", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "case", "ev", ":=", "<-", "g", ".", "userEvents", ":", "if", "err", ":=", "ev", ".", "f", "(", "g", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "if", "err", ":=", "g", ".", "consumeevents", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", ":=", "g", ".", "flush", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}" ]
// MainLoop runs the main loop until an error is returned. A successful // finish should return ErrQuit.
[ "MainLoop", "runs", "the", "main", "loop", "until", "an", "error", "is", "returned", ".", "A", "successful", "finish", "should", "return", "ErrQuit", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L351-L388
train
jroimartin/gocui
gui.go
consumeevents
func (g *Gui) consumeevents() error { for { select { case ev := <-g.tbEvents: if err := g.handleEvent(&ev); err != nil { return err } case ev := <-g.userEvents: if err := ev.f(g); err != nil { return err } default: return nil } } }
go
func (g *Gui) consumeevents() error { for { select { case ev := <-g.tbEvents: if err := g.handleEvent(&ev); err != nil { return err } case ev := <-g.userEvents: if err := ev.f(g); err != nil { return err } default: return nil } } }
[ "func", "(", "g", "*", "Gui", ")", "consumeevents", "(", ")", "error", "{", "for", "{", "select", "{", "case", "ev", ":=", "<-", "g", ".", "tbEvents", ":", "if", "err", ":=", "g", ".", "handleEvent", "(", "&", "ev", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "case", "ev", ":=", "<-", "g", ".", "userEvents", ":", "if", "err", ":=", "ev", ".", "f", "(", "g", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "default", ":", "return", "nil", "\n", "}", "\n", "}", "\n", "}" ]
// consumeevents handles the remaining events in the events pool.
[ "consumeevents", "handles", "the", "remaining", "events", "in", "the", "events", "pool", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L391-L406
train
jroimartin/gocui
gui.go
flush
func (g *Gui) flush() error { termbox.Clear(termbox.Attribute(g.FgColor), termbox.Attribute(g.BgColor)) maxX, maxY := termbox.Size() // if GUI's size has changed, we need to redraw all views if maxX != g.maxX || maxY != g.maxY { for _, v := range g.views { v.tainted = true } } g.maxX, g.maxY = maxX, maxY for _, m := range g.managers { if err := m.Layout(g); err != nil { return err } } for _, v := range g.views { if v.Frame { var fgColor, bgColor Attribute if g.Highlight && v == g.currentView { fgColor = g.SelFgColor bgColor = g.SelBgColor } else { fgColor = g.FgColor bgColor = g.BgColor } if err := g.drawFrameEdges(v, fgColor, bgColor); err != nil { return err } if err := g.drawFrameCorners(v, fgColor, bgColor); err != nil { return err } if v.Title != "" { if err := g.drawTitle(v, fgColor, bgColor); err != nil { return err } } } if err := g.draw(v); err != nil { return err } } termbox.Flush() return nil }
go
func (g *Gui) flush() error { termbox.Clear(termbox.Attribute(g.FgColor), termbox.Attribute(g.BgColor)) maxX, maxY := termbox.Size() // if GUI's size has changed, we need to redraw all views if maxX != g.maxX || maxY != g.maxY { for _, v := range g.views { v.tainted = true } } g.maxX, g.maxY = maxX, maxY for _, m := range g.managers { if err := m.Layout(g); err != nil { return err } } for _, v := range g.views { if v.Frame { var fgColor, bgColor Attribute if g.Highlight && v == g.currentView { fgColor = g.SelFgColor bgColor = g.SelBgColor } else { fgColor = g.FgColor bgColor = g.BgColor } if err := g.drawFrameEdges(v, fgColor, bgColor); err != nil { return err } if err := g.drawFrameCorners(v, fgColor, bgColor); err != nil { return err } if v.Title != "" { if err := g.drawTitle(v, fgColor, bgColor); err != nil { return err } } } if err := g.draw(v); err != nil { return err } } termbox.Flush() return nil }
[ "func", "(", "g", "*", "Gui", ")", "flush", "(", ")", "error", "{", "termbox", ".", "Clear", "(", "termbox", ".", "Attribute", "(", "g", ".", "FgColor", ")", ",", "termbox", ".", "Attribute", "(", "g", ".", "BgColor", ")", ")", "\n\n", "maxX", ",", "maxY", ":=", "termbox", ".", "Size", "(", ")", "\n", "// if GUI's size has changed, we need to redraw all views", "if", "maxX", "!=", "g", ".", "maxX", "||", "maxY", "!=", "g", ".", "maxY", "{", "for", "_", ",", "v", ":=", "range", "g", ".", "views", "{", "v", ".", "tainted", "=", "true", "\n", "}", "\n", "}", "\n", "g", ".", "maxX", ",", "g", ".", "maxY", "=", "maxX", ",", "maxY", "\n\n", "for", "_", ",", "m", ":=", "range", "g", ".", "managers", "{", "if", "err", ":=", "m", ".", "Layout", "(", "g", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "for", "_", ",", "v", ":=", "range", "g", ".", "views", "{", "if", "v", ".", "Frame", "{", "var", "fgColor", ",", "bgColor", "Attribute", "\n", "if", "g", ".", "Highlight", "&&", "v", "==", "g", ".", "currentView", "{", "fgColor", "=", "g", ".", "SelFgColor", "\n", "bgColor", "=", "g", ".", "SelBgColor", "\n", "}", "else", "{", "fgColor", "=", "g", ".", "FgColor", "\n", "bgColor", "=", "g", ".", "BgColor", "\n", "}", "\n\n", "if", "err", ":=", "g", ".", "drawFrameEdges", "(", "v", ",", "fgColor", ",", "bgColor", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", ":=", "g", ".", "drawFrameCorners", "(", "v", ",", "fgColor", ",", "bgColor", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "v", ".", "Title", "!=", "\"", "\"", "{", "if", "err", ":=", "g", ".", "drawTitle", "(", "v", ",", "fgColor", ",", "bgColor", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "err", ":=", "g", ".", "draw", "(", "v", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "termbox", ".", "Flush", "(", ")", "\n", "return", "nil", "\n", "}" ]
// flush updates the gui, re-drawing frames and buffers.
[ "flush", "updates", "the", "gui", "re", "-", "drawing", "frames", "and", "buffers", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L422-L468
train
jroimartin/gocui
gui.go
drawFrameEdges
func (g *Gui) drawFrameEdges(v *View, fgColor, bgColor Attribute) error { runeH, runeV := '─', '│' if g.ASCII { runeH, runeV = '-', '|' } for x := v.x0 + 1; x < v.x1 && x < g.maxX; x++ { if x < 0 { continue } if v.y0 > -1 && v.y0 < g.maxY { if err := g.SetRune(x, v.y0, runeH, fgColor, bgColor); err != nil { return err } } if v.y1 > -1 && v.y1 < g.maxY { if err := g.SetRune(x, v.y1, runeH, fgColor, bgColor); err != nil { return err } } } for y := v.y0 + 1; y < v.y1 && y < g.maxY; y++ { if y < 0 { continue } if v.x0 > -1 && v.x0 < g.maxX { if err := g.SetRune(v.x0, y, runeV, fgColor, bgColor); err != nil { return err } } if v.x1 > -1 && v.x1 < g.maxX { if err := g.SetRune(v.x1, y, runeV, fgColor, bgColor); err != nil { return err } } } return nil }
go
func (g *Gui) drawFrameEdges(v *View, fgColor, bgColor Attribute) error { runeH, runeV := '─', '│' if g.ASCII { runeH, runeV = '-', '|' } for x := v.x0 + 1; x < v.x1 && x < g.maxX; x++ { if x < 0 { continue } if v.y0 > -1 && v.y0 < g.maxY { if err := g.SetRune(x, v.y0, runeH, fgColor, bgColor); err != nil { return err } } if v.y1 > -1 && v.y1 < g.maxY { if err := g.SetRune(x, v.y1, runeH, fgColor, bgColor); err != nil { return err } } } for y := v.y0 + 1; y < v.y1 && y < g.maxY; y++ { if y < 0 { continue } if v.x0 > -1 && v.x0 < g.maxX { if err := g.SetRune(v.x0, y, runeV, fgColor, bgColor); err != nil { return err } } if v.x1 > -1 && v.x1 < g.maxX { if err := g.SetRune(v.x1, y, runeV, fgColor, bgColor); err != nil { return err } } } return nil }
[ "func", "(", "g", "*", "Gui", ")", "drawFrameEdges", "(", "v", "*", "View", ",", "fgColor", ",", "bgColor", "Attribute", ")", "error", "{", "runeH", ",", "runeV", ":=", "'─', ", "'", "'", "\n", "if", "g", ".", "ASCII", "{", "runeH", ",", "runeV", "=", "'-'", ",", "'|'", "\n", "}", "\n\n", "for", "x", ":=", "v", ".", "x0", "+", "1", ";", "x", "<", "v", ".", "x1", "&&", "x", "<", "g", ".", "maxX", ";", "x", "++", "{", "if", "x", "<", "0", "{", "continue", "\n", "}", "\n", "if", "v", ".", "y0", ">", "-", "1", "&&", "v", ".", "y0", "<", "g", ".", "maxY", "{", "if", "err", ":=", "g", ".", "SetRune", "(", "x", ",", "v", ".", "y0", ",", "runeH", ",", "fgColor", ",", "bgColor", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "if", "v", ".", "y1", ">", "-", "1", "&&", "v", ".", "y1", "<", "g", ".", "maxY", "{", "if", "err", ":=", "g", ".", "SetRune", "(", "x", ",", "v", ".", "y1", ",", "runeH", ",", "fgColor", ",", "bgColor", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "for", "y", ":=", "v", ".", "y0", "+", "1", ";", "y", "<", "v", ".", "y1", "&&", "y", "<", "g", ".", "maxY", ";", "y", "++", "{", "if", "y", "<", "0", "{", "continue", "\n", "}", "\n", "if", "v", ".", "x0", ">", "-", "1", "&&", "v", ".", "x0", "<", "g", ".", "maxX", "{", "if", "err", ":=", "g", ".", "SetRune", "(", "v", ".", "x0", ",", "y", ",", "runeV", ",", "fgColor", ",", "bgColor", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "if", "v", ".", "x1", ">", "-", "1", "&&", "v", ".", "x1", "<", "g", ".", "maxX", "{", "if", "err", ":=", "g", ".", "SetRune", "(", "v", ".", "x1", ",", "y", ",", "runeV", ",", "fgColor", ",", "bgColor", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// drawFrameEdges draws the horizontal and vertical edges of a view.
[ "drawFrameEdges", "draws", "the", "horizontal", "and", "vertical", "edges", "of", "a", "view", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L471-L508
train
jroimartin/gocui
gui.go
drawFrameCorners
func (g *Gui) drawFrameCorners(v *View, fgColor, bgColor Attribute) error { runeTL, runeTR, runeBL, runeBR := '┌', '┐', '└', '┘' if g.ASCII { runeTL, runeTR, runeBL, runeBR = '+', '+', '+', '+' } corners := []struct { x, y int ch rune }{{v.x0, v.y0, runeTL}, {v.x1, v.y0, runeTR}, {v.x0, v.y1, runeBL}, {v.x1, v.y1, runeBR}} for _, c := range corners { if c.x >= 0 && c.y >= 0 && c.x < g.maxX && c.y < g.maxY { if err := g.SetRune(c.x, c.y, c.ch, fgColor, bgColor); err != nil { return err } } } return nil }
go
func (g *Gui) drawFrameCorners(v *View, fgColor, bgColor Attribute) error { runeTL, runeTR, runeBL, runeBR := '┌', '┐', '└', '┘' if g.ASCII { runeTL, runeTR, runeBL, runeBR = '+', '+', '+', '+' } corners := []struct { x, y int ch rune }{{v.x0, v.y0, runeTL}, {v.x1, v.y0, runeTR}, {v.x0, v.y1, runeBL}, {v.x1, v.y1, runeBR}} for _, c := range corners { if c.x >= 0 && c.y >= 0 && c.x < g.maxX && c.y < g.maxY { if err := g.SetRune(c.x, c.y, c.ch, fgColor, bgColor); err != nil { return err } } } return nil }
[ "func", "(", "g", "*", "Gui", ")", "drawFrameCorners", "(", "v", "*", "View", ",", "fgColor", ",", "bgColor", "Attribute", ")", "error", "{", "runeTL", ",", "runeTR", ",", "runeBL", ",", "runeBR", ":=", "'┌', ", "'", "', '└", "'", " '┘'", "", "", "\n", "if", "g", ".", "ASCII", "{", "runeTL", ",", "runeTR", ",", "runeBL", ",", "runeBR", "=", "'+'", ",", "'+'", ",", "'+'", ",", "'+'", "\n", "}", "\n\n", "corners", ":=", "[", "]", "struct", "{", "x", ",", "y", "int", "\n", "ch", "rune", "\n", "}", "{", "{", "v", ".", "x0", ",", "v", ".", "y0", ",", "runeTL", "}", ",", "{", "v", ".", "x1", ",", "v", ".", "y0", ",", "runeTR", "}", ",", "{", "v", ".", "x0", ",", "v", ".", "y1", ",", "runeBL", "}", ",", "{", "v", ".", "x1", ",", "v", ".", "y1", ",", "runeBR", "}", "}", "\n\n", "for", "_", ",", "c", ":=", "range", "corners", "{", "if", "c", ".", "x", ">=", "0", "&&", "c", ".", "y", ">=", "0", "&&", "c", ".", "x", "<", "g", ".", "maxX", "&&", "c", ".", "y", "<", "g", ".", "maxY", "{", "if", "err", ":=", "g", ".", "SetRune", "(", "c", ".", "x", ",", "c", ".", "y", ",", "c", ".", "ch", ",", "fgColor", ",", "bgColor", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// drawFrameCorners draws the corners of the view.
[ "drawFrameCorners", "draws", "the", "corners", "of", "the", "view", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L511-L530
train
jroimartin/gocui
gui.go
drawTitle
func (g *Gui) drawTitle(v *View, fgColor, bgColor Attribute) error { if v.y0 < 0 || v.y0 >= g.maxY { return nil } for i, ch := range v.Title { x := v.x0 + i + 2 if x < 0 { continue } else if x > v.x1-2 || x >= g.maxX { break } if err := g.SetRune(x, v.y0, ch, fgColor, bgColor); err != nil { return err } } return nil }
go
func (g *Gui) drawTitle(v *View, fgColor, bgColor Attribute) error { if v.y0 < 0 || v.y0 >= g.maxY { return nil } for i, ch := range v.Title { x := v.x0 + i + 2 if x < 0 { continue } else if x > v.x1-2 || x >= g.maxX { break } if err := g.SetRune(x, v.y0, ch, fgColor, bgColor); err != nil { return err } } return nil }
[ "func", "(", "g", "*", "Gui", ")", "drawTitle", "(", "v", "*", "View", ",", "fgColor", ",", "bgColor", "Attribute", ")", "error", "{", "if", "v", ".", "y0", "<", "0", "||", "v", ".", "y0", ">=", "g", ".", "maxY", "{", "return", "nil", "\n", "}", "\n\n", "for", "i", ",", "ch", ":=", "range", "v", ".", "Title", "{", "x", ":=", "v", ".", "x0", "+", "i", "+", "2", "\n", "if", "x", "<", "0", "{", "continue", "\n", "}", "else", "if", "x", ">", "v", ".", "x1", "-", "2", "||", "x", ">=", "g", ".", "maxX", "{", "break", "\n", "}", "\n", "if", "err", ":=", "g", ".", "SetRune", "(", "x", ",", "v", ".", "y0", ",", "ch", ",", "fgColor", ",", "bgColor", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// drawTitle draws the title of the view.
[ "drawTitle", "draws", "the", "title", "of", "the", "view", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L533-L550
train
jroimartin/gocui
gui.go
draw
func (g *Gui) draw(v *View) error { if g.Cursor { if curview := g.currentView; curview != nil { vMaxX, vMaxY := curview.Size() if curview.cx < 0 { curview.cx = 0 } else if curview.cx >= vMaxX { curview.cx = vMaxX - 1 } if curview.cy < 0 { curview.cy = 0 } else if curview.cy >= vMaxY { curview.cy = vMaxY - 1 } gMaxX, gMaxY := g.Size() cx, cy := curview.x0+curview.cx+1, curview.y0+curview.cy+1 if cx >= 0 && cx < gMaxX && cy >= 0 && cy < gMaxY { termbox.SetCursor(cx, cy) } else { termbox.HideCursor() } } } else { termbox.HideCursor() } v.clearRunes() if err := v.draw(); err != nil { return err } return nil }
go
func (g *Gui) draw(v *View) error { if g.Cursor { if curview := g.currentView; curview != nil { vMaxX, vMaxY := curview.Size() if curview.cx < 0 { curview.cx = 0 } else if curview.cx >= vMaxX { curview.cx = vMaxX - 1 } if curview.cy < 0 { curview.cy = 0 } else if curview.cy >= vMaxY { curview.cy = vMaxY - 1 } gMaxX, gMaxY := g.Size() cx, cy := curview.x0+curview.cx+1, curview.y0+curview.cy+1 if cx >= 0 && cx < gMaxX && cy >= 0 && cy < gMaxY { termbox.SetCursor(cx, cy) } else { termbox.HideCursor() } } } else { termbox.HideCursor() } v.clearRunes() if err := v.draw(); err != nil { return err } return nil }
[ "func", "(", "g", "*", "Gui", ")", "draw", "(", "v", "*", "View", ")", "error", "{", "if", "g", ".", "Cursor", "{", "if", "curview", ":=", "g", ".", "currentView", ";", "curview", "!=", "nil", "{", "vMaxX", ",", "vMaxY", ":=", "curview", ".", "Size", "(", ")", "\n", "if", "curview", ".", "cx", "<", "0", "{", "curview", ".", "cx", "=", "0", "\n", "}", "else", "if", "curview", ".", "cx", ">=", "vMaxX", "{", "curview", ".", "cx", "=", "vMaxX", "-", "1", "\n", "}", "\n", "if", "curview", ".", "cy", "<", "0", "{", "curview", ".", "cy", "=", "0", "\n", "}", "else", "if", "curview", ".", "cy", ">=", "vMaxY", "{", "curview", ".", "cy", "=", "vMaxY", "-", "1", "\n", "}", "\n\n", "gMaxX", ",", "gMaxY", ":=", "g", ".", "Size", "(", ")", "\n", "cx", ",", "cy", ":=", "curview", ".", "x0", "+", "curview", ".", "cx", "+", "1", ",", "curview", ".", "y0", "+", "curview", ".", "cy", "+", "1", "\n", "if", "cx", ">=", "0", "&&", "cx", "<", "gMaxX", "&&", "cy", ">=", "0", "&&", "cy", "<", "gMaxY", "{", "termbox", ".", "SetCursor", "(", "cx", ",", "cy", ")", "\n", "}", "else", "{", "termbox", ".", "HideCursor", "(", ")", "\n", "}", "\n", "}", "\n", "}", "else", "{", "termbox", ".", "HideCursor", "(", ")", "\n", "}", "\n\n", "v", ".", "clearRunes", "(", ")", "\n", "if", "err", ":=", "v", ".", "draw", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// draw manages the cursor and calls the draw function of a view.
[ "draw", "manages", "the", "cursor", "and", "calls", "the", "draw", "function", "of", "a", "view", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L553-L585
train
jroimartin/gocui
gui.go
onKey
func (g *Gui) onKey(ev *termbox.Event) error { switch ev.Type { case termbox.EventKey: matched, err := g.execKeybindings(g.currentView, ev) if err != nil { return err } if matched { break } if g.currentView != nil && g.currentView.Editable && g.currentView.Editor != nil { g.currentView.Editor.Edit(g.currentView, Key(ev.Key), ev.Ch, Modifier(ev.Mod)) } case termbox.EventMouse: mx, my := ev.MouseX, ev.MouseY v, err := g.ViewByPosition(mx, my) if err != nil { break } if err := v.SetCursor(mx-v.x0-1, my-v.y0-1); err != nil { return err } if _, err := g.execKeybindings(v, ev); err != nil { return err } } return nil }
go
func (g *Gui) onKey(ev *termbox.Event) error { switch ev.Type { case termbox.EventKey: matched, err := g.execKeybindings(g.currentView, ev) if err != nil { return err } if matched { break } if g.currentView != nil && g.currentView.Editable && g.currentView.Editor != nil { g.currentView.Editor.Edit(g.currentView, Key(ev.Key), ev.Ch, Modifier(ev.Mod)) } case termbox.EventMouse: mx, my := ev.MouseX, ev.MouseY v, err := g.ViewByPosition(mx, my) if err != nil { break } if err := v.SetCursor(mx-v.x0-1, my-v.y0-1); err != nil { return err } if _, err := g.execKeybindings(v, ev); err != nil { return err } } return nil }
[ "func", "(", "g", "*", "Gui", ")", "onKey", "(", "ev", "*", "termbox", ".", "Event", ")", "error", "{", "switch", "ev", ".", "Type", "{", "case", "termbox", ".", "EventKey", ":", "matched", ",", "err", ":=", "g", ".", "execKeybindings", "(", "g", ".", "currentView", ",", "ev", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "matched", "{", "break", "\n", "}", "\n", "if", "g", ".", "currentView", "!=", "nil", "&&", "g", ".", "currentView", ".", "Editable", "&&", "g", ".", "currentView", ".", "Editor", "!=", "nil", "{", "g", ".", "currentView", ".", "Editor", ".", "Edit", "(", "g", ".", "currentView", ",", "Key", "(", "ev", ".", "Key", ")", ",", "ev", ".", "Ch", ",", "Modifier", "(", "ev", ".", "Mod", ")", ")", "\n", "}", "\n", "case", "termbox", ".", "EventMouse", ":", "mx", ",", "my", ":=", "ev", ".", "MouseX", ",", "ev", ".", "MouseY", "\n", "v", ",", "err", ":=", "g", ".", "ViewByPosition", "(", "mx", ",", "my", ")", "\n", "if", "err", "!=", "nil", "{", "break", "\n", "}", "\n", "if", "err", ":=", "v", ".", "SetCursor", "(", "mx", "-", "v", ".", "x0", "-", "1", ",", "my", "-", "v", ".", "y0", "-", "1", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "_", ",", "err", ":=", "g", ".", "execKeybindings", "(", "v", ",", "ev", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// onKey manages key-press events. A keybinding handler is called when // a key-press or mouse event satisfies a configured keybinding. Furthermore, // currentView's internal buffer is modified if currentView.Editable is true.
[ "onKey", "manages", "key", "-", "press", "events", ".", "A", "keybinding", "handler", "is", "called", "when", "a", "key", "-", "press", "or", "mouse", "event", "satisfies", "a", "configured", "keybinding", ".", "Furthermore", "currentView", "s", "internal", "buffer", "is", "modified", "if", "currentView", ".", "Editable", "is", "true", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L590-L618
train
jroimartin/gocui
gui.go
execKeybindings
func (g *Gui) execKeybindings(v *View, ev *termbox.Event) (matched bool, err error) { matched = false for _, kb := range g.keybindings { if kb.handler == nil { continue } if kb.matchKeypress(Key(ev.Key), ev.Ch, Modifier(ev.Mod)) && kb.matchView(v) { if err := kb.handler(g, v); err != nil { return false, err } matched = true } } return matched, nil }
go
func (g *Gui) execKeybindings(v *View, ev *termbox.Event) (matched bool, err error) { matched = false for _, kb := range g.keybindings { if kb.handler == nil { continue } if kb.matchKeypress(Key(ev.Key), ev.Ch, Modifier(ev.Mod)) && kb.matchView(v) { if err := kb.handler(g, v); err != nil { return false, err } matched = true } } return matched, nil }
[ "func", "(", "g", "*", "Gui", ")", "execKeybindings", "(", "v", "*", "View", ",", "ev", "*", "termbox", ".", "Event", ")", "(", "matched", "bool", ",", "err", "error", ")", "{", "matched", "=", "false", "\n", "for", "_", ",", "kb", ":=", "range", "g", ".", "keybindings", "{", "if", "kb", ".", "handler", "==", "nil", "{", "continue", "\n", "}", "\n", "if", "kb", ".", "matchKeypress", "(", "Key", "(", "ev", ".", "Key", ")", ",", "ev", ".", "Ch", ",", "Modifier", "(", "ev", ".", "Mod", ")", ")", "&&", "kb", ".", "matchView", "(", "v", ")", "{", "if", "err", ":=", "kb", ".", "handler", "(", "g", ",", "v", ")", ";", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "matched", "=", "true", "\n", "}", "\n", "}", "\n", "return", "matched", ",", "nil", "\n", "}" ]
// execKeybindings executes the keybinding handlers that match the passed view // and event. The value of matched is true if there is a match and no errors.
[ "execKeybindings", "executes", "the", "keybinding", "handlers", "that", "match", "the", "passed", "view", "and", "event", ".", "The", "value", "of", "matched", "is", "true", "if", "there", "is", "a", "match", "and", "no", "errors", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L622-L636
train
envoyproxy/protoc-gen-validate
templates/java/register.go
makeInvalidClassnameCharactersUnderscores
func makeInvalidClassnameCharactersUnderscores(name string) string { var sb strings.Builder for _, c := range name { switch { case c >= '0' && c <= '9': sb.WriteRune(c) case c >= 'a' && c <= 'z': sb.WriteRune(c) case c >= 'A' && c <= 'Z': sb.WriteRune(c) default: sb.WriteRune('_') } } return sb.String() }
go
func makeInvalidClassnameCharactersUnderscores(name string) string { var sb strings.Builder for _, c := range name { switch { case c >= '0' && c <= '9': sb.WriteRune(c) case c >= 'a' && c <= 'z': sb.WriteRune(c) case c >= 'A' && c <= 'Z': sb.WriteRune(c) default: sb.WriteRune('_') } } return sb.String() }
[ "func", "makeInvalidClassnameCharactersUnderscores", "(", "name", "string", ")", "string", "{", "var", "sb", "strings", ".", "Builder", "\n", "for", "_", ",", "c", ":=", "range", "name", "{", "switch", "{", "case", "c", ">=", "'0'", "&&", "c", "<=", "'9'", ":", "sb", ".", "WriteRune", "(", "c", ")", "\n", "case", "c", ">=", "'a'", "&&", "c", "<=", "'z'", ":", "sb", ".", "WriteRune", "(", "c", ")", "\n", "case", "c", ">=", "'A'", "&&", "c", "<=", "'Z'", ":", "sb", ".", "WriteRune", "(", "c", ")", "\n", "default", ":", "sb", ".", "WriteRune", "(", "'_'", ")", "\n", "}", "\n", "}", "\n", "return", "sb", ".", "String", "(", ")", "\n", "}" ]
// Replace invalid identifier characters with an underscore
[ "Replace", "invalid", "identifier", "characters", "with", "an", "underscore" ]
fcf5978a9d1e0d26f3239a013c54dc65dae6c768
https://github.com/envoyproxy/protoc-gen-validate/blob/fcf5978a9d1e0d26f3239a013c54dc65dae6c768/templates/java/register.go#L193-L208
train
envoyproxy/protoc-gen-validate
templates/shared/reflection.go
Has
func Has(msg proto.Message, fld string) bool { val := extractVal(msg) return val.IsValid() && val.FieldByName(fld).IsValid() }
go
func Has(msg proto.Message, fld string) bool { val := extractVal(msg) return val.IsValid() && val.FieldByName(fld).IsValid() }
[ "func", "Has", "(", "msg", "proto", ".", "Message", ",", "fld", "string", ")", "bool", "{", "val", ":=", "extractVal", "(", "msg", ")", "\n", "return", "val", ".", "IsValid", "(", ")", "&&", "val", ".", "FieldByName", "(", "fld", ")", ".", "IsValid", "(", ")", "\n", "}" ]
// Has returns true if the provided Message has the a field fld.
[ "Has", "returns", "true", "if", "the", "provided", "Message", "has", "the", "a", "field", "fld", "." ]
fcf5978a9d1e0d26f3239a013c54dc65dae6c768
https://github.com/envoyproxy/protoc-gen-validate/blob/fcf5978a9d1e0d26f3239a013c54dc65dae6c768/templates/shared/reflection.go#L24-L28
train
envoyproxy/protoc-gen-validate
templates/shared/disabled.go
Disabled
func Disabled(msg pgs.Message) (disabled bool, err error) { _, err = msg.Extension(validate.E_Disabled, &disabled) return }
go
func Disabled(msg pgs.Message) (disabled bool, err error) { _, err = msg.Extension(validate.E_Disabled, &disabled) return }
[ "func", "Disabled", "(", "msg", "pgs", ".", "Message", ")", "(", "disabled", "bool", ",", "err", "error", ")", "{", "_", ",", "err", "=", "msg", ".", "Extension", "(", "validate", ".", "E_Disabled", ",", "&", "disabled", ")", "\n", "return", "\n", "}" ]
// Disabled returns true if validations are disabled for msg
[ "Disabled", "returns", "true", "if", "validations", "are", "disabled", "for", "msg" ]
fcf5978a9d1e0d26f3239a013c54dc65dae6c768
https://github.com/envoyproxy/protoc-gen-validate/blob/fcf5978a9d1e0d26f3239a013c54dc65dae6c768/templates/shared/disabled.go#L9-L12
train
envoyproxy/protoc-gen-validate
templates/shared/disabled.go
RequiredOneOf
func RequiredOneOf(oo pgs.OneOf) (required bool, err error) { _, err = oo.Extension(validate.E_Required, &required) return }
go
func RequiredOneOf(oo pgs.OneOf) (required bool, err error) { _, err = oo.Extension(validate.E_Required, &required) return }
[ "func", "RequiredOneOf", "(", "oo", "pgs", ".", "OneOf", ")", "(", "required", "bool", ",", "err", "error", ")", "{", "_", ",", "err", "=", "oo", ".", "Extension", "(", "validate", ".", "E_Required", ",", "&", "required", ")", "\n", "return", "\n", "}" ]
// RequiredOneOf returns true if the oneof field requires a field to be set
[ "RequiredOneOf", "returns", "true", "if", "the", "oneof", "field", "requires", "a", "field", "to", "be", "set" ]
fcf5978a9d1e0d26f3239a013c54dc65dae6c768
https://github.com/envoyproxy/protoc-gen-validate/blob/fcf5978a9d1e0d26f3239a013c54dc65dae6c768/templates/shared/disabled.go#L15-L18
train
envoyproxy/protoc-gen-validate
templates/shared/well_known.go
Needs
func Needs(m pgs.Message, wk WellKnown) bool { for _, f := range m.Fields() { var rules validate.FieldRules if _, err := f.Extension(validate.E_Rules, &rules); err != nil { continue } switch { case f.Type().IsRepeated() && f.Type().Element().ProtoType() == pgs.StringT: if strRulesNeeds(rules.GetRepeated().GetItems().GetString_(), wk) { return true } case f.Type().IsMap(): if f.Type().Key().ProtoType() == pgs.StringT && strRulesNeeds(rules.GetMap().GetKeys().GetString_(), wk) { return true } if f.Type().Element().ProtoType() == pgs.StringT && strRulesNeeds(rules.GetMap().GetValues().GetString_(), wk) { return true } case f.Type().ProtoType() == pgs.StringT: if strRulesNeeds(rules.GetString_(), wk) { return true } } } return false }
go
func Needs(m pgs.Message, wk WellKnown) bool { for _, f := range m.Fields() { var rules validate.FieldRules if _, err := f.Extension(validate.E_Rules, &rules); err != nil { continue } switch { case f.Type().IsRepeated() && f.Type().Element().ProtoType() == pgs.StringT: if strRulesNeeds(rules.GetRepeated().GetItems().GetString_(), wk) { return true } case f.Type().IsMap(): if f.Type().Key().ProtoType() == pgs.StringT && strRulesNeeds(rules.GetMap().GetKeys().GetString_(), wk) { return true } if f.Type().Element().ProtoType() == pgs.StringT && strRulesNeeds(rules.GetMap().GetValues().GetString_(), wk) { return true } case f.Type().ProtoType() == pgs.StringT: if strRulesNeeds(rules.GetString_(), wk) { return true } } } return false }
[ "func", "Needs", "(", "m", "pgs", ".", "Message", ",", "wk", "WellKnown", ")", "bool", "{", "for", "_", ",", "f", ":=", "range", "m", ".", "Fields", "(", ")", "{", "var", "rules", "validate", ".", "FieldRules", "\n", "if", "_", ",", "err", ":=", "f", ".", "Extension", "(", "validate", ".", "E_Rules", ",", "&", "rules", ")", ";", "err", "!=", "nil", "{", "continue", "\n", "}", "\n\n", "switch", "{", "case", "f", ".", "Type", "(", ")", ".", "IsRepeated", "(", ")", "&&", "f", ".", "Type", "(", ")", ".", "Element", "(", ")", ".", "ProtoType", "(", ")", "==", "pgs", ".", "StringT", ":", "if", "strRulesNeeds", "(", "rules", ".", "GetRepeated", "(", ")", ".", "GetItems", "(", ")", ".", "GetString_", "(", ")", ",", "wk", ")", "{", "return", "true", "\n", "}", "\n", "case", "f", ".", "Type", "(", ")", ".", "IsMap", "(", ")", ":", "if", "f", ".", "Type", "(", ")", ".", "Key", "(", ")", ".", "ProtoType", "(", ")", "==", "pgs", ".", "StringT", "&&", "strRulesNeeds", "(", "rules", ".", "GetMap", "(", ")", ".", "GetKeys", "(", ")", ".", "GetString_", "(", ")", ",", "wk", ")", "{", "return", "true", "\n", "}", "\n", "if", "f", ".", "Type", "(", ")", ".", "Element", "(", ")", ".", "ProtoType", "(", ")", "==", "pgs", ".", "StringT", "&&", "strRulesNeeds", "(", "rules", ".", "GetMap", "(", ")", ".", "GetValues", "(", ")", ".", "GetString_", "(", ")", ",", "wk", ")", "{", "return", "true", "\n", "}", "\n", "case", "f", ".", "Type", "(", ")", ".", "ProtoType", "(", ")", "==", "pgs", ".", "StringT", ":", "if", "strRulesNeeds", "(", "rules", ".", "GetString_", "(", ")", ",", "wk", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// Needs returns true if a well-known string validator is needed for this // message.
[ "Needs", "returns", "true", "if", "a", "well", "-", "known", "string", "validator", "is", "needed", "for", "this", "message", "." ]
fcf5978a9d1e0d26f3239a013c54dc65dae6c768
https://github.com/envoyproxy/protoc-gen-validate/blob/fcf5978a9d1e0d26f3239a013c54dc65dae6c768/templates/shared/well_known.go#L17-L47
train
vishvananda/netlink
addr_linux.go
AddrSubscribe
func AddrSubscribe(ch chan<- AddrUpdate, done <-chan struct{}) error { return addrSubscribeAt(netns.None(), netns.None(), ch, done, nil, false) }
go
func AddrSubscribe(ch chan<- AddrUpdate, done <-chan struct{}) error { return addrSubscribeAt(netns.None(), netns.None(), ch, done, nil, false) }
[ "func", "AddrSubscribe", "(", "ch", "chan", "<-", "AddrUpdate", ",", "done", "<-", "chan", "struct", "{", "}", ")", "error", "{", "return", "addrSubscribeAt", "(", "netns", ".", "None", "(", ")", ",", "netns", ".", "None", "(", ")", ",", "ch", ",", "done", ",", "nil", ",", "false", ")", "\n", "}" ]
// AddrSubscribe takes a chan down which notifications will be sent // when addresses change. Close the 'done' chan to stop subscription.
[ "AddrSubscribe", "takes", "a", "chan", "down", "which", "notifications", "will", "be", "sent", "when", "addresses", "change", ".", "Close", "the", "done", "chan", "to", "stop", "subscription", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/addr_linux.go#L272-L274
train
vishvananda/netlink
addr_linux.go
AddrSubscribeWithOptions
func AddrSubscribeWithOptions(ch chan<- AddrUpdate, done <-chan struct{}, options AddrSubscribeOptions) error { if options.Namespace == nil { none := netns.None() options.Namespace = &none } return addrSubscribeAt(*options.Namespace, netns.None(), ch, done, options.ErrorCallback, options.ListExisting) }
go
func AddrSubscribeWithOptions(ch chan<- AddrUpdate, done <-chan struct{}, options AddrSubscribeOptions) error { if options.Namespace == nil { none := netns.None() options.Namespace = &none } return addrSubscribeAt(*options.Namespace, netns.None(), ch, done, options.ErrorCallback, options.ListExisting) }
[ "func", "AddrSubscribeWithOptions", "(", "ch", "chan", "<-", "AddrUpdate", ",", "done", "<-", "chan", "struct", "{", "}", ",", "options", "AddrSubscribeOptions", ")", "error", "{", "if", "options", ".", "Namespace", "==", "nil", "{", "none", ":=", "netns", ".", "None", "(", ")", "\n", "options", ".", "Namespace", "=", "&", "none", "\n", "}", "\n", "return", "addrSubscribeAt", "(", "*", "options", ".", "Namespace", ",", "netns", ".", "None", "(", ")", ",", "ch", ",", "done", ",", "options", ".", "ErrorCallback", ",", "options", ".", "ListExisting", ")", "\n", "}" ]
// AddrSubscribeWithOptions work like AddrSubscribe but enable to // provide additional options to modify the behavior. Currently, the // namespace can be provided as well as an error callback.
[ "AddrSubscribeWithOptions", "work", "like", "AddrSubscribe", "but", "enable", "to", "provide", "additional", "options", "to", "modify", "the", "behavior", ".", "Currently", "the", "namespace", "can", "be", "provided", "as", "well", "as", "an", "error", "callback", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/addr_linux.go#L293-L299
train
vishvananda/netlink
nl/nl_linux.go
GetIPFamily
func GetIPFamily(ip net.IP) int { if len(ip) <= net.IPv4len { return FAMILY_V4 } if ip.To4() != nil { return FAMILY_V4 } return FAMILY_V6 }
go
func GetIPFamily(ip net.IP) int { if len(ip) <= net.IPv4len { return FAMILY_V4 } if ip.To4() != nil { return FAMILY_V4 } return FAMILY_V6 }
[ "func", "GetIPFamily", "(", "ip", "net", ".", "IP", ")", "int", "{", "if", "len", "(", "ip", ")", "<=", "net", ".", "IPv4len", "{", "return", "FAMILY_V4", "\n", "}", "\n", "if", "ip", ".", "To4", "(", ")", "!=", "nil", "{", "return", "FAMILY_V4", "\n", "}", "\n", "return", "FAMILY_V6", "\n", "}" ]
// GetIPFamily returns the family type of a net.IP.
[ "GetIPFamily", "returns", "the", "family", "type", "of", "a", "net", ".", "IP", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L37-L45
train
vishvananda/netlink
nl/nl_linux.go
NewIfInfomsg
func NewIfInfomsg(family int) *IfInfomsg { return &IfInfomsg{ IfInfomsg: unix.IfInfomsg{ Family: uint8(family), }, } }
go
func NewIfInfomsg(family int) *IfInfomsg { return &IfInfomsg{ IfInfomsg: unix.IfInfomsg{ Family: uint8(family), }, } }
[ "func", "NewIfInfomsg", "(", "family", "int", ")", "*", "IfInfomsg", "{", "return", "&", "IfInfomsg", "{", "IfInfomsg", ":", "unix", ".", "IfInfomsg", "{", "Family", ":", "uint8", "(", "family", ")", ",", "}", ",", "}", "\n", "}" ]
// Create an IfInfomsg with family specified
[ "Create", "an", "IfInfomsg", "with", "family", "specified" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L89-L95
train
vishvananda/netlink
nl/nl_linux.go
NewRtAttr
func NewRtAttr(attrType int, data []byte) *RtAttr { return &RtAttr{ RtAttr: unix.RtAttr{ Type: uint16(attrType), }, children: []NetlinkRequestData{}, Data: data, } }
go
func NewRtAttr(attrType int, data []byte) *RtAttr { return &RtAttr{ RtAttr: unix.RtAttr{ Type: uint16(attrType), }, children: []NetlinkRequestData{}, Data: data, } }
[ "func", "NewRtAttr", "(", "attrType", "int", ",", "data", "[", "]", "byte", ")", "*", "RtAttr", "{", "return", "&", "RtAttr", "{", "RtAttr", ":", "unix", ".", "RtAttr", "{", "Type", ":", "uint16", "(", "attrType", ")", ",", "}", ",", "children", ":", "[", "]", "NetlinkRequestData", "{", "}", ",", "Data", ":", "data", ",", "}", "\n", "}" ]
// Create a new Extended RtAttr object
[ "Create", "a", "new", "Extended", "RtAttr", "object" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L268-L276
train
vishvananda/netlink
nl/nl_linux.go
AddRtAttr
func (a *RtAttr) AddRtAttr(attrType int, data []byte) *RtAttr { attr := NewRtAttr(attrType, data) a.children = append(a.children, attr) return attr }
go
func (a *RtAttr) AddRtAttr(attrType int, data []byte) *RtAttr { attr := NewRtAttr(attrType, data) a.children = append(a.children, attr) return attr }
[ "func", "(", "a", "*", "RtAttr", ")", "AddRtAttr", "(", "attrType", "int", ",", "data", "[", "]", "byte", ")", "*", "RtAttr", "{", "attr", ":=", "NewRtAttr", "(", "attrType", ",", "data", ")", "\n", "a", ".", "children", "=", "append", "(", "a", ".", "children", ",", "attr", ")", "\n", "return", "attr", "\n", "}" ]
// AddRtAttr adds an RtAttr as a child and returns the new attribute
[ "AddRtAttr", "adds", "an", "RtAttr", "as", "a", "child", "and", "returns", "the", "new", "attribute" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L286-L290
train
vishvananda/netlink
nl/nl_linux.go
AddChild
func (a *RtAttr) AddChild(attr NetlinkRequestData) { a.children = append(a.children, attr) }
go
func (a *RtAttr) AddChild(attr NetlinkRequestData) { a.children = append(a.children, attr) }
[ "func", "(", "a", "*", "RtAttr", ")", "AddChild", "(", "attr", "NetlinkRequestData", ")", "{", "a", ".", "children", "=", "append", "(", "a", ".", "children", ",", "attr", ")", "\n", "}" ]
// AddChild adds an existing NetlinkRequestData as a child.
[ "AddChild", "adds", "an", "existing", "NetlinkRequestData", "as", "a", "child", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L293-L295
train
vishvananda/netlink
nl/nl_linux.go
Serialize
func (req *NetlinkRequest) Serialize() []byte { length := unix.SizeofNlMsghdr dataBytes := make([][]byte, len(req.Data)) for i, data := range req.Data { dataBytes[i] = data.Serialize() length = length + len(dataBytes[i]) } length += len(req.RawData) req.Len = uint32(length) b := make([]byte, length) hdr := (*(*[unix.SizeofNlMsghdr]byte)(unsafe.Pointer(req)))[:] next := unix.SizeofNlMsghdr copy(b[0:next], hdr) for _, data := range dataBytes { for _, dataByte := range data { b[next] = dataByte next = next + 1 } } // Add the raw data if any if len(req.RawData) > 0 { copy(b[next:length], req.RawData) } return b }
go
func (req *NetlinkRequest) Serialize() []byte { length := unix.SizeofNlMsghdr dataBytes := make([][]byte, len(req.Data)) for i, data := range req.Data { dataBytes[i] = data.Serialize() length = length + len(dataBytes[i]) } length += len(req.RawData) req.Len = uint32(length) b := make([]byte, length) hdr := (*(*[unix.SizeofNlMsghdr]byte)(unsafe.Pointer(req)))[:] next := unix.SizeofNlMsghdr copy(b[0:next], hdr) for _, data := range dataBytes { for _, dataByte := range data { b[next] = dataByte next = next + 1 } } // Add the raw data if any if len(req.RawData) > 0 { copy(b[next:length], req.RawData) } return b }
[ "func", "(", "req", "*", "NetlinkRequest", ")", "Serialize", "(", ")", "[", "]", "byte", "{", "length", ":=", "unix", ".", "SizeofNlMsghdr", "\n", "dataBytes", ":=", "make", "(", "[", "]", "[", "]", "byte", ",", "len", "(", "req", ".", "Data", ")", ")", "\n", "for", "i", ",", "data", ":=", "range", "req", ".", "Data", "{", "dataBytes", "[", "i", "]", "=", "data", ".", "Serialize", "(", ")", "\n", "length", "=", "length", "+", "len", "(", "dataBytes", "[", "i", "]", ")", "\n", "}", "\n", "length", "+=", "len", "(", "req", ".", "RawData", ")", "\n\n", "req", ".", "Len", "=", "uint32", "(", "length", ")", "\n", "b", ":=", "make", "(", "[", "]", "byte", ",", "length", ")", "\n", "hdr", ":=", "(", "*", "(", "*", "[", "unix", ".", "SizeofNlMsghdr", "]", "byte", ")", "(", "unsafe", ".", "Pointer", "(", "req", ")", ")", ")", "[", ":", "]", "\n", "next", ":=", "unix", ".", "SizeofNlMsghdr", "\n", "copy", "(", "b", "[", "0", ":", "next", "]", ",", "hdr", ")", "\n", "for", "_", ",", "data", ":=", "range", "dataBytes", "{", "for", "_", ",", "dataByte", ":=", "range", "data", "{", "b", "[", "next", "]", "=", "dataByte", "\n", "next", "=", "next", "+", "1", "\n", "}", "\n", "}", "\n", "// Add the raw data if any", "if", "len", "(", "req", ".", "RawData", ")", ">", "0", "{", "copy", "(", "b", "[", "next", ":", "length", "]", ",", "req", ".", "RawData", ")", "\n", "}", "\n", "return", "b", "\n", "}" ]
// Serialize the Netlink Request into a byte array
[ "Serialize", "the", "Netlink", "Request", "into", "a", "byte", "array" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L346-L371
train
vishvananda/netlink
nl/nl_linux.go
AddRawData
func (req *NetlinkRequest) AddRawData(data []byte) { req.RawData = append(req.RawData, data...) }
go
func (req *NetlinkRequest) AddRawData(data []byte) { req.RawData = append(req.RawData, data...) }
[ "func", "(", "req", "*", "NetlinkRequest", ")", "AddRawData", "(", "data", "[", "]", "byte", ")", "{", "req", ".", "RawData", "=", "append", "(", "req", ".", "RawData", ",", "data", "...", ")", "\n", "}" ]
// AddRawData adds raw bytes to the end of the NetlinkRequest object during serialization
[ "AddRawData", "adds", "raw", "bytes", "to", "the", "end", "of", "the", "NetlinkRequest", "object", "during", "serialization" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L378-L380
train
vishvananda/netlink
nl/nl_linux.go
Execute
func (req *NetlinkRequest) Execute(sockType int, resType uint16) ([][]byte, error) { var ( s *NetlinkSocket err error ) if req.Sockets != nil { if sh, ok := req.Sockets[sockType]; ok { s = sh.Socket req.Seq = atomic.AddUint32(&sh.Seq, 1) } } sharedSocket := s != nil if s == nil { s, err = getNetlinkSocket(sockType) if err != nil { return nil, err } defer s.Close() } else { s.Lock() defer s.Unlock() } if err := s.Send(req); err != nil { return nil, err } pid, err := s.GetPid() if err != nil { return nil, err } var res [][]byte done: for { msgs, err := s.Receive() if err != nil { return nil, err } for _, m := range msgs { if m.Header.Seq != req.Seq { if sharedSocket { continue } return nil, fmt.Errorf("Wrong Seq nr %d, expected %d", m.Header.Seq, req.Seq) } if m.Header.Pid != pid { return nil, fmt.Errorf("Wrong pid %d, expected %d", m.Header.Pid, pid) } if m.Header.Type == unix.NLMSG_DONE { break done } if m.Header.Type == unix.NLMSG_ERROR { native := NativeEndian() error := int32(native.Uint32(m.Data[0:4])) if error == 0 { break done } return nil, syscall.Errno(-error) } if resType != 0 && m.Header.Type != resType { continue } res = append(res, m.Data) if m.Header.Flags&unix.NLM_F_MULTI == 0 { break done } } } return res, nil }
go
func (req *NetlinkRequest) Execute(sockType int, resType uint16) ([][]byte, error) { var ( s *NetlinkSocket err error ) if req.Sockets != nil { if sh, ok := req.Sockets[sockType]; ok { s = sh.Socket req.Seq = atomic.AddUint32(&sh.Seq, 1) } } sharedSocket := s != nil if s == nil { s, err = getNetlinkSocket(sockType) if err != nil { return nil, err } defer s.Close() } else { s.Lock() defer s.Unlock() } if err := s.Send(req); err != nil { return nil, err } pid, err := s.GetPid() if err != nil { return nil, err } var res [][]byte done: for { msgs, err := s.Receive() if err != nil { return nil, err } for _, m := range msgs { if m.Header.Seq != req.Seq { if sharedSocket { continue } return nil, fmt.Errorf("Wrong Seq nr %d, expected %d", m.Header.Seq, req.Seq) } if m.Header.Pid != pid { return nil, fmt.Errorf("Wrong pid %d, expected %d", m.Header.Pid, pid) } if m.Header.Type == unix.NLMSG_DONE { break done } if m.Header.Type == unix.NLMSG_ERROR { native := NativeEndian() error := int32(native.Uint32(m.Data[0:4])) if error == 0 { break done } return nil, syscall.Errno(-error) } if resType != 0 && m.Header.Type != resType { continue } res = append(res, m.Data) if m.Header.Flags&unix.NLM_F_MULTI == 0 { break done } } } return res, nil }
[ "func", "(", "req", "*", "NetlinkRequest", ")", "Execute", "(", "sockType", "int", ",", "resType", "uint16", ")", "(", "[", "]", "[", "]", "byte", ",", "error", ")", "{", "var", "(", "s", "*", "NetlinkSocket", "\n", "err", "error", "\n", ")", "\n\n", "if", "req", ".", "Sockets", "!=", "nil", "{", "if", "sh", ",", "ok", ":=", "req", ".", "Sockets", "[", "sockType", "]", ";", "ok", "{", "s", "=", "sh", ".", "Socket", "\n", "req", ".", "Seq", "=", "atomic", ".", "AddUint32", "(", "&", "sh", ".", "Seq", ",", "1", ")", "\n", "}", "\n", "}", "\n", "sharedSocket", ":=", "s", "!=", "nil", "\n\n", "if", "s", "==", "nil", "{", "s", ",", "err", "=", "getNetlinkSocket", "(", "sockType", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "s", ".", "Close", "(", ")", "\n", "}", "else", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n", "}", "\n\n", "if", "err", ":=", "s", ".", "Send", "(", "req", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "pid", ",", "err", ":=", "s", ".", "GetPid", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "res", "[", "]", "[", "]", "byte", "\n\n", "done", ":", "for", "{", "msgs", ",", "err", ":=", "s", ".", "Receive", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "for", "_", ",", "m", ":=", "range", "msgs", "{", "if", "m", ".", "Header", ".", "Seq", "!=", "req", ".", "Seq", "{", "if", "sharedSocket", "{", "continue", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "m", ".", "Header", ".", "Seq", ",", "req", ".", "Seq", ")", "\n", "}", "\n", "if", "m", ".", "Header", ".", "Pid", "!=", "pid", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "m", ".", "Header", ".", "Pid", ",", "pid", ")", "\n", "}", "\n", "if", "m", ".", "Header", ".", "Type", "==", "unix", ".", "NLMSG_DONE", "{", "break", "done", "\n", "}", "\n", "if", "m", ".", "Header", ".", "Type", "==", "unix", ".", "NLMSG_ERROR", "{", "native", ":=", "NativeEndian", "(", ")", "\n", "error", ":=", "int32", "(", "native", ".", "Uint32", "(", "m", ".", "Data", "[", "0", ":", "4", "]", ")", ")", "\n", "if", "error", "==", "0", "{", "break", "done", "\n", "}", "\n", "return", "nil", ",", "syscall", ".", "Errno", "(", "-", "error", ")", "\n", "}", "\n", "if", "resType", "!=", "0", "&&", "m", ".", "Header", ".", "Type", "!=", "resType", "{", "continue", "\n", "}", "\n", "res", "=", "append", "(", "res", ",", "m", ".", "Data", ")", "\n", "if", "m", ".", "Header", ".", "Flags", "&", "unix", ".", "NLM_F_MULTI", "==", "0", "{", "break", "done", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "res", ",", "nil", "\n", "}" ]
// Execute the request against a the given sockType. // Returns a list of netlink messages in serialized format, optionally filtered // by resType.
[ "Execute", "the", "request", "against", "a", "the", "given", "sockType", ".", "Returns", "a", "list", "of", "netlink", "messages", "in", "serialized", "format", "optionally", "filtered", "by", "resType", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L385-L458
train
vishvananda/netlink
nl/nl_linux.go
NewNetlinkRequest
func NewNetlinkRequest(proto, flags int) *NetlinkRequest { return &NetlinkRequest{ NlMsghdr: unix.NlMsghdr{ Len: uint32(unix.SizeofNlMsghdr), Type: uint16(proto), Flags: unix.NLM_F_REQUEST | uint16(flags), Seq: atomic.AddUint32(&nextSeqNr, 1), }, } }
go
func NewNetlinkRequest(proto, flags int) *NetlinkRequest { return &NetlinkRequest{ NlMsghdr: unix.NlMsghdr{ Len: uint32(unix.SizeofNlMsghdr), Type: uint16(proto), Flags: unix.NLM_F_REQUEST | uint16(flags), Seq: atomic.AddUint32(&nextSeqNr, 1), }, } }
[ "func", "NewNetlinkRequest", "(", "proto", ",", "flags", "int", ")", "*", "NetlinkRequest", "{", "return", "&", "NetlinkRequest", "{", "NlMsghdr", ":", "unix", ".", "NlMsghdr", "{", "Len", ":", "uint32", "(", "unix", ".", "SizeofNlMsghdr", ")", ",", "Type", ":", "uint16", "(", "proto", ")", ",", "Flags", ":", "unix", ".", "NLM_F_REQUEST", "|", "uint16", "(", "flags", ")", ",", "Seq", ":", "atomic", ".", "AddUint32", "(", "&", "nextSeqNr", ",", "1", ")", ",", "}", ",", "}", "\n", "}" ]
// Create a new netlink request from proto and flags // Note the Len value will be inaccurate once data is added until // the message is serialized
[ "Create", "a", "new", "netlink", "request", "from", "proto", "and", "flags", "Note", "the", "Len", "value", "will", "be", "inaccurate", "once", "data", "is", "added", "until", "the", "message", "is", "serialized" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L463-L472
train
vishvananda/netlink
nl/nl_linux.go
GetNetlinkSocketAt
func GetNetlinkSocketAt(newNs, curNs netns.NsHandle, protocol int) (*NetlinkSocket, error) { c, err := executeInNetns(newNs, curNs) if err != nil { return nil, err } defer c() return getNetlinkSocket(protocol) }
go
func GetNetlinkSocketAt(newNs, curNs netns.NsHandle, protocol int) (*NetlinkSocket, error) { c, err := executeInNetns(newNs, curNs) if err != nil { return nil, err } defer c() return getNetlinkSocket(protocol) }
[ "func", "GetNetlinkSocketAt", "(", "newNs", ",", "curNs", "netns", ".", "NsHandle", ",", "protocol", "int", ")", "(", "*", "NetlinkSocket", ",", "error", ")", "{", "c", ",", "err", ":=", "executeInNetns", "(", "newNs", ",", "curNs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "c", "(", ")", "\n", "return", "getNetlinkSocket", "(", "protocol", ")", "\n", "}" ]
// GetNetlinkSocketAt opens a netlink socket in the network namespace newNs // and positions the thread back into the network namespace specified by curNs, // when done. If curNs is close, the function derives the current namespace and // moves back into it when done. If newNs is close, the socket will be opened // in the current network namespace.
[ "GetNetlinkSocketAt", "opens", "a", "netlink", "socket", "in", "the", "network", "namespace", "newNs", "and", "positions", "the", "thread", "back", "into", "the", "network", "namespace", "specified", "by", "curNs", "when", "done", ".", "If", "curNs", "is", "close", "the", "function", "derives", "the", "current", "namespace", "and", "moves", "back", "into", "it", "when", "done", ".", "If", "newNs", "is", "close", "the", "socket", "will", "be", "opened", "in", "the", "current", "network", "namespace", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L502-L509
train
vishvananda/netlink
nl/nl_linux.go
SetSendTimeout
func (s *NetlinkSocket) SetSendTimeout(timeout *unix.Timeval) error { // Set a send timeout of SOCKET_SEND_TIMEOUT, this will allow the Send to periodically unblock and avoid that a routine // remains stuck on a send on a closed fd return unix.SetsockoptTimeval(int(s.fd), unix.SOL_SOCKET, unix.SO_SNDTIMEO, timeout) }
go
func (s *NetlinkSocket) SetSendTimeout(timeout *unix.Timeval) error { // Set a send timeout of SOCKET_SEND_TIMEOUT, this will allow the Send to periodically unblock and avoid that a routine // remains stuck on a send on a closed fd return unix.SetsockoptTimeval(int(s.fd), unix.SOL_SOCKET, unix.SO_SNDTIMEO, timeout) }
[ "func", "(", "s", "*", "NetlinkSocket", ")", "SetSendTimeout", "(", "timeout", "*", "unix", ".", "Timeval", ")", "error", "{", "// Set a send timeout of SOCKET_SEND_TIMEOUT, this will allow the Send to periodically unblock and avoid that a routine", "// remains stuck on a send on a closed fd", "return", "unix", ".", "SetsockoptTimeval", "(", "int", "(", "s", ".", "fd", ")", ",", "unix", ".", "SOL_SOCKET", ",", "unix", ".", "SO_SNDTIMEO", ",", "timeout", ")", "\n", "}" ]
// SetSendTimeout allows to set a send timeout on the socket
[ "SetSendTimeout", "allows", "to", "set", "a", "send", "timeout", "on", "the", "socket" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L639-L643
train
vishvananda/netlink
nl/nl_linux.go
SetReceiveTimeout
func (s *NetlinkSocket) SetReceiveTimeout(timeout *unix.Timeval) error { // Set a read timeout of SOCKET_READ_TIMEOUT, this will allow the Read to periodically unblock and avoid that a routine // remains stuck on a recvmsg on a closed fd return unix.SetsockoptTimeval(int(s.fd), unix.SOL_SOCKET, unix.SO_RCVTIMEO, timeout) }
go
func (s *NetlinkSocket) SetReceiveTimeout(timeout *unix.Timeval) error { // Set a read timeout of SOCKET_READ_TIMEOUT, this will allow the Read to periodically unblock and avoid that a routine // remains stuck on a recvmsg on a closed fd return unix.SetsockoptTimeval(int(s.fd), unix.SOL_SOCKET, unix.SO_RCVTIMEO, timeout) }
[ "func", "(", "s", "*", "NetlinkSocket", ")", "SetReceiveTimeout", "(", "timeout", "*", "unix", ".", "Timeval", ")", "error", "{", "// Set a read timeout of SOCKET_READ_TIMEOUT, this will allow the Read to periodically unblock and avoid that a routine", "// remains stuck on a recvmsg on a closed fd", "return", "unix", ".", "SetsockoptTimeval", "(", "int", "(", "s", ".", "fd", ")", ",", "unix", ".", "SOL_SOCKET", ",", "unix", ".", "SO_RCVTIMEO", ",", "timeout", ")", "\n", "}" ]
// SetReceiveTimeout allows to set a receive timeout on the socket
[ "SetReceiveTimeout", "allows", "to", "set", "a", "receive", "timeout", "on", "the", "socket" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L646-L650
train
vishvananda/netlink
neigh_linux.go
NeighListExecute
func (h *Handle) NeighListExecute(msg Ndmsg) ([]Neigh, error) { req := h.newNetlinkRequest(unix.RTM_GETNEIGH, unix.NLM_F_DUMP) req.AddData(&msg) msgs, err := req.Execute(unix.NETLINK_ROUTE, unix.RTM_NEWNEIGH) if err != nil { return nil, err } var res []Neigh for _, m := range msgs { ndm := deserializeNdmsg(m) if msg.Index != 0 && ndm.Index != msg.Index { // Ignore messages from other interfaces continue } neigh, err := NeighDeserialize(m) if err != nil { continue } res = append(res, *neigh) } return res, nil }
go
func (h *Handle) NeighListExecute(msg Ndmsg) ([]Neigh, error) { req := h.newNetlinkRequest(unix.RTM_GETNEIGH, unix.NLM_F_DUMP) req.AddData(&msg) msgs, err := req.Execute(unix.NETLINK_ROUTE, unix.RTM_NEWNEIGH) if err != nil { return nil, err } var res []Neigh for _, m := range msgs { ndm := deserializeNdmsg(m) if msg.Index != 0 && ndm.Index != msg.Index { // Ignore messages from other interfaces continue } neigh, err := NeighDeserialize(m) if err != nil { continue } res = append(res, *neigh) } return res, nil }
[ "func", "(", "h", "*", "Handle", ")", "NeighListExecute", "(", "msg", "Ndmsg", ")", "(", "[", "]", "Neigh", ",", "error", ")", "{", "req", ":=", "h", ".", "newNetlinkRequest", "(", "unix", ".", "RTM_GETNEIGH", ",", "unix", ".", "NLM_F_DUMP", ")", "\n", "req", ".", "AddData", "(", "&", "msg", ")", "\n\n", "msgs", ",", "err", ":=", "req", ".", "Execute", "(", "unix", ".", "NETLINK_ROUTE", ",", "unix", ".", "RTM_NEWNEIGH", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "res", "[", "]", "Neigh", "\n", "for", "_", ",", "m", ":=", "range", "msgs", "{", "ndm", ":=", "deserializeNdmsg", "(", "m", ")", "\n", "if", "msg", ".", "Index", "!=", "0", "&&", "ndm", ".", "Index", "!=", "msg", ".", "Index", "{", "// Ignore messages from other interfaces", "continue", "\n", "}", "\n\n", "neigh", ",", "err", ":=", "NeighDeserialize", "(", "m", ")", "\n", "if", "err", "!=", "nil", "{", "continue", "\n", "}", "\n\n", "res", "=", "append", "(", "res", ",", "*", "neigh", ")", "\n", "}", "\n\n", "return", "res", ",", "nil", "\n", "}" ]
// NeighListExecute returns a list of neighbour entries filtered by link, ip family, flag and state.
[ "NeighListExecute", "returns", "a", "list", "of", "neighbour", "entries", "filtered", "by", "link", "ip", "family", "flag", "and", "state", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh_linux.go#L221-L247
train
vishvananda/netlink
neigh_linux.go
NeighSubscribe
func NeighSubscribe(ch chan<- NeighUpdate, done <-chan struct{}) error { return neighSubscribeAt(netns.None(), netns.None(), ch, done, nil, false) }
go
func NeighSubscribe(ch chan<- NeighUpdate, done <-chan struct{}) error { return neighSubscribeAt(netns.None(), netns.None(), ch, done, nil, false) }
[ "func", "NeighSubscribe", "(", "ch", "chan", "<-", "NeighUpdate", ",", "done", "<-", "chan", "struct", "{", "}", ")", "error", "{", "return", "neighSubscribeAt", "(", "netns", ".", "None", "(", ")", ",", "netns", ".", "None", "(", ")", ",", "ch", ",", "done", ",", "nil", ",", "false", ")", "\n", "}" ]
// NeighSubscribe takes a chan down which notifications will be sent // when neighbors are added or deleted. Close the 'done' chan to stop subscription.
[ "NeighSubscribe", "takes", "a", "chan", "down", "which", "notifications", "will", "be", "sent", "when", "neighbors", "are", "added", "or", "deleted", ".", "Close", "the", "done", "chan", "to", "stop", "subscription", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh_linux.go#L299-L301
train
vishvananda/netlink
neigh_linux.go
NeighSubscribeWithOptions
func NeighSubscribeWithOptions(ch chan<- NeighUpdate, done <-chan struct{}, options NeighSubscribeOptions) error { if options.Namespace == nil { none := netns.None() options.Namespace = &none } return neighSubscribeAt(*options.Namespace, netns.None(), ch, done, options.ErrorCallback, options.ListExisting) }
go
func NeighSubscribeWithOptions(ch chan<- NeighUpdate, done <-chan struct{}, options NeighSubscribeOptions) error { if options.Namespace == nil { none := netns.None() options.Namespace = &none } return neighSubscribeAt(*options.Namespace, netns.None(), ch, done, options.ErrorCallback, options.ListExisting) }
[ "func", "NeighSubscribeWithOptions", "(", "ch", "chan", "<-", "NeighUpdate", ",", "done", "<-", "chan", "struct", "{", "}", ",", "options", "NeighSubscribeOptions", ")", "error", "{", "if", "options", ".", "Namespace", "==", "nil", "{", "none", ":=", "netns", ".", "None", "(", ")", "\n", "options", ".", "Namespace", "=", "&", "none", "\n", "}", "\n", "return", "neighSubscribeAt", "(", "*", "options", ".", "Namespace", ",", "netns", ".", "None", "(", ")", ",", "ch", ",", "done", ",", "options", ".", "ErrorCallback", ",", "options", ".", "ListExisting", ")", "\n", "}" ]
// NeighSubscribeWithOptions work like NeighSubscribe but enable to // provide additional options to modify the behavior. Currently, the // namespace can be provided as well as an error callback.
[ "NeighSubscribeWithOptions", "work", "like", "NeighSubscribe", "but", "enable", "to", "provide", "additional", "options", "to", "modify", "the", "behavior", ".", "Currently", "the", "namespace", "can", "be", "provided", "as", "well", "as", "an", "error", "callback", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh_linux.go#L320-L326
train
vishvananda/netlink
conntrack_linux.go
AddIP
func (f *ConntrackFilter) AddIP(tp ConntrackFilterType, ip net.IP) error { if f.ipFilter == nil { f.ipFilter = make(map[ConntrackFilterType]net.IP) } if _, ok := f.ipFilter[tp]; ok { return errors.New("Filter attribute already present") } f.ipFilter[tp] = ip return nil }
go
func (f *ConntrackFilter) AddIP(tp ConntrackFilterType, ip net.IP) error { if f.ipFilter == nil { f.ipFilter = make(map[ConntrackFilterType]net.IP) } if _, ok := f.ipFilter[tp]; ok { return errors.New("Filter attribute already present") } f.ipFilter[tp] = ip return nil }
[ "func", "(", "f", "*", "ConntrackFilter", ")", "AddIP", "(", "tp", "ConntrackFilterType", ",", "ip", "net", ".", "IP", ")", "error", "{", "if", "f", ".", "ipFilter", "==", "nil", "{", "f", ".", "ipFilter", "=", "make", "(", "map", "[", "ConntrackFilterType", "]", "net", ".", "IP", ")", "\n", "}", "\n", "if", "_", ",", "ok", ":=", "f", ".", "ipFilter", "[", "tp", "]", ";", "ok", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "f", ".", "ipFilter", "[", "tp", "]", "=", "ip", "\n", "return", "nil", "\n", "}" ]
// AddIP adds an IP to the conntrack filter
[ "AddIP", "adds", "an", "IP", "to", "the", "conntrack", "filter" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/conntrack_linux.go#L350-L359
train
vishvananda/netlink
conntrack_linux.go
MatchConntrackFlow
func (f *ConntrackFilter) MatchConntrackFlow(flow *ConntrackFlow) bool { if len(f.ipFilter) == 0 { // empty filter always not match return false } match := true // -orig-src ip Source address from original direction if elem, found := f.ipFilter[ConntrackOrigSrcIP]; found { match = match && elem.Equal(flow.Forward.SrcIP) } // -orig-dst ip Destination address from original direction if elem, found := f.ipFilter[ConntrackOrigDstIP]; match && found { match = match && elem.Equal(flow.Forward.DstIP) } // -src-nat ip Source NAT ip if elem, found := f.ipFilter[ConntrackReplySrcIP]; match && found { match = match && elem.Equal(flow.Reverse.SrcIP) } // -dst-nat ip Destination NAT ip if elem, found := f.ipFilter[ConntrackReplyDstIP]; match && found { match = match && elem.Equal(flow.Reverse.DstIP) } // Match source or destination reply IP if elem, found := f.ipFilter[ConntrackReplyAnyIP]; match && found { match = match && (elem.Equal(flow.Reverse.SrcIP) || elem.Equal(flow.Reverse.DstIP)) } return match }
go
func (f *ConntrackFilter) MatchConntrackFlow(flow *ConntrackFlow) bool { if len(f.ipFilter) == 0 { // empty filter always not match return false } match := true // -orig-src ip Source address from original direction if elem, found := f.ipFilter[ConntrackOrigSrcIP]; found { match = match && elem.Equal(flow.Forward.SrcIP) } // -orig-dst ip Destination address from original direction if elem, found := f.ipFilter[ConntrackOrigDstIP]; match && found { match = match && elem.Equal(flow.Forward.DstIP) } // -src-nat ip Source NAT ip if elem, found := f.ipFilter[ConntrackReplySrcIP]; match && found { match = match && elem.Equal(flow.Reverse.SrcIP) } // -dst-nat ip Destination NAT ip if elem, found := f.ipFilter[ConntrackReplyDstIP]; match && found { match = match && elem.Equal(flow.Reverse.DstIP) } // Match source or destination reply IP if elem, found := f.ipFilter[ConntrackReplyAnyIP]; match && found { match = match && (elem.Equal(flow.Reverse.SrcIP) || elem.Equal(flow.Reverse.DstIP)) } return match }
[ "func", "(", "f", "*", "ConntrackFilter", ")", "MatchConntrackFlow", "(", "flow", "*", "ConntrackFlow", ")", "bool", "{", "if", "len", "(", "f", ".", "ipFilter", ")", "==", "0", "{", "// empty filter always not match", "return", "false", "\n", "}", "\n\n", "match", ":=", "true", "\n", "// -orig-src ip Source address from original direction", "if", "elem", ",", "found", ":=", "f", ".", "ipFilter", "[", "ConntrackOrigSrcIP", "]", ";", "found", "{", "match", "=", "match", "&&", "elem", ".", "Equal", "(", "flow", ".", "Forward", ".", "SrcIP", ")", "\n", "}", "\n\n", "// -orig-dst ip Destination address from original direction", "if", "elem", ",", "found", ":=", "f", ".", "ipFilter", "[", "ConntrackOrigDstIP", "]", ";", "match", "&&", "found", "{", "match", "=", "match", "&&", "elem", ".", "Equal", "(", "flow", ".", "Forward", ".", "DstIP", ")", "\n", "}", "\n\n", "// -src-nat ip Source NAT ip", "if", "elem", ",", "found", ":=", "f", ".", "ipFilter", "[", "ConntrackReplySrcIP", "]", ";", "match", "&&", "found", "{", "match", "=", "match", "&&", "elem", ".", "Equal", "(", "flow", ".", "Reverse", ".", "SrcIP", ")", "\n", "}", "\n\n", "// -dst-nat ip Destination NAT ip", "if", "elem", ",", "found", ":=", "f", ".", "ipFilter", "[", "ConntrackReplyDstIP", "]", ";", "match", "&&", "found", "{", "match", "=", "match", "&&", "elem", ".", "Equal", "(", "flow", ".", "Reverse", ".", "DstIP", ")", "\n", "}", "\n\n", "// Match source or destination reply IP", "if", "elem", ",", "found", ":=", "f", ".", "ipFilter", "[", "ConntrackReplyAnyIP", "]", ";", "match", "&&", "found", "{", "match", "=", "match", "&&", "(", "elem", ".", "Equal", "(", "flow", ".", "Reverse", ".", "SrcIP", ")", "||", "elem", ".", "Equal", "(", "flow", ".", "Reverse", ".", "DstIP", ")", ")", "\n", "}", "\n\n", "return", "match", "\n", "}" ]
// MatchConntrackFlow applies the filter to the flow and returns true if the flow matches the filter // false otherwise
[ "MatchConntrackFlow", "applies", "the", "filter", "to", "the", "flow", "and", "returns", "true", "if", "the", "flow", "matches", "the", "filter", "false", "otherwise" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/conntrack_linux.go#L363-L396
train
vishvananda/netlink
protinfo.go
String
func (prot *Protinfo) String() string { if prot == nil { return "<nil>" } var boolStrings []string if prot.Hairpin { boolStrings = append(boolStrings, "Hairpin") } if prot.Guard { boolStrings = append(boolStrings, "Guard") } if prot.FastLeave { boolStrings = append(boolStrings, "FastLeave") } if prot.RootBlock { boolStrings = append(boolStrings, "RootBlock") } if prot.Learning { boolStrings = append(boolStrings, "Learning") } if prot.Flood { boolStrings = append(boolStrings, "Flood") } if prot.ProxyArp { boolStrings = append(boolStrings, "ProxyArp") } if prot.ProxyArpWiFi { boolStrings = append(boolStrings, "ProxyArpWiFi") } return strings.Join(boolStrings, " ") }
go
func (prot *Protinfo) String() string { if prot == nil { return "<nil>" } var boolStrings []string if prot.Hairpin { boolStrings = append(boolStrings, "Hairpin") } if prot.Guard { boolStrings = append(boolStrings, "Guard") } if prot.FastLeave { boolStrings = append(boolStrings, "FastLeave") } if prot.RootBlock { boolStrings = append(boolStrings, "RootBlock") } if prot.Learning { boolStrings = append(boolStrings, "Learning") } if prot.Flood { boolStrings = append(boolStrings, "Flood") } if prot.ProxyArp { boolStrings = append(boolStrings, "ProxyArp") } if prot.ProxyArpWiFi { boolStrings = append(boolStrings, "ProxyArpWiFi") } return strings.Join(boolStrings, " ") }
[ "func", "(", "prot", "*", "Protinfo", ")", "String", "(", ")", "string", "{", "if", "prot", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n\n", "var", "boolStrings", "[", "]", "string", "\n", "if", "prot", ".", "Hairpin", "{", "boolStrings", "=", "append", "(", "boolStrings", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "prot", ".", "Guard", "{", "boolStrings", "=", "append", "(", "boolStrings", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "prot", ".", "FastLeave", "{", "boolStrings", "=", "append", "(", "boolStrings", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "prot", ".", "RootBlock", "{", "boolStrings", "=", "append", "(", "boolStrings", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "prot", ".", "Learning", "{", "boolStrings", "=", "append", "(", "boolStrings", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "prot", ".", "Flood", "{", "boolStrings", "=", "append", "(", "boolStrings", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "prot", ".", "ProxyArp", "{", "boolStrings", "=", "append", "(", "boolStrings", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "prot", ".", "ProxyArpWiFi", "{", "boolStrings", "=", "append", "(", "boolStrings", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "boolStrings", ",", "\"", "\"", ")", "\n", "}" ]
// String returns a list of enabled flags
[ "String", "returns", "a", "list", "of", "enabled", "flags" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/protinfo.go#L20-L51
train
vishvananda/netlink
class.go
Attrs
func (c *ServiceCurve) Attrs() (uint32, uint32, uint32) { return c.m1, c.d, c.m2 }
go
func (c *ServiceCurve) Attrs() (uint32, uint32, uint32) { return c.m1, c.d, c.m2 }
[ "func", "(", "c", "*", "ServiceCurve", ")", "Attrs", "(", ")", "(", "uint32", ",", "uint32", ",", "uint32", ")", "{", "return", "c", ".", "m1", ",", "c", ".", "d", ",", "c", ".", "m2", "\n", "}" ]
// Attrs return the parameters of the service curve
[ "Attrs", "return", "the", "parameters", "of", "the", "service", "curve" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/class.go#L143-L145
train
vishvananda/netlink
class.go
SetRsc
func (hfsc *HfscClass) SetRsc(m1 uint32, d uint32, m2 uint32) { hfsc.Rsc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8} }
go
func (hfsc *HfscClass) SetRsc(m1 uint32, d uint32, m2 uint32) { hfsc.Rsc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8} }
[ "func", "(", "hfsc", "*", "HfscClass", ")", "SetRsc", "(", "m1", "uint32", ",", "d", "uint32", ",", "m2", "uint32", ")", "{", "hfsc", ".", "Rsc", "=", "ServiceCurve", "{", "m1", ":", "m1", "/", "8", ",", "d", ":", "d", ",", "m2", ":", "m2", "/", "8", "}", "\n", "}" ]
// SetRsc sets the Rsc curve
[ "SetRsc", "sets", "the", "Rsc", "curve" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/class.go#L166-L168
train
vishvananda/netlink
class.go
SetSC
func (hfsc *HfscClass) SetSC(m1 uint32, d uint32, m2 uint32) { hfsc.Rsc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8} hfsc.Fsc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8} }
go
func (hfsc *HfscClass) SetSC(m1 uint32, d uint32, m2 uint32) { hfsc.Rsc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8} hfsc.Fsc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8} }
[ "func", "(", "hfsc", "*", "HfscClass", ")", "SetSC", "(", "m1", "uint32", ",", "d", "uint32", ",", "m2", "uint32", ")", "{", "hfsc", ".", "Rsc", "=", "ServiceCurve", "{", "m1", ":", "m1", "/", "8", ",", "d", ":", "d", ",", "m2", ":", "m2", "/", "8", "}", "\n", "hfsc", ".", "Fsc", "=", "ServiceCurve", "{", "m1", ":", "m1", "/", "8", ",", "d", ":", "d", ",", "m2", ":", "m2", "/", "8", "}", "\n", "}" ]
// SetSC implements the SC from the tc CLI
[ "SetSC", "implements", "the", "SC", "from", "the", "tc", "CLI" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/class.go#L171-L174
train
vishvananda/netlink
class.go
SetUL
func (hfsc *HfscClass) SetUL(m1 uint32, d uint32, m2 uint32) { hfsc.Usc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8} }
go
func (hfsc *HfscClass) SetUL(m1 uint32, d uint32, m2 uint32) { hfsc.Usc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8} }
[ "func", "(", "hfsc", "*", "HfscClass", ")", "SetUL", "(", "m1", "uint32", ",", "d", "uint32", ",", "m2", "uint32", ")", "{", "hfsc", ".", "Usc", "=", "ServiceCurve", "{", "m1", ":", "m1", "/", "8", ",", "d", ":", "d", ",", "m2", ":", "m2", "/", "8", "}", "\n", "}" ]
// SetUL implements the UL from the tc CLI
[ "SetUL", "implements", "the", "UL", "from", "the", "tc", "CLI" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/class.go#L177-L179
train
vishvananda/netlink
class.go
SetLS
func (hfsc *HfscClass) SetLS(m1 uint32, d uint32, m2 uint32) { hfsc.Fsc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8} }
go
func (hfsc *HfscClass) SetLS(m1 uint32, d uint32, m2 uint32) { hfsc.Fsc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8} }
[ "func", "(", "hfsc", "*", "HfscClass", ")", "SetLS", "(", "m1", "uint32", ",", "d", "uint32", ",", "m2", "uint32", ")", "{", "hfsc", ".", "Fsc", "=", "ServiceCurve", "{", "m1", ":", "m1", "/", "8", ",", "d", ":", "d", ",", "m2", ":", "m2", "/", "8", "}", "\n", "}" ]
// SetLS implements the LS from the tc CLI
[ "SetLS", "implements", "the", "LS", "from", "the", "tc", "CLI" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/class.go#L182-L184
train
vishvananda/netlink
class.go
NewHfscClass
func NewHfscClass(attrs ClassAttrs) *HfscClass { return &HfscClass{ ClassAttrs: attrs, Rsc: ServiceCurve{}, Fsc: ServiceCurve{}, Usc: ServiceCurve{}, } }
go
func NewHfscClass(attrs ClassAttrs) *HfscClass { return &HfscClass{ ClassAttrs: attrs, Rsc: ServiceCurve{}, Fsc: ServiceCurve{}, Usc: ServiceCurve{}, } }
[ "func", "NewHfscClass", "(", "attrs", "ClassAttrs", ")", "*", "HfscClass", "{", "return", "&", "HfscClass", "{", "ClassAttrs", ":", "attrs", ",", "Rsc", ":", "ServiceCurve", "{", "}", ",", "Fsc", ":", "ServiceCurve", "{", "}", ",", "Usc", ":", "ServiceCurve", "{", "}", ",", "}", "\n", "}" ]
// NewHfscClass returns a new HFSC struct with the set parameters
[ "NewHfscClass", "returns", "a", "new", "HFSC", "struct", "with", "the", "set", "parameters" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/class.go#L187-L194
train
vishvananda/netlink
link.go
StringToBondMode
func StringToBondMode(s string) BondMode { mode, ok := StringToBondModeMap[s] if !ok { return BOND_MODE_UNKNOWN } return mode }
go
func StringToBondMode(s string) BondMode { mode, ok := StringToBondModeMap[s] if !ok { return BOND_MODE_UNKNOWN } return mode }
[ "func", "StringToBondMode", "(", "s", "string", ")", "BondMode", "{", "mode", ",", "ok", ":=", "StringToBondModeMap", "[", "s", "]", "\n", "if", "!", "ok", "{", "return", "BOND_MODE_UNKNOWN", "\n", "}", "\n", "return", "mode", "\n", "}" ]
// StringToBondMode returns bond mode, or uknonw is the s is invalid.
[ "StringToBondMode", "returns", "bond", "mode", "or", "uknonw", "is", "the", "s", "is", "invalid", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link.go#L420-L426
train
vishvananda/netlink
link.go
StringToBondXmitHashPolicy
func StringToBondXmitHashPolicy(s string) BondXmitHashPolicy { lacp, ok := StringToBondXmitHashPolicyMap[s] if !ok { return BOND_XMIT_HASH_POLICY_UNKNOWN } return lacp }
go
func StringToBondXmitHashPolicy(s string) BondXmitHashPolicy { lacp, ok := StringToBondXmitHashPolicyMap[s] if !ok { return BOND_XMIT_HASH_POLICY_UNKNOWN } return lacp }
[ "func", "StringToBondXmitHashPolicy", "(", "s", "string", ")", "BondXmitHashPolicy", "{", "lacp", ",", "ok", ":=", "StringToBondXmitHashPolicyMap", "[", "s", "]", "\n", "if", "!", "ok", "{", "return", "BOND_XMIT_HASH_POLICY_UNKNOWN", "\n", "}", "\n", "return", "lacp", "\n", "}" ]
// StringToBondXmitHashPolicy returns bond lacp arte, or uknonw is the s is invalid.
[ "StringToBondXmitHashPolicy", "returns", "bond", "lacp", "arte", "or", "uknonw", "is", "the", "s", "is", "invalid", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link.go#L511-L517
train
vishvananda/netlink
link.go
StringToBondLacpRate
func StringToBondLacpRate(s string) BondLacpRate { lacp, ok := StringToBondLacpRateMap[s] if !ok { return BOND_LACP_RATE_UNKNOWN } return lacp }
go
func StringToBondLacpRate(s string) BondLacpRate { lacp, ok := StringToBondLacpRateMap[s] if !ok { return BOND_LACP_RATE_UNKNOWN } return lacp }
[ "func", "StringToBondLacpRate", "(", "s", "string", ")", "BondLacpRate", "{", "lacp", ",", "ok", ":=", "StringToBondLacpRateMap", "[", "s", "]", "\n", "if", "!", "ok", "{", "return", "BOND_LACP_RATE_UNKNOWN", "\n", "}", "\n", "return", "lacp", "\n", "}" ]
// StringToBondLacpRate returns bond lacp arte, or uknonw is the s is invalid.
[ "StringToBondLacpRate", "returns", "bond", "lacp", "arte", "or", "uknonw", "is", "the", "s", "is", "invalid", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link.go#L556-L562
train
vishvananda/netlink
devlink_linux.go
DevLinkGetDeviceList
func (h *Handle) DevLinkGetDeviceList() ([]*DevlinkDevice, error) { f, err := h.GenlFamilyGet(nl.GENL_DEVLINK_NAME) if err != nil { return nil, err } msg := &nl.Genlmsg{ Command: nl.DEVLINK_CMD_GET, Version: nl.GENL_DEVLINK_VERSION, } req := h.newNetlinkRequest(int(f.ID), unix.NLM_F_REQUEST|unix.NLM_F_ACK|unix.NLM_F_DUMP) req.AddData(msg) msgs, err := req.Execute(unix.NETLINK_GENERIC, 0) if err != nil { return nil, err } devices, err := parseDevLinkDeviceList(msgs) if err != nil { return nil, err } for _, d := range devices { h.getEswitchAttrs(f, d) } return devices, nil }
go
func (h *Handle) DevLinkGetDeviceList() ([]*DevlinkDevice, error) { f, err := h.GenlFamilyGet(nl.GENL_DEVLINK_NAME) if err != nil { return nil, err } msg := &nl.Genlmsg{ Command: nl.DEVLINK_CMD_GET, Version: nl.GENL_DEVLINK_VERSION, } req := h.newNetlinkRequest(int(f.ID), unix.NLM_F_REQUEST|unix.NLM_F_ACK|unix.NLM_F_DUMP) req.AddData(msg) msgs, err := req.Execute(unix.NETLINK_GENERIC, 0) if err != nil { return nil, err } devices, err := parseDevLinkDeviceList(msgs) if err != nil { return nil, err } for _, d := range devices { h.getEswitchAttrs(f, d) } return devices, nil }
[ "func", "(", "h", "*", "Handle", ")", "DevLinkGetDeviceList", "(", ")", "(", "[", "]", "*", "DevlinkDevice", ",", "error", ")", "{", "f", ",", "err", ":=", "h", ".", "GenlFamilyGet", "(", "nl", ".", "GENL_DEVLINK_NAME", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "msg", ":=", "&", "nl", ".", "Genlmsg", "{", "Command", ":", "nl", ".", "DEVLINK_CMD_GET", ",", "Version", ":", "nl", ".", "GENL_DEVLINK_VERSION", ",", "}", "\n", "req", ":=", "h", ".", "newNetlinkRequest", "(", "int", "(", "f", ".", "ID", ")", ",", "unix", ".", "NLM_F_REQUEST", "|", "unix", ".", "NLM_F_ACK", "|", "unix", ".", "NLM_F_DUMP", ")", "\n", "req", ".", "AddData", "(", "msg", ")", "\n", "msgs", ",", "err", ":=", "req", ".", "Execute", "(", "unix", ".", "NETLINK_GENERIC", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "devices", ",", "err", ":=", "parseDevLinkDeviceList", "(", "msgs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "for", "_", ",", "d", ":=", "range", "devices", "{", "h", ".", "getEswitchAttrs", "(", "f", ",", "d", ")", "\n", "}", "\n", "return", "devices", ",", "nil", "\n", "}" ]
// DevLinkGetDeviceList provides a pointer to devlink devices and nil error, // otherwise returns an error code.
[ "DevLinkGetDeviceList", "provides", "a", "pointer", "to", "devlink", "devices", "and", "nil", "error", "otherwise", "returns", "an", "error", "code", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/devlink_linux.go#L148-L172
train
vishvananda/netlink
rdma_link_linux.go
RdmaLinkByName
func (h *Handle) RdmaLinkByName(name string) (*RdmaLink, error) { proto := getProtoField(nl.RDMA_NL_NLDEV, nl.RDMA_NLDEV_CMD_GET) req := h.newNetlinkRequest(proto, unix.NLM_F_ACK|unix.NLM_F_DUMP) return execRdmaGetLink(req, name) }
go
func (h *Handle) RdmaLinkByName(name string) (*RdmaLink, error) { proto := getProtoField(nl.RDMA_NL_NLDEV, nl.RDMA_NLDEV_CMD_GET) req := h.newNetlinkRequest(proto, unix.NLM_F_ACK|unix.NLM_F_DUMP) return execRdmaGetLink(req, name) }
[ "func", "(", "h", "*", "Handle", ")", "RdmaLinkByName", "(", "name", "string", ")", "(", "*", "RdmaLink", ",", "error", ")", "{", "proto", ":=", "getProtoField", "(", "nl", ".", "RDMA_NL_NLDEV", ",", "nl", ".", "RDMA_NLDEV_CMD_GET", ")", "\n", "req", ":=", "h", ".", "newNetlinkRequest", "(", "proto", ",", "unix", ".", "NLM_F_ACK", "|", "unix", ".", "NLM_F_DUMP", ")", "\n\n", "return", "execRdmaGetLink", "(", "req", ",", "name", ")", "\n", "}" ]
// RdmaLinkByName finds a link by name and returns a pointer to the object if // found and nil error, otherwise returns error code.
[ "RdmaLinkByName", "finds", "a", "link", "by", "name", "and", "returns", "a", "pointer", "to", "the", "object", "if", "found", "and", "nil", "error", "otherwise", "returns", "error", "code", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/rdma_link_linux.go#L112-L118
train
vishvananda/netlink
netlink.go
NewIPNet
func NewIPNet(ip net.IP) *net.IPNet { if ip.To4() != nil { return &net.IPNet{IP: ip, Mask: net.CIDRMask(32, 32)} } return &net.IPNet{IP: ip, Mask: net.CIDRMask(128, 128)} }
go
func NewIPNet(ip net.IP) *net.IPNet { if ip.To4() != nil { return &net.IPNet{IP: ip, Mask: net.CIDRMask(32, 32)} } return &net.IPNet{IP: ip, Mask: net.CIDRMask(128, 128)} }
[ "func", "NewIPNet", "(", "ip", "net", ".", "IP", ")", "*", "net", ".", "IPNet", "{", "if", "ip", ".", "To4", "(", ")", "!=", "nil", "{", "return", "&", "net", ".", "IPNet", "{", "IP", ":", "ip", ",", "Mask", ":", "net", ".", "CIDRMask", "(", "32", ",", "32", ")", "}", "\n", "}", "\n", "return", "&", "net", ".", "IPNet", "{", "IP", ":", "ip", ",", "Mask", ":", "net", ".", "CIDRMask", "(", "128", ",", "128", ")", "}", "\n", "}" ]
// NewIPNet generates an IPNet from an ip address using a netmask of 32 or 128.
[ "NewIPNet", "generates", "an", "IPNet", "from", "an", "ip", "address", "using", "a", "netmask", "of", "32", "or", "128", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/netlink.go#L35-L40
train
vishvananda/netlink
link_linux.go
LinkSetVfGUID
func (h *Handle) LinkSetVfGUID(link Link, vf int, vfGuid net.HardwareAddr, guidType int) error { var err error var guid uint64 buf := bytes.NewBuffer(vfGuid) err = binary.Read(buf, binary.LittleEndian, &guid) if err != nil { return err } base := link.Attrs() h.ensureIndex(base) req := h.newNetlinkRequest(unix.RTM_SETLINK, unix.NLM_F_ACK) msg := nl.NewIfInfomsg(unix.AF_UNSPEC) msg.Index = int32(base.Index) req.AddData(msg) data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil) info := data.AddRtAttr(nl.IFLA_VF_INFO, nil) vfmsg := nl.VfGUID{ Vf: uint32(vf), GUID: guid, } info.AddRtAttr(guidType, vfmsg.Serialize()) req.AddData(data) _, err = req.Execute(unix.NETLINK_ROUTE, 0) return err }
go
func (h *Handle) LinkSetVfGUID(link Link, vf int, vfGuid net.HardwareAddr, guidType int) error { var err error var guid uint64 buf := bytes.NewBuffer(vfGuid) err = binary.Read(buf, binary.LittleEndian, &guid) if err != nil { return err } base := link.Attrs() h.ensureIndex(base) req := h.newNetlinkRequest(unix.RTM_SETLINK, unix.NLM_F_ACK) msg := nl.NewIfInfomsg(unix.AF_UNSPEC) msg.Index = int32(base.Index) req.AddData(msg) data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil) info := data.AddRtAttr(nl.IFLA_VF_INFO, nil) vfmsg := nl.VfGUID{ Vf: uint32(vf), GUID: guid, } info.AddRtAttr(guidType, vfmsg.Serialize()) req.AddData(data) _, err = req.Execute(unix.NETLINK_ROUTE, 0) return err }
[ "func", "(", "h", "*", "Handle", ")", "LinkSetVfGUID", "(", "link", "Link", ",", "vf", "int", ",", "vfGuid", "net", ".", "HardwareAddr", ",", "guidType", "int", ")", "error", "{", "var", "err", "error", "\n", "var", "guid", "uint64", "\n\n", "buf", ":=", "bytes", ".", "NewBuffer", "(", "vfGuid", ")", "\n", "err", "=", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "guid", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "base", ":=", "link", ".", "Attrs", "(", ")", "\n", "h", ".", "ensureIndex", "(", "base", ")", "\n", "req", ":=", "h", ".", "newNetlinkRequest", "(", "unix", ".", "RTM_SETLINK", ",", "unix", ".", "NLM_F_ACK", ")", "\n\n", "msg", ":=", "nl", ".", "NewIfInfomsg", "(", "unix", ".", "AF_UNSPEC", ")", "\n", "msg", ".", "Index", "=", "int32", "(", "base", ".", "Index", ")", "\n", "req", ".", "AddData", "(", "msg", ")", "\n\n", "data", ":=", "nl", ".", "NewRtAttr", "(", "unix", ".", "IFLA_VFINFO_LIST", ",", "nil", ")", "\n", "info", ":=", "data", ".", "AddRtAttr", "(", "nl", ".", "IFLA_VF_INFO", ",", "nil", ")", "\n", "vfmsg", ":=", "nl", ".", "VfGUID", "{", "Vf", ":", "uint32", "(", "vf", ")", ",", "GUID", ":", "guid", ",", "}", "\n", "info", ".", "AddRtAttr", "(", "guidType", ",", "vfmsg", ".", "Serialize", "(", ")", ")", "\n", "req", ".", "AddData", "(", "data", ")", "\n\n", "_", ",", "err", "=", "req", ".", "Execute", "(", "unix", ".", "NETLINK_ROUTE", ",", "0", ")", "\n", "return", "err", "\n", "}" ]
// LinkSetVfGUID sets the node or port GUID of a vf for the link.
[ "LinkSetVfGUID", "sets", "the", "node", "or", "port", "GUID", "of", "a", "vf", "for", "the", "link", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L579-L608
train
vishvananda/netlink
link_linux.go
LinkByName
func (h *Handle) LinkByName(name string) (Link, error) { if h.lookupByDump { return h.linkByNameDump(name) } req := h.newNetlinkRequest(unix.RTM_GETLINK, unix.NLM_F_ACK) msg := nl.NewIfInfomsg(unix.AF_UNSPEC) req.AddData(msg) attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF)) req.AddData(attr) nameData := nl.NewRtAttr(unix.IFLA_IFNAME, nl.ZeroTerminated(name)) req.AddData(nameData) link, err := execGetLink(req) if err == unix.EINVAL { // older kernels don't support looking up via IFLA_IFNAME // so fall back to dumping all links h.lookupByDump = true return h.linkByNameDump(name) } return link, err }
go
func (h *Handle) LinkByName(name string) (Link, error) { if h.lookupByDump { return h.linkByNameDump(name) } req := h.newNetlinkRequest(unix.RTM_GETLINK, unix.NLM_F_ACK) msg := nl.NewIfInfomsg(unix.AF_UNSPEC) req.AddData(msg) attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF)) req.AddData(attr) nameData := nl.NewRtAttr(unix.IFLA_IFNAME, nl.ZeroTerminated(name)) req.AddData(nameData) link, err := execGetLink(req) if err == unix.EINVAL { // older kernels don't support looking up via IFLA_IFNAME // so fall back to dumping all links h.lookupByDump = true return h.linkByNameDump(name) } return link, err }
[ "func", "(", "h", "*", "Handle", ")", "LinkByName", "(", "name", "string", ")", "(", "Link", ",", "error", ")", "{", "if", "h", ".", "lookupByDump", "{", "return", "h", ".", "linkByNameDump", "(", "name", ")", "\n", "}", "\n\n", "req", ":=", "h", ".", "newNetlinkRequest", "(", "unix", ".", "RTM_GETLINK", ",", "unix", ".", "NLM_F_ACK", ")", "\n\n", "msg", ":=", "nl", ".", "NewIfInfomsg", "(", "unix", ".", "AF_UNSPEC", ")", "\n", "req", ".", "AddData", "(", "msg", ")", "\n\n", "attr", ":=", "nl", ".", "NewRtAttr", "(", "unix", ".", "IFLA_EXT_MASK", ",", "nl", ".", "Uint32Attr", "(", "nl", ".", "RTEXT_FILTER_VF", ")", ")", "\n", "req", ".", "AddData", "(", "attr", ")", "\n\n", "nameData", ":=", "nl", ".", "NewRtAttr", "(", "unix", ".", "IFLA_IFNAME", ",", "nl", ".", "ZeroTerminated", "(", "name", ")", ")", "\n", "req", ".", "AddData", "(", "nameData", ")", "\n\n", "link", ",", "err", ":=", "execGetLink", "(", "req", ")", "\n", "if", "err", "==", "unix", ".", "EINVAL", "{", "// older kernels don't support looking up via IFLA_IFNAME", "// so fall back to dumping all links", "h", ".", "lookupByDump", "=", "true", "\n", "return", "h", ".", "linkByNameDump", "(", "name", ")", "\n", "}", "\n\n", "return", "link", ",", "err", "\n", "}" ]
// LinkByName finds a link by name and returns a pointer to the object.
[ "LinkByName", "finds", "a", "link", "by", "name", "and", "returns", "a", "pointer", "to", "the", "object", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L1283-L1308
train
vishvananda/netlink
link_linux.go
LinkByAlias
func (h *Handle) LinkByAlias(alias string) (Link, error) { if h.lookupByDump { return h.linkByAliasDump(alias) } req := h.newNetlinkRequest(unix.RTM_GETLINK, unix.NLM_F_ACK) msg := nl.NewIfInfomsg(unix.AF_UNSPEC) req.AddData(msg) attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF)) req.AddData(attr) nameData := nl.NewRtAttr(unix.IFLA_IFALIAS, nl.ZeroTerminated(alias)) req.AddData(nameData) link, err := execGetLink(req) if err == unix.EINVAL { // older kernels don't support looking up via IFLA_IFALIAS // so fall back to dumping all links h.lookupByDump = true return h.linkByAliasDump(alias) } return link, err }
go
func (h *Handle) LinkByAlias(alias string) (Link, error) { if h.lookupByDump { return h.linkByAliasDump(alias) } req := h.newNetlinkRequest(unix.RTM_GETLINK, unix.NLM_F_ACK) msg := nl.NewIfInfomsg(unix.AF_UNSPEC) req.AddData(msg) attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF)) req.AddData(attr) nameData := nl.NewRtAttr(unix.IFLA_IFALIAS, nl.ZeroTerminated(alias)) req.AddData(nameData) link, err := execGetLink(req) if err == unix.EINVAL { // older kernels don't support looking up via IFLA_IFALIAS // so fall back to dumping all links h.lookupByDump = true return h.linkByAliasDump(alias) } return link, err }
[ "func", "(", "h", "*", "Handle", ")", "LinkByAlias", "(", "alias", "string", ")", "(", "Link", ",", "error", ")", "{", "if", "h", ".", "lookupByDump", "{", "return", "h", ".", "linkByAliasDump", "(", "alias", ")", "\n", "}", "\n\n", "req", ":=", "h", ".", "newNetlinkRequest", "(", "unix", ".", "RTM_GETLINK", ",", "unix", ".", "NLM_F_ACK", ")", "\n\n", "msg", ":=", "nl", ".", "NewIfInfomsg", "(", "unix", ".", "AF_UNSPEC", ")", "\n", "req", ".", "AddData", "(", "msg", ")", "\n\n", "attr", ":=", "nl", ".", "NewRtAttr", "(", "unix", ".", "IFLA_EXT_MASK", ",", "nl", ".", "Uint32Attr", "(", "nl", ".", "RTEXT_FILTER_VF", ")", ")", "\n", "req", ".", "AddData", "(", "attr", ")", "\n\n", "nameData", ":=", "nl", ".", "NewRtAttr", "(", "unix", ".", "IFLA_IFALIAS", ",", "nl", ".", "ZeroTerminated", "(", "alias", ")", ")", "\n", "req", ".", "AddData", "(", "nameData", ")", "\n\n", "link", ",", "err", ":=", "execGetLink", "(", "req", ")", "\n", "if", "err", "==", "unix", ".", "EINVAL", "{", "// older kernels don't support looking up via IFLA_IFALIAS", "// so fall back to dumping all links", "h", ".", "lookupByDump", "=", "true", "\n", "return", "h", ".", "linkByAliasDump", "(", "alias", ")", "\n", "}", "\n\n", "return", "link", ",", "err", "\n", "}" ]
// LinkByAlias finds a link by its alias and returns a pointer to the object. // If there are multiple links with the alias it returns the first one
[ "LinkByAlias", "finds", "a", "link", "by", "its", "alias", "and", "returns", "a", "pointer", "to", "the", "object", ".", "If", "there", "are", "multiple", "links", "with", "the", "alias", "it", "returns", "the", "first", "one" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L1318-L1343
train
vishvananda/netlink
link_linux.go
LinkByIndex
func (h *Handle) LinkByIndex(index int) (Link, error) { req := h.newNetlinkRequest(unix.RTM_GETLINK, unix.NLM_F_ACK) msg := nl.NewIfInfomsg(unix.AF_UNSPEC) msg.Index = int32(index) req.AddData(msg) attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF)) req.AddData(attr) return execGetLink(req) }
go
func (h *Handle) LinkByIndex(index int) (Link, error) { req := h.newNetlinkRequest(unix.RTM_GETLINK, unix.NLM_F_ACK) msg := nl.NewIfInfomsg(unix.AF_UNSPEC) msg.Index = int32(index) req.AddData(msg) attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF)) req.AddData(attr) return execGetLink(req) }
[ "func", "(", "h", "*", "Handle", ")", "LinkByIndex", "(", "index", "int", ")", "(", "Link", ",", "error", ")", "{", "req", ":=", "h", ".", "newNetlinkRequest", "(", "unix", ".", "RTM_GETLINK", ",", "unix", ".", "NLM_F_ACK", ")", "\n\n", "msg", ":=", "nl", ".", "NewIfInfomsg", "(", "unix", ".", "AF_UNSPEC", ")", "\n", "msg", ".", "Index", "=", "int32", "(", "index", ")", "\n", "req", ".", "AddData", "(", "msg", ")", "\n", "attr", ":=", "nl", ".", "NewRtAttr", "(", "unix", ".", "IFLA_EXT_MASK", ",", "nl", ".", "Uint32Attr", "(", "nl", ".", "RTEXT_FILTER_VF", ")", ")", "\n", "req", ".", "AddData", "(", "attr", ")", "\n\n", "return", "execGetLink", "(", "req", ")", "\n", "}" ]
// LinkByIndex finds a link by index and returns a pointer to the object.
[ "LinkByIndex", "finds", "a", "link", "by", "index", "and", "returns", "a", "pointer", "to", "the", "object", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L1351-L1361
train
vishvananda/netlink
link_linux.go
LinkSubscribe
func LinkSubscribe(ch chan<- LinkUpdate, done <-chan struct{}) error { return linkSubscribeAt(netns.None(), netns.None(), ch, done, nil, false) }
go
func LinkSubscribe(ch chan<- LinkUpdate, done <-chan struct{}) error { return linkSubscribeAt(netns.None(), netns.None(), ch, done, nil, false) }
[ "func", "LinkSubscribe", "(", "ch", "chan", "<-", "LinkUpdate", ",", "done", "<-", "chan", "struct", "{", "}", ")", "error", "{", "return", "linkSubscribeAt", "(", "netns", ".", "None", "(", ")", ",", "netns", ".", "None", "(", ")", ",", "ch", ",", "done", ",", "nil", ",", "false", ")", "\n", "}" ]
// LinkSubscribe takes a chan down which notifications will be sent // when links change. Close the 'done' chan to stop subscription.
[ "LinkSubscribe", "takes", "a", "chan", "down", "which", "notifications", "will", "be", "sent", "when", "links", "change", ".", "Close", "the", "done", "chan", "to", "stop", "subscription", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L1626-L1628
train
vishvananda/netlink
link_linux.go
LinkSubscribeWithOptions
func LinkSubscribeWithOptions(ch chan<- LinkUpdate, done <-chan struct{}, options LinkSubscribeOptions) error { if options.Namespace == nil { none := netns.None() options.Namespace = &none } return linkSubscribeAt(*options.Namespace, netns.None(), ch, done, options.ErrorCallback, options.ListExisting) }
go
func LinkSubscribeWithOptions(ch chan<- LinkUpdate, done <-chan struct{}, options LinkSubscribeOptions) error { if options.Namespace == nil { none := netns.None() options.Namespace = &none } return linkSubscribeAt(*options.Namespace, netns.None(), ch, done, options.ErrorCallback, options.ListExisting) }
[ "func", "LinkSubscribeWithOptions", "(", "ch", "chan", "<-", "LinkUpdate", ",", "done", "<-", "chan", "struct", "{", "}", ",", "options", "LinkSubscribeOptions", ")", "error", "{", "if", "options", ".", "Namespace", "==", "nil", "{", "none", ":=", "netns", ".", "None", "(", ")", "\n", "options", ".", "Namespace", "=", "&", "none", "\n", "}", "\n", "return", "linkSubscribeAt", "(", "*", "options", ".", "Namespace", ",", "netns", ".", "None", "(", ")", ",", "ch", ",", "done", ",", "options", ".", "ErrorCallback", ",", "options", ".", "ListExisting", ")", "\n", "}" ]
// LinkSubscribeWithOptions work like LinkSubscribe but enable to // provide additional options to modify the behavior. Currently, the // namespace can be provided as well as an error callback.
[ "LinkSubscribeWithOptions", "work", "like", "LinkSubscribe", "but", "enable", "to", "provide", "additional", "options", "to", "modify", "the", "behavior", ".", "Currently", "the", "namespace", "can", "be", "provided", "as", "well", "as", "an", "error", "callback", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L1647-L1653
train
vishvananda/netlink
link_linux.go
LinkSetBondSlave
func LinkSetBondSlave(link Link, master *Bond) error { fd, err := getSocketUDP() if err != nil { return err } defer syscall.Close(fd) ifreq := newIocltSlaveReq(link.Attrs().Name, master.Attrs().Name) _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), unix.SIOCBONDENSLAVE, uintptr(unsafe.Pointer(ifreq))) if errno != 0 { return fmt.Errorf("Failed to enslave %q to %q, errno=%v", link.Attrs().Name, master.Attrs().Name, errno) } return nil }
go
func LinkSetBondSlave(link Link, master *Bond) error { fd, err := getSocketUDP() if err != nil { return err } defer syscall.Close(fd) ifreq := newIocltSlaveReq(link.Attrs().Name, master.Attrs().Name) _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), unix.SIOCBONDENSLAVE, uintptr(unsafe.Pointer(ifreq))) if errno != 0 { return fmt.Errorf("Failed to enslave %q to %q, errno=%v", link.Attrs().Name, master.Attrs().Name, errno) } return nil }
[ "func", "LinkSetBondSlave", "(", "link", "Link", ",", "master", "*", "Bond", ")", "error", "{", "fd", ",", "err", ":=", "getSocketUDP", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "syscall", ".", "Close", "(", "fd", ")", "\n\n", "ifreq", ":=", "newIocltSlaveReq", "(", "link", ".", "Attrs", "(", ")", ".", "Name", ",", "master", ".", "Attrs", "(", ")", ".", "Name", ")", "\n\n", "_", ",", "_", ",", "errno", ":=", "syscall", ".", "Syscall", "(", "syscall", ".", "SYS_IOCTL", ",", "uintptr", "(", "fd", ")", ",", "unix", ".", "SIOCBONDENSLAVE", ",", "uintptr", "(", "unsafe", ".", "Pointer", "(", "ifreq", ")", ")", ")", "\n", "if", "errno", "!=", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "link", ".", "Attrs", "(", ")", ".", "Name", ",", "master", ".", "Attrs", "(", ")", ".", "Name", ",", "errno", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// LinkSetBondSlave add slave to bond link via ioctl interface.
[ "LinkSetBondSlave", "add", "slave", "to", "bond", "link", "via", "ioctl", "interface", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L2531-L2545
train
vishvananda/netlink
link_linux.go
VethPeerIndex
func VethPeerIndex(link *Veth) (int, error) { fd, err := getSocketUDP() if err != nil { return -1, err } defer syscall.Close(fd) ifreq, sSet := newIocltStringSetReq(link.Name) _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), SIOCETHTOOL, uintptr(unsafe.Pointer(ifreq))) if errno != 0 { return -1, fmt.Errorf("SIOCETHTOOL request for %q failed, errno=%v", link.Attrs().Name, errno) } gstrings := &ethtoolGstrings{ cmd: ETHTOOL_GSTRINGS, stringSet: ETH_SS_STATS, length: sSet.data[0], } ifreq.Data = uintptr(unsafe.Pointer(gstrings)) _, _, errno = syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), SIOCETHTOOL, uintptr(unsafe.Pointer(ifreq))) if errno != 0 { return -1, fmt.Errorf("SIOCETHTOOL request for %q failed, errno=%v", link.Attrs().Name, errno) } stats := &ethtoolStats{ cmd: ETHTOOL_GSTATS, nStats: gstrings.length, } ifreq.Data = uintptr(unsafe.Pointer(stats)) _, _, errno = syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), SIOCETHTOOL, uintptr(unsafe.Pointer(ifreq))) if errno != 0 { return -1, fmt.Errorf("SIOCETHTOOL request for %q failed, errno=%v", link.Attrs().Name, errno) } return int(stats.data[0]), nil }
go
func VethPeerIndex(link *Veth) (int, error) { fd, err := getSocketUDP() if err != nil { return -1, err } defer syscall.Close(fd) ifreq, sSet := newIocltStringSetReq(link.Name) _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), SIOCETHTOOL, uintptr(unsafe.Pointer(ifreq))) if errno != 0 { return -1, fmt.Errorf("SIOCETHTOOL request for %q failed, errno=%v", link.Attrs().Name, errno) } gstrings := &ethtoolGstrings{ cmd: ETHTOOL_GSTRINGS, stringSet: ETH_SS_STATS, length: sSet.data[0], } ifreq.Data = uintptr(unsafe.Pointer(gstrings)) _, _, errno = syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), SIOCETHTOOL, uintptr(unsafe.Pointer(ifreq))) if errno != 0 { return -1, fmt.Errorf("SIOCETHTOOL request for %q failed, errno=%v", link.Attrs().Name, errno) } stats := &ethtoolStats{ cmd: ETHTOOL_GSTATS, nStats: gstrings.length, } ifreq.Data = uintptr(unsafe.Pointer(stats)) _, _, errno = syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), SIOCETHTOOL, uintptr(unsafe.Pointer(ifreq))) if errno != 0 { return -1, fmt.Errorf("SIOCETHTOOL request for %q failed, errno=%v", link.Attrs().Name, errno) } return int(stats.data[0]), nil }
[ "func", "VethPeerIndex", "(", "link", "*", "Veth", ")", "(", "int", ",", "error", ")", "{", "fd", ",", "err", ":=", "getSocketUDP", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n", "defer", "syscall", ".", "Close", "(", "fd", ")", "\n\n", "ifreq", ",", "sSet", ":=", "newIocltStringSetReq", "(", "link", ".", "Name", ")", "\n", "_", ",", "_", ",", "errno", ":=", "syscall", ".", "Syscall", "(", "syscall", ".", "SYS_IOCTL", ",", "uintptr", "(", "fd", ")", ",", "SIOCETHTOOL", ",", "uintptr", "(", "unsafe", ".", "Pointer", "(", "ifreq", ")", ")", ")", "\n", "if", "errno", "!=", "0", "{", "return", "-", "1", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "link", ".", "Attrs", "(", ")", ".", "Name", ",", "errno", ")", "\n", "}", "\n\n", "gstrings", ":=", "&", "ethtoolGstrings", "{", "cmd", ":", "ETHTOOL_GSTRINGS", ",", "stringSet", ":", "ETH_SS_STATS", ",", "length", ":", "sSet", ".", "data", "[", "0", "]", ",", "}", "\n", "ifreq", ".", "Data", "=", "uintptr", "(", "unsafe", ".", "Pointer", "(", "gstrings", ")", ")", "\n", "_", ",", "_", ",", "errno", "=", "syscall", ".", "Syscall", "(", "syscall", ".", "SYS_IOCTL", ",", "uintptr", "(", "fd", ")", ",", "SIOCETHTOOL", ",", "uintptr", "(", "unsafe", ".", "Pointer", "(", "ifreq", ")", ")", ")", "\n", "if", "errno", "!=", "0", "{", "return", "-", "1", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "link", ".", "Attrs", "(", ")", ".", "Name", ",", "errno", ")", "\n", "}", "\n\n", "stats", ":=", "&", "ethtoolStats", "{", "cmd", ":", "ETHTOOL_GSTATS", ",", "nStats", ":", "gstrings", ".", "length", ",", "}", "\n", "ifreq", ".", "Data", "=", "uintptr", "(", "unsafe", ".", "Pointer", "(", "stats", ")", ")", "\n", "_", ",", "_", ",", "errno", "=", "syscall", ".", "Syscall", "(", "syscall", ".", "SYS_IOCTL", ",", "uintptr", "(", "fd", ")", ",", "SIOCETHTOOL", ",", "uintptr", "(", "unsafe", ".", "Pointer", "(", "ifreq", ")", ")", ")", "\n", "if", "errno", "!=", "0", "{", "return", "-", "1", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "link", ".", "Attrs", "(", ")", ".", "Name", ",", "errno", ")", "\n", "}", "\n", "return", "int", "(", "stats", ".", "data", "[", "0", "]", ")", ",", "nil", "\n", "}" ]
// VethPeerIndex get veth peer index.
[ "VethPeerIndex", "get", "veth", "peer", "index", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L2548-L2582
train
vishvananda/netlink
netns_linux.go
GetNetNsIdByFd
func (h *Handle) GetNetNsIdByFd(fd int) (int, error) { return h.getNetNsId(NETNSA_FD, uint32(fd)) }
go
func (h *Handle) GetNetNsIdByFd(fd int) (int, error) { return h.getNetNsId(NETNSA_FD, uint32(fd)) }
[ "func", "(", "h", "*", "Handle", ")", "GetNetNsIdByFd", "(", "fd", "int", ")", "(", "int", ",", "error", ")", "{", "return", "h", ".", "getNetNsId", "(", "NETNSA_FD", ",", "uint32", "(", "fd", ")", ")", "\n", "}" ]
// GetNetNsIdByFd looks up the network namespace ID for a given fd. // fd must be an open file descriptor to a namespace file. // Returns -1 if the namespace does not have an ID set.
[ "GetNetNsIdByFd", "looks", "up", "the", "network", "namespace", "ID", "for", "a", "given", "fd", ".", "fd", "must", "be", "an", "open", "file", "descriptor", "to", "a", "namespace", "file", ".", "Returns", "-", "1", "if", "the", "namespace", "does", "not", "have", "an", "ID", "set", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/netns_linux.go#L57-L59
train
vishvananda/netlink
netns_linux.go
SetNetNsIdByFd
func (h *Handle) SetNetNsIdByFd(fd, nsid int) error { return h.setNetNsId(NETNSA_FD, uint32(fd), uint32(nsid)) }
go
func (h *Handle) SetNetNsIdByFd(fd, nsid int) error { return h.setNetNsId(NETNSA_FD, uint32(fd), uint32(nsid)) }
[ "func", "(", "h", "*", "Handle", ")", "SetNetNsIdByFd", "(", "fd", ",", "nsid", "int", ")", "error", "{", "return", "h", ".", "setNetNsId", "(", "NETNSA_FD", ",", "uint32", "(", "fd", ")", ",", "uint32", "(", "nsid", ")", ")", "\n", "}" ]
// SetNetNSIdByFd sets the ID of the network namespace for a given fd. // fd must be an open file descriptor to a namespace file. // The ID can only be set for namespaces without an ID already set.
[ "SetNetNSIdByFd", "sets", "the", "ID", "of", "the", "network", "namespace", "for", "a", "given", "fd", ".", "fd", "must", "be", "an", "open", "file", "descriptor", "to", "a", "namespace", "file", ".", "The", "ID", "can", "only", "be", "set", "for", "namespaces", "without", "an", "ID", "already", "set", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/netns_linux.go#L71-L73
train
vishvananda/netlink
netns_linux.go
getNetNsId
func (h *Handle) getNetNsId(attrType int, val uint32) (int, error) { req := h.newNetlinkRequest(unix.RTM_GETNSID, unix.NLM_F_REQUEST) rtgen := nl.NewRtGenMsg() req.AddData(rtgen) b := make([]byte, 4, 4) native.PutUint32(b, val) attr := nl.NewRtAttr(attrType, b) req.AddData(attr) msgs, err := req.Execute(unix.NETLINK_ROUTE, unix.RTM_NEWNSID) if err != nil { return 0, err } for _, m := range msgs { msg := nl.DeserializeRtGenMsg(m) attrs, err := nl.ParseRouteAttr(m[msg.Len():]) if err != nil { return 0, err } for _, attr := range attrs { switch attr.Attr.Type { case NETNSA_NSID: return int(int32(native.Uint32(attr.Value))), nil } } } return 0, fmt.Errorf("unexpected empty result") }
go
func (h *Handle) getNetNsId(attrType int, val uint32) (int, error) { req := h.newNetlinkRequest(unix.RTM_GETNSID, unix.NLM_F_REQUEST) rtgen := nl.NewRtGenMsg() req.AddData(rtgen) b := make([]byte, 4, 4) native.PutUint32(b, val) attr := nl.NewRtAttr(attrType, b) req.AddData(attr) msgs, err := req.Execute(unix.NETLINK_ROUTE, unix.RTM_NEWNSID) if err != nil { return 0, err } for _, m := range msgs { msg := nl.DeserializeRtGenMsg(m) attrs, err := nl.ParseRouteAttr(m[msg.Len():]) if err != nil { return 0, err } for _, attr := range attrs { switch attr.Attr.Type { case NETNSA_NSID: return int(int32(native.Uint32(attr.Value))), nil } } } return 0, fmt.Errorf("unexpected empty result") }
[ "func", "(", "h", "*", "Handle", ")", "getNetNsId", "(", "attrType", "int", ",", "val", "uint32", ")", "(", "int", ",", "error", ")", "{", "req", ":=", "h", ".", "newNetlinkRequest", "(", "unix", ".", "RTM_GETNSID", ",", "unix", ".", "NLM_F_REQUEST", ")", "\n\n", "rtgen", ":=", "nl", ".", "NewRtGenMsg", "(", ")", "\n", "req", ".", "AddData", "(", "rtgen", ")", "\n\n", "b", ":=", "make", "(", "[", "]", "byte", ",", "4", ",", "4", ")", "\n", "native", ".", "PutUint32", "(", "b", ",", "val", ")", "\n", "attr", ":=", "nl", ".", "NewRtAttr", "(", "attrType", ",", "b", ")", "\n", "req", ".", "AddData", "(", "attr", ")", "\n\n", "msgs", ",", "err", ":=", "req", ".", "Execute", "(", "unix", ".", "NETLINK_ROUTE", ",", "unix", ".", "RTM_NEWNSID", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "for", "_", ",", "m", ":=", "range", "msgs", "{", "msg", ":=", "nl", ".", "DeserializeRtGenMsg", "(", "m", ")", "\n\n", "attrs", ",", "err", ":=", "nl", ".", "ParseRouteAttr", "(", "m", "[", "msg", ".", "Len", "(", ")", ":", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "for", "_", ",", "attr", ":=", "range", "attrs", "{", "switch", "attr", ".", "Attr", ".", "Type", "{", "case", "NETNSA_NSID", ":", "return", "int", "(", "int32", "(", "native", ".", "Uint32", "(", "attr", ".", "Value", ")", ")", ")", ",", "nil", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}" ]
// getNetNsId requests the netnsid for a given type-val pair // type should be either NETNSA_PID or NETNSA_FD
[ "getNetNsId", "requests", "the", "netnsid", "for", "a", "given", "type", "-", "val", "pair", "type", "should", "be", "either", "NETNSA_PID", "or", "NETNSA_FD" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/netns_linux.go#L84-L118
train
vishvananda/netlink
netns_linux.go
setNetNsId
func (h *Handle) setNetNsId(attrType int, val uint32, newnsid uint32) error { req := h.newNetlinkRequest(unix.RTM_NEWNSID, unix.NLM_F_REQUEST|unix.NLM_F_ACK) rtgen := nl.NewRtGenMsg() req.AddData(rtgen) b := make([]byte, 4, 4) native.PutUint32(b, val) attr := nl.NewRtAttr(attrType, b) req.AddData(attr) b1 := make([]byte, 4, 4) native.PutUint32(b1, newnsid) attr1 := nl.NewRtAttr(NETNSA_NSID, b1) req.AddData(attr1) _, err := req.Execute(unix.NETLINK_ROUTE, unix.RTM_NEWNSID) return err }
go
func (h *Handle) setNetNsId(attrType int, val uint32, newnsid uint32) error { req := h.newNetlinkRequest(unix.RTM_NEWNSID, unix.NLM_F_REQUEST|unix.NLM_F_ACK) rtgen := nl.NewRtGenMsg() req.AddData(rtgen) b := make([]byte, 4, 4) native.PutUint32(b, val) attr := nl.NewRtAttr(attrType, b) req.AddData(attr) b1 := make([]byte, 4, 4) native.PutUint32(b1, newnsid) attr1 := nl.NewRtAttr(NETNSA_NSID, b1) req.AddData(attr1) _, err := req.Execute(unix.NETLINK_ROUTE, unix.RTM_NEWNSID) return err }
[ "func", "(", "h", "*", "Handle", ")", "setNetNsId", "(", "attrType", "int", ",", "val", "uint32", ",", "newnsid", "uint32", ")", "error", "{", "req", ":=", "h", ".", "newNetlinkRequest", "(", "unix", ".", "RTM_NEWNSID", ",", "unix", ".", "NLM_F_REQUEST", "|", "unix", ".", "NLM_F_ACK", ")", "\n\n", "rtgen", ":=", "nl", ".", "NewRtGenMsg", "(", ")", "\n", "req", ".", "AddData", "(", "rtgen", ")", "\n\n", "b", ":=", "make", "(", "[", "]", "byte", ",", "4", ",", "4", ")", "\n", "native", ".", "PutUint32", "(", "b", ",", "val", ")", "\n", "attr", ":=", "nl", ".", "NewRtAttr", "(", "attrType", ",", "b", ")", "\n", "req", ".", "AddData", "(", "attr", ")", "\n\n", "b1", ":=", "make", "(", "[", "]", "byte", ",", "4", ",", "4", ")", "\n", "native", ".", "PutUint32", "(", "b1", ",", "newnsid", ")", "\n", "attr1", ":=", "nl", ".", "NewRtAttr", "(", "NETNSA_NSID", ",", "b1", ")", "\n", "req", ".", "AddData", "(", "attr1", ")", "\n\n", "_", ",", "err", ":=", "req", ".", "Execute", "(", "unix", ".", "NETLINK_ROUTE", ",", "unix", ".", "RTM_NEWNSID", ")", "\n", "return", "err", "\n", "}" ]
// setNetNsId sets the netnsid for a given type-val pair // type should be either NETNSA_PID or NETNSA_FD // The ID can only be set for namespaces without an ID already set
[ "setNetNsId", "sets", "the", "netnsid", "for", "a", "given", "type", "-", "val", "pair", "type", "should", "be", "either", "NETNSA_PID", "or", "NETNSA_FD", "The", "ID", "can", "only", "be", "set", "for", "namespaces", "without", "an", "ID", "already", "set" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/netns_linux.go#L123-L141
train
vishvananda/netlink
route.go
ipNetEqual
func ipNetEqual(ipn1 *net.IPNet, ipn2 *net.IPNet) bool { if ipn1 == ipn2 { return true } if ipn1 == nil || ipn2 == nil { return false } m1, _ := ipn1.Mask.Size() m2, _ := ipn2.Mask.Size() return m1 == m2 && ipn1.IP.Equal(ipn2.IP) }
go
func ipNetEqual(ipn1 *net.IPNet, ipn2 *net.IPNet) bool { if ipn1 == ipn2 { return true } if ipn1 == nil || ipn2 == nil { return false } m1, _ := ipn1.Mask.Size() m2, _ := ipn2.Mask.Size() return m1 == m2 && ipn1.IP.Equal(ipn2.IP) }
[ "func", "ipNetEqual", "(", "ipn1", "*", "net", ".", "IPNet", ",", "ipn2", "*", "net", ".", "IPNet", ")", "bool", "{", "if", "ipn1", "==", "ipn2", "{", "return", "true", "\n", "}", "\n", "if", "ipn1", "==", "nil", "||", "ipn2", "==", "nil", "{", "return", "false", "\n", "}", "\n", "m1", ",", "_", ":=", "ipn1", ".", "Mask", ".", "Size", "(", ")", "\n", "m2", ",", "_", ":=", "ipn2", ".", "Mask", ".", "Size", "(", ")", "\n", "return", "m1", "==", "m2", "&&", "ipn1", ".", "IP", ".", "Equal", "(", "ipn2", ".", "IP", ")", "\n", "}" ]
// ipNetEqual returns true iff both IPNet are equal
[ "ipNetEqual", "returns", "true", "iff", "both", "IPNet", "are", "equal" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/route.go#L170-L180
train
vishvananda/netlink
ioctl_linux.go
newIocltSlaveReq
func newIocltSlaveReq(slave, master string) *IfreqSlave { ifreq := &IfreqSlave{} copy(ifreq.Name[:unix.IFNAMSIZ-1], master) copy(ifreq.Slave[:unix.IFNAMSIZ-1], slave) return ifreq }
go
func newIocltSlaveReq(slave, master string) *IfreqSlave { ifreq := &IfreqSlave{} copy(ifreq.Name[:unix.IFNAMSIZ-1], master) copy(ifreq.Slave[:unix.IFNAMSIZ-1], slave) return ifreq }
[ "func", "newIocltSlaveReq", "(", "slave", ",", "master", "string", ")", "*", "IfreqSlave", "{", "ifreq", ":=", "&", "IfreqSlave", "{", "}", "\n", "copy", "(", "ifreq", ".", "Name", "[", ":", "unix", ".", "IFNAMSIZ", "-", "1", "]", ",", "master", ")", "\n", "copy", "(", "ifreq", ".", "Slave", "[", ":", "unix", ".", "IFNAMSIZ", "-", "1", "]", ",", "slave", ")", "\n", "return", "ifreq", "\n", "}" ]
// newIocltSlaveReq returns filled IfreqSlave with proper interface names // It is used by ioctl to assign slave to bond master
[ "newIocltSlaveReq", "returns", "filled", "IfreqSlave", "with", "proper", "interface", "names", "It", "is", "used", "by", "ioctl", "to", "assign", "slave", "to", "bond", "master" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/ioctl_linux.go#L75-L80
train
vishvananda/netlink
ioctl_linux.go
newIocltStringSetReq
func newIocltStringSetReq(linkName string) (*Ifreq, *ethtoolSset) { e := &ethtoolSset{ cmd: ETHTOOL_GSSET_INFO, mask: 1 << ETH_SS_STATS, } ifreq := &Ifreq{Data: uintptr(unsafe.Pointer(e))} copy(ifreq.Name[:unix.IFNAMSIZ-1], linkName) return ifreq, e }
go
func newIocltStringSetReq(linkName string) (*Ifreq, *ethtoolSset) { e := &ethtoolSset{ cmd: ETHTOOL_GSSET_INFO, mask: 1 << ETH_SS_STATS, } ifreq := &Ifreq{Data: uintptr(unsafe.Pointer(e))} copy(ifreq.Name[:unix.IFNAMSIZ-1], linkName) return ifreq, e }
[ "func", "newIocltStringSetReq", "(", "linkName", "string", ")", "(", "*", "Ifreq", ",", "*", "ethtoolSset", ")", "{", "e", ":=", "&", "ethtoolSset", "{", "cmd", ":", "ETHTOOL_GSSET_INFO", ",", "mask", ":", "1", "<<", "ETH_SS_STATS", ",", "}", "\n\n", "ifreq", ":=", "&", "Ifreq", "{", "Data", ":", "uintptr", "(", "unsafe", ".", "Pointer", "(", "e", ")", ")", "}", "\n", "copy", "(", "ifreq", ".", "Name", "[", ":", "unix", ".", "IFNAMSIZ", "-", "1", "]", ",", "linkName", ")", "\n", "return", "ifreq", ",", "e", "\n", "}" ]
// newIocltStringSetReq creates request to get interface string set
[ "newIocltStringSetReq", "creates", "request", "to", "get", "interface", "string", "set" ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/ioctl_linux.go#L83-L92
train
vishvananda/netlink
addr.go
Equal
func (a Addr) Equal(x Addr) bool { sizea, _ := a.Mask.Size() sizeb, _ := x.Mask.Size() // ignore label for comparison return a.IP.Equal(x.IP) && sizea == sizeb }
go
func (a Addr) Equal(x Addr) bool { sizea, _ := a.Mask.Size() sizeb, _ := x.Mask.Size() // ignore label for comparison return a.IP.Equal(x.IP) && sizea == sizeb }
[ "func", "(", "a", "Addr", ")", "Equal", "(", "x", "Addr", ")", "bool", "{", "sizea", ",", "_", ":=", "a", ".", "Mask", ".", "Size", "(", ")", "\n", "sizeb", ",", "_", ":=", "x", ".", "Mask", ".", "Size", "(", ")", "\n", "// ignore label for comparison", "return", "a", ".", "IP", ".", "Equal", "(", "x", ".", "IP", ")", "&&", "sizea", "==", "sizeb", "\n", "}" ]
// Equal returns true if both Addrs have the same net.IPNet value.
[ "Equal", "returns", "true", "if", "both", "Addrs", "have", "the", "same", "net", ".", "IPNet", "value", "." ]
fd97bf4e47867b5e794234baa6b8a7746135ec10
https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/addr.go#L44-L49
train