repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
kardianos/service
version.go
versionAtMost
func versionAtMost(version, max []int) (bool, error) { if comp, err := versionCompare(version, max); err != nil { return false, err } else if comp == 1 { return false, nil } return true, nil }
go
func versionAtMost(version, max []int) (bool, error) { if comp, err := versionCompare(version, max); err != nil { return false, err } else if comp == 1 { return false, nil } return true, nil }
[ "func", "versionAtMost", "(", "version", ",", "max", "[", "]", "int", ")", "(", "bool", ",", "error", ")", "{", "if", "comp", ",", "err", ":=", "versionCompare", "(", "version", ",", "max", ")", ";", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "else", "if", "comp", "==", "1", "{", "return", "false", ",", "nil", "\n", "}", "\n", "return", "true", ",", "nil", "\n", "}" ]
// versionAtMost will return true if the provided version is less than or equal to max
[ "versionAtMost", "will", "return", "true", "if", "the", "provided", "version", "is", "less", "than", "or", "equal", "to", "max" ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/version.go#L10-L17
train
kardianos/service
version.go
versionCompare
func versionCompare(v1, v2 []int) (int, error) { if len(v1) != len(v2) { return 0, errors.New("version length mismatch") } for idx, v2S := range v2 { v1S := v1[idx] if v1S > v2S { return 1, nil } if v1S < v2S { return -1, nil } } return 0, nil }
go
func versionCompare(v1, v2 []int) (int, error) { if len(v1) != len(v2) { return 0, errors.New("version length mismatch") } for idx, v2S := range v2 { v1S := v1[idx] if v1S > v2S { return 1, nil } if v1S < v2S { return -1, nil } } return 0, nil }
[ "func", "versionCompare", "(", "v1", ",", "v2", "[", "]", "int", ")", "(", "int", ",", "error", ")", "{", "if", "len", "(", "v1", ")", "!=", "len", "(", "v2", ")", "{", "return", "0", ",", "errors", ".", "New", "(", "\"version length mismatch\"", ")", "\n", "}", "\n", "for", "idx", ",", "v2S", ":=", "range", "v2", "{", "v1S", ":=", "v1", "[", "idx", "]", "\n", "if", "v1S", ">", "v2S", "{", "return", "1", ",", "nil", "\n", "}", "\n", "if", "v1S", "<", "v2S", "{", "return", "-", "1", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "0", ",", "nil", "\n", "}" ]
// versionCompare take to versions split into integer arrays and attempts to compare them // An error will be returned if there is an array length mismatch. // Return values are as follows // -1 - v1 is less than v2 // 0 - v1 is equal to v2 // 1 - v1 is greater than v2
[ "versionCompare", "take", "to", "versions", "split", "into", "integer", "arrays", "and", "attempts", "to", "compare", "them", "An", "error", "will", "be", "returned", "if", "there", "is", "an", "array", "length", "mismatch", ".", "Return", "values", "are", "as", "follows", "-", "1", "-", "v1", "is", "less", "than", "v2", "0", "-", "v1", "is", "equal", "to", "v2", "1", "-", "v1", "is", "greater", "than", "v2" ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/version.go#L25-L41
train
kardianos/service
version.go
parseVersion
func parseVersion(v string) []int { version := make([]int, 3) for idx, vStr := range strings.Split(v, ".") { vS, err := strconv.Atoi(vStr) if err != nil { return nil } version[idx] = vS } return version }
go
func parseVersion(v string) []int { version := make([]int, 3) for idx, vStr := range strings.Split(v, ".") { vS, err := strconv.Atoi(vStr) if err != nil { return nil } version[idx] = vS } return version }
[ "func", "parseVersion", "(", "v", "string", ")", "[", "]", "int", "{", "version", ":=", "make", "(", "[", "]", "int", ",", "3", ")", "\n", "for", "idx", ",", "vStr", ":=", "range", "strings", ".", "Split", "(", "v", ",", "\".\"", ")", "{", "vS", ",", "err", ":=", "strconv", ".", "Atoi", "(", "vStr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", "\n", "}", "\n", "version", "[", "idx", "]", "=", "vS", "\n", "}", "\n", "return", "version", "\n", "}" ]
// parseVersion will parse any integer type version seperated by periods. // This does not fully support semver style versions.
[ "parseVersion", "will", "parse", "any", "integer", "type", "version", "seperated", "by", "periods", ".", "This", "does", "not", "fully", "support", "semver", "style", "versions", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/version.go#L45-L57
train
kardianos/service
service.go
New
func New(i Interface, c *Config) (Service, error) { if len(c.Name) == 0 { return nil, ErrNameFieldRequired } if system == nil { return nil, ErrNoServiceSystemDetected } return system.New(i, c) }
go
func New(i Interface, c *Config) (Service, error) { if len(c.Name) == 0 { return nil, ErrNameFieldRequired } if system == nil { return nil, ErrNoServiceSystemDetected } return system.New(i, c) }
[ "func", "New", "(", "i", "Interface", ",", "c", "*", "Config", ")", "(", "Service", ",", "error", ")", "{", "if", "len", "(", "c", ".", "Name", ")", "==", "0", "{", "return", "nil", ",", "ErrNameFieldRequired", "\n", "}", "\n", "if", "system", "==", "nil", "{", "return", "nil", ",", "ErrNoServiceSystemDetected", "\n", "}", "\n", "return", "system", ".", "New", "(", "i", ",", "c", ")", "\n", "}" ]
// New creates a new service based on a service interface and configuration.
[ "New", "creates", "a", "new", "service", "based", "on", "a", "service", "interface", "and", "configuration", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service.go#L160-L168
train
kardianos/service
service.go
bool
func (kv KeyValue) bool(name string, defaultValue bool) bool { if v, found := kv[name]; found { if castValue, is := v.(bool); is { return castValue } } return defaultValue }
go
func (kv KeyValue) bool(name string, defaultValue bool) bool { if v, found := kv[name]; found { if castValue, is := v.(bool); is { return castValue } } return defaultValue }
[ "func", "(", "kv", "KeyValue", ")", "bool", "(", "name", "string", ",", "defaultValue", "bool", ")", "bool", "{", "if", "v", ",", "found", ":=", "kv", "[", "name", "]", ";", "found", "{", "if", "castValue", ",", "is", ":=", "v", ".", "(", "bool", ")", ";", "is", "{", "return", "castValue", "\n", "}", "\n", "}", "\n", "return", "defaultValue", "\n", "}" ]
// bool returns the value of the given name, assuming the value is a boolean. // If the value isn't found or is not of the type, the defaultValue is returned.
[ "bool", "returns", "the", "value", "of", "the", "given", "name", "assuming", "the", "value", "is", "a", "boolean", ".", "If", "the", "value", "isn", "t", "found", "or", "is", "not", "of", "the", "type", "the", "defaultValue", "is", "returned", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service.go#L176-L183
train
kardianos/service
service.go
Control
func Control(s Service, action string) error { var err error switch action { case ControlAction[0]: err = s.Start() case ControlAction[1]: err = s.Stop() case ControlAction[2]: err = s.Restart() case ControlAction[3]: err = s.Install() case ControlAction[4]: err = s.Uninstall() default: err = fmt.Errorf("Unknown action %s", action) } if err != nil { return fmt.Errorf("Failed to %s %v: %v", action, s, err) } return nil }
go
func Control(s Service, action string) error { var err error switch action { case ControlAction[0]: err = s.Start() case ControlAction[1]: err = s.Stop() case ControlAction[2]: err = s.Restart() case ControlAction[3]: err = s.Install() case ControlAction[4]: err = s.Uninstall() default: err = fmt.Errorf("Unknown action %s", action) } if err != nil { return fmt.Errorf("Failed to %s %v: %v", action, s, err) } return nil }
[ "func", "Control", "(", "s", "Service", ",", "action", "string", ")", "error", "{", "var", "err", "error", "\n", "switch", "action", "{", "case", "ControlAction", "[", "0", "]", ":", "err", "=", "s", ".", "Start", "(", ")", "\n", "case", "ControlAction", "[", "1", "]", ":", "err", "=", "s", ".", "Stop", "(", ")", "\n", "case", "ControlAction", "[", "2", "]", ":", "err", "=", "s", ".", "Restart", "(", ")", "\n", "case", "ControlAction", "[", "3", "]", ":", "err", "=", "s", ".", "Install", "(", ")", "\n", "case", "ControlAction", "[", "4", "]", ":", "err", "=", "s", ".", "Uninstall", "(", ")", "\n", "default", ":", "err", "=", "fmt", ".", "Errorf", "(", "\"Unknown action %s\"", ",", "action", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Failed to %s %v: %v\"", ",", "action", ",", "s", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Control issues control functions to the service from a given action string.
[ "Control", "issues", "control", "functions", "to", "the", "service", "from", "a", "given", "action", "string", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service.go#L368-L388
train
kardianos/service
service_windows.go
Errorf
func (l WindowsLogger) Errorf(format string, a ...interface{}) error { return l.send(l.ev.Error(3, fmt.Sprintf(format, a...))) }
go
func (l WindowsLogger) Errorf(format string, a ...interface{}) error { return l.send(l.ev.Error(3, fmt.Sprintf(format, a...))) }
[ "func", "(", "l", "WindowsLogger", ")", "Errorf", "(", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "send", "(", "l", ".", "ev", ".", "Error", "(", "3", ",", "fmt", ".", "Sprintf", "(", "format", ",", "a", "...", ")", ")", ")", "\n", "}" ]
// Errorf logs an error message.
[ "Errorf", "logs", "an", "error", "message", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service_windows.go#L87-L89
train
kardianos/service
service_windows.go
Warningf
func (l WindowsLogger) Warningf(format string, a ...interface{}) error { return l.send(l.ev.Warning(2, fmt.Sprintf(format, a...))) }
go
func (l WindowsLogger) Warningf(format string, a ...interface{}) error { return l.send(l.ev.Warning(2, fmt.Sprintf(format, a...))) }
[ "func", "(", "l", "WindowsLogger", ")", "Warningf", "(", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "send", "(", "l", ".", "ev", ".", "Warning", "(", "2", ",", "fmt", ".", "Sprintf", "(", "format", ",", "a", "...", ")", ")", ")", "\n", "}" ]
// Warningf logs an warning message.
[ "Warningf", "logs", "an", "warning", "message", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service_windows.go#L92-L94
train
kardianos/service
service_windows.go
Infof
func (l WindowsLogger) Infof(format string, a ...interface{}) error { return l.send(l.ev.Info(1, fmt.Sprintf(format, a...))) }
go
func (l WindowsLogger) Infof(format string, a ...interface{}) error { return l.send(l.ev.Info(1, fmt.Sprintf(format, a...))) }
[ "func", "(", "l", "WindowsLogger", ")", "Infof", "(", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "send", "(", "l", ".", "ev", ".", "Info", "(", "1", ",", "fmt", ".", "Sprintf", "(", "format", ",", "a", "...", ")", ")", ")", "\n", "}" ]
// Infof logs an info message.
[ "Infof", "logs", "an", "info", "message", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service_windows.go#L97-L99
train
kardianos/service
service_windows.go
NError
func (l WindowsLogger) NError(eventID uint32, v ...interface{}) error { return l.send(l.ev.Error(eventID, fmt.Sprint(v...))) }
go
func (l WindowsLogger) NError(eventID uint32, v ...interface{}) error { return l.send(l.ev.Error(eventID, fmt.Sprint(v...))) }
[ "func", "(", "l", "WindowsLogger", ")", "NError", "(", "eventID", "uint32", ",", "v", "...", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "send", "(", "l", ".", "ev", ".", "Error", "(", "eventID", ",", "fmt", ".", "Sprint", "(", "v", "...", ")", ")", ")", "\n", "}" ]
// NError logs an error message and an event ID.
[ "NError", "logs", "an", "error", "message", "and", "an", "event", "ID", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service_windows.go#L102-L104
train
kardianos/service
service_windows.go
NWarning
func (l WindowsLogger) NWarning(eventID uint32, v ...interface{}) error { return l.send(l.ev.Warning(eventID, fmt.Sprint(v...))) }
go
func (l WindowsLogger) NWarning(eventID uint32, v ...interface{}) error { return l.send(l.ev.Warning(eventID, fmt.Sprint(v...))) }
[ "func", "(", "l", "WindowsLogger", ")", "NWarning", "(", "eventID", "uint32", ",", "v", "...", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "send", "(", "l", ".", "ev", ".", "Warning", "(", "eventID", ",", "fmt", ".", "Sprint", "(", "v", "...", ")", ")", ")", "\n", "}" ]
// NWarning logs an warning message and an event ID.
[ "NWarning", "logs", "an", "warning", "message", "and", "an", "event", "ID", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service_windows.go#L107-L109
train
kardianos/service
service_windows.go
NInfo
func (l WindowsLogger) NInfo(eventID uint32, v ...interface{}) error { return l.send(l.ev.Info(eventID, fmt.Sprint(v...))) }
go
func (l WindowsLogger) NInfo(eventID uint32, v ...interface{}) error { return l.send(l.ev.Info(eventID, fmt.Sprint(v...))) }
[ "func", "(", "l", "WindowsLogger", ")", "NInfo", "(", "eventID", "uint32", ",", "v", "...", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "send", "(", "l", ".", "ev", ".", "Info", "(", "eventID", ",", "fmt", ".", "Sprint", "(", "v", "...", ")", ")", ")", "\n", "}" ]
// NInfo logs an info message and an event ID.
[ "NInfo", "logs", "an", "info", "message", "and", "an", "event", "ID", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service_windows.go#L112-L114
train
kardianos/service
service_windows.go
NErrorf
func (l WindowsLogger) NErrorf(eventID uint32, format string, a ...interface{}) error { return l.send(l.ev.Error(eventID, fmt.Sprintf(format, a...))) }
go
func (l WindowsLogger) NErrorf(eventID uint32, format string, a ...interface{}) error { return l.send(l.ev.Error(eventID, fmt.Sprintf(format, a...))) }
[ "func", "(", "l", "WindowsLogger", ")", "NErrorf", "(", "eventID", "uint32", ",", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "send", "(", "l", ".", "ev", ".", "Error", "(", "eventID", ",", "fmt", ".", "Sprintf", "(", "format", ",", "a", "...", ")", ")", ")", "\n", "}" ]
// NErrorf logs an error message and an event ID.
[ "NErrorf", "logs", "an", "error", "message", "and", "an", "event", "ID", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service_windows.go#L117-L119
train
kardianos/service
service_windows.go
NWarningf
func (l WindowsLogger) NWarningf(eventID uint32, format string, a ...interface{}) error { return l.send(l.ev.Warning(eventID, fmt.Sprintf(format, a...))) }
go
func (l WindowsLogger) NWarningf(eventID uint32, format string, a ...interface{}) error { return l.send(l.ev.Warning(eventID, fmt.Sprintf(format, a...))) }
[ "func", "(", "l", "WindowsLogger", ")", "NWarningf", "(", "eventID", "uint32", ",", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "send", "(", "l", ".", "ev", ".", "Warning", "(", "eventID", ",", "fmt", ".", "Sprintf", "(", "format", ",", "a", "...", ")", ")", ")", "\n", "}" ]
// NWarningf logs an warning message and an event ID.
[ "NWarningf", "logs", "an", "warning", "message", "and", "an", "event", "ID", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service_windows.go#L122-L124
train
kardianos/service
service_windows.go
NInfof
func (l WindowsLogger) NInfof(eventID uint32, format string, a ...interface{}) error { return l.send(l.ev.Info(eventID, fmt.Sprintf(format, a...))) }
go
func (l WindowsLogger) NInfof(eventID uint32, format string, a ...interface{}) error { return l.send(l.ev.Info(eventID, fmt.Sprintf(format, a...))) }
[ "func", "(", "l", "WindowsLogger", ")", "NInfof", "(", "eventID", "uint32", ",", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "send", "(", "l", ".", "ev", ".", "Info", "(", "eventID", ",", "fmt", ".", "Sprintf", "(", "format", ",", "a", "...", ")", ")", ")", "\n", "}" ]
// NInfof logs an info message and an event ID.
[ "NInfof", "logs", "an", "info", "message", "and", "an", "event", "ID", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service_windows.go#L127-L129
train
kardianos/service
service_windows.go
getStopTimeout
func getStopTimeout() time.Duration { // For default and paths see https://support.microsoft.com/en-us/kb/146092 defaultTimeout := time.Millisecond * 20000 key, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Control`, registry.READ) if err != nil { return defaultTimeout } sv, _, err := key.GetStringValue("WaitToKillServiceTimeout") if err != nil { return defaultTimeout } v, err := strconv.Atoi(sv) if err != nil { return defaultTimeout } return time.Millisecond * time.Duration(v) }
go
func getStopTimeout() time.Duration { // For default and paths see https://support.microsoft.com/en-us/kb/146092 defaultTimeout := time.Millisecond * 20000 key, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Control`, registry.READ) if err != nil { return defaultTimeout } sv, _, err := key.GetStringValue("WaitToKillServiceTimeout") if err != nil { return defaultTimeout } v, err := strconv.Atoi(sv) if err != nil { return defaultTimeout } return time.Millisecond * time.Duration(v) }
[ "func", "getStopTimeout", "(", ")", "time", ".", "Duration", "{", "defaultTimeout", ":=", "time", ".", "Millisecond", "*", "20000", "\n", "key", ",", "err", ":=", "registry", ".", "OpenKey", "(", "registry", ".", "LOCAL_MACHINE", ",", "`SYSTEM\\CurrentControlSet\\Control`", ",", "registry", ".", "READ", ")", "\n", "if", "err", "!=", "nil", "{", "return", "defaultTimeout", "\n", "}", "\n", "sv", ",", "_", ",", "err", ":=", "key", ".", "GetStringValue", "(", "\"WaitToKillServiceTimeout\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "defaultTimeout", "\n", "}", "\n", "v", ",", "err", ":=", "strconv", ".", "Atoi", "(", "sv", ")", "\n", "if", "err", "!=", "nil", "{", "return", "defaultTimeout", "\n", "}", "\n", "return", "time", ".", "Millisecond", "*", "time", ".", "Duration", "(", "v", ")", "\n", "}" ]
// getStopTimeout fetches the time before windows will kill the service.
[ "getStopTimeout", "fetches", "the", "time", "before", "windows", "will", "kill", "the", "service", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service_windows.go#L406-L422
train
jroimartin/gocui
edit.go
simpleEditor
func simpleEditor(v *View, key Key, ch rune, mod Modifier) { switch { case ch != 0 && mod == 0: v.EditWrite(ch) case key == KeySpace: v.EditWrite(' ') case key == KeyBackspace || key == KeyBackspace2: v.EditDelete(true) case key == KeyDelete: v.EditDelete(false) case key == KeyInsert: v.Overwrite = !v.Overwrite case key == KeyEnter: v.EditNewLine() case key == KeyArrowDown: v.MoveCursor(0, 1, false) case key == KeyArrowUp: v.MoveCursor(0, -1, false) case key == KeyArrowLeft: v.MoveCursor(-1, 0, false) case key == KeyArrowRight: v.MoveCursor(1, 0, false) } }
go
func simpleEditor(v *View, key Key, ch rune, mod Modifier) { switch { case ch != 0 && mod == 0: v.EditWrite(ch) case key == KeySpace: v.EditWrite(' ') case key == KeyBackspace || key == KeyBackspace2: v.EditDelete(true) case key == KeyDelete: v.EditDelete(false) case key == KeyInsert: v.Overwrite = !v.Overwrite case key == KeyEnter: v.EditNewLine() case key == KeyArrowDown: v.MoveCursor(0, 1, false) case key == KeyArrowUp: v.MoveCursor(0, -1, false) case key == KeyArrowLeft: v.MoveCursor(-1, 0, false) case key == KeyArrowRight: v.MoveCursor(1, 0, false) } }
[ "func", "simpleEditor", "(", "v", "*", "View", ",", "key", "Key", ",", "ch", "rune", ",", "mod", "Modifier", ")", "{", "switch", "{", "case", "ch", "!=", "0", "&&", "mod", "==", "0", ":", "v", ".", "EditWrite", "(", "ch", ")", "\n", "case", "key", "==", "KeySpace", ":", "v", ".", "EditWrite", "(", "' '", ")", "\n", "case", "key", "==", "KeyBackspace", "||", "key", "==", "KeyBackspace2", ":", "v", ".", "EditDelete", "(", "true", ")", "\n", "case", "key", "==", "KeyDelete", ":", "v", ".", "EditDelete", "(", "false", ")", "\n", "case", "key", "==", "KeyInsert", ":", "v", ".", "Overwrite", "=", "!", "v", ".", "Overwrite", "\n", "case", "key", "==", "KeyEnter", ":", "v", ".", "EditNewLine", "(", ")", "\n", "case", "key", "==", "KeyArrowDown", ":", "v", ".", "MoveCursor", "(", "0", ",", "1", ",", "false", ")", "\n", "case", "key", "==", "KeyArrowUp", ":", "v", ".", "MoveCursor", "(", "0", ",", "-", "1", ",", "false", ")", "\n", "case", "key", "==", "KeyArrowLeft", ":", "v", ".", "MoveCursor", "(", "-", "1", ",", "0", ",", "false", ")", "\n", "case", "key", "==", "KeyArrowRight", ":", "v", ".", "MoveCursor", "(", "1", ",", "0", ",", "false", ")", "\n", "}", "\n", "}" ]
// simpleEditor is used as the default gocui editor.
[ "simpleEditor", "is", "used", "as", "the", "default", "gocui", "editor", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/edit.go#L30-L53
train
jroimartin/gocui
edit.go
EditWrite
func (v *View) EditWrite(ch rune) { v.writeRune(v.cx, v.cy, ch) v.MoveCursor(1, 0, true) }
go
func (v *View) EditWrite(ch rune) { v.writeRune(v.cx, v.cy, ch) v.MoveCursor(1, 0, true) }
[ "func", "(", "v", "*", "View", ")", "EditWrite", "(", "ch", "rune", ")", "{", "v", ".", "writeRune", "(", "v", ".", "cx", ",", "v", ".", "cy", ",", "ch", ")", "\n", "v", ".", "MoveCursor", "(", "1", ",", "0", ",", "true", ")", "\n", "}" ]
// EditWrite writes a rune at the cursor position.
[ "EditWrite", "writes", "a", "rune", "at", "the", "cursor", "position", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/edit.go#L56-L59
train
jroimartin/gocui
edit.go
EditDelete
func (v *View) EditDelete(back bool) { x, y := v.ox+v.cx, v.oy+v.cy if y < 0 { return } else if y >= len(v.viewLines) { v.MoveCursor(-1, 0, true) return } maxX, _ := v.Size() if back { if x == 0 { // start of the line if y < 1 { return } var maxPrevWidth int if v.Wrap { maxPrevWidth = maxX } else { maxPrevWidth = maxInt } if v.viewLines[y].linesX == 0 { // regular line v.mergeLines(v.cy - 1) if len(v.viewLines[y-1].line) < maxPrevWidth { v.MoveCursor(-1, 0, true) } } else { // wrapped line v.deleteRune(len(v.viewLines[y-1].line)-1, v.cy-1) v.MoveCursor(-1, 0, true) } } else { // middle/end of the line v.deleteRune(v.cx-1, v.cy) v.MoveCursor(-1, 0, true) } } else { if x == len(v.viewLines[y].line) { // end of the line v.mergeLines(v.cy) } else { // start/middle of the line v.deleteRune(v.cx, v.cy) } } }
go
func (v *View) EditDelete(back bool) { x, y := v.ox+v.cx, v.oy+v.cy if y < 0 { return } else if y >= len(v.viewLines) { v.MoveCursor(-1, 0, true) return } maxX, _ := v.Size() if back { if x == 0 { // start of the line if y < 1 { return } var maxPrevWidth int if v.Wrap { maxPrevWidth = maxX } else { maxPrevWidth = maxInt } if v.viewLines[y].linesX == 0 { // regular line v.mergeLines(v.cy - 1) if len(v.viewLines[y-1].line) < maxPrevWidth { v.MoveCursor(-1, 0, true) } } else { // wrapped line v.deleteRune(len(v.viewLines[y-1].line)-1, v.cy-1) v.MoveCursor(-1, 0, true) } } else { // middle/end of the line v.deleteRune(v.cx-1, v.cy) v.MoveCursor(-1, 0, true) } } else { if x == len(v.viewLines[y].line) { // end of the line v.mergeLines(v.cy) } else { // start/middle of the line v.deleteRune(v.cx, v.cy) } } }
[ "func", "(", "v", "*", "View", ")", "EditDelete", "(", "back", "bool", ")", "{", "x", ",", "y", ":=", "v", ".", "ox", "+", "v", ".", "cx", ",", "v", ".", "oy", "+", "v", ".", "cy", "\n", "if", "y", "<", "0", "{", "return", "\n", "}", "else", "if", "y", ">=", "len", "(", "v", ".", "viewLines", ")", "{", "v", ".", "MoveCursor", "(", "-", "1", ",", "0", ",", "true", ")", "\n", "return", "\n", "}", "\n", "maxX", ",", "_", ":=", "v", ".", "Size", "(", ")", "\n", "if", "back", "{", "if", "x", "==", "0", "{", "if", "y", "<", "1", "{", "return", "\n", "}", "\n", "var", "maxPrevWidth", "int", "\n", "if", "v", ".", "Wrap", "{", "maxPrevWidth", "=", "maxX", "\n", "}", "else", "{", "maxPrevWidth", "=", "maxInt", "\n", "}", "\n", "if", "v", ".", "viewLines", "[", "y", "]", ".", "linesX", "==", "0", "{", "v", ".", "mergeLines", "(", "v", ".", "cy", "-", "1", ")", "\n", "if", "len", "(", "v", ".", "viewLines", "[", "y", "-", "1", "]", ".", "line", ")", "<", "maxPrevWidth", "{", "v", ".", "MoveCursor", "(", "-", "1", ",", "0", ",", "true", ")", "\n", "}", "\n", "}", "else", "{", "v", ".", "deleteRune", "(", "len", "(", "v", ".", "viewLines", "[", "y", "-", "1", "]", ".", "line", ")", "-", "1", ",", "v", ".", "cy", "-", "1", ")", "\n", "v", ".", "MoveCursor", "(", "-", "1", ",", "0", ",", "true", ")", "\n", "}", "\n", "}", "else", "{", "v", ".", "deleteRune", "(", "v", ".", "cx", "-", "1", ",", "v", ".", "cy", ")", "\n", "v", ".", "MoveCursor", "(", "-", "1", ",", "0", ",", "true", ")", "\n", "}", "\n", "}", "else", "{", "if", "x", "==", "len", "(", "v", ".", "viewLines", "[", "y", "]", ".", "line", ")", "{", "v", ".", "mergeLines", "(", "v", ".", "cy", ")", "\n", "}", "else", "{", "v", ".", "deleteRune", "(", "v", ".", "cx", ",", "v", ".", "cy", ")", "\n", "}", "\n", "}", "\n", "}" ]
// EditDelete deletes a rune at the cursor position. back determines the // direction.
[ "EditDelete", "deletes", "a", "rune", "at", "the", "cursor", "position", ".", "back", "determines", "the", "direction", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/edit.go#L63-L106
train
jroimartin/gocui
edit.go
EditNewLine
func (v *View) EditNewLine() { v.breakLine(v.cx, v.cy) v.ox = 0 v.cx = 0 v.MoveCursor(0, 1, true) }
go
func (v *View) EditNewLine() { v.breakLine(v.cx, v.cy) v.ox = 0 v.cx = 0 v.MoveCursor(0, 1, true) }
[ "func", "(", "v", "*", "View", ")", "EditNewLine", "(", ")", "{", "v", ".", "breakLine", "(", "v", ".", "cx", ",", "v", ".", "cy", ")", "\n", "v", ".", "ox", "=", "0", "\n", "v", ".", "cx", "=", "0", "\n", "v", ".", "MoveCursor", "(", "0", ",", "1", ",", "true", ")", "\n", "}" ]
// EditNewLine inserts a new line under the cursor.
[ "EditNewLine", "inserts", "a", "new", "line", "under", "the", "cursor", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/edit.go#L109-L114
train
jroimartin/gocui
edit.go
mergeLines
func (v *View) mergeLines(y int) error { v.tainted = true _, y, err := v.realPosition(0, y) if err != nil { return err } if y < 0 || y >= len(v.lines) { return errors.New("invalid point") } if y < len(v.lines)-1 { // otherwise we don't need to merge anything v.lines[y] = append(v.lines[y], v.lines[y+1]...) v.lines = append(v.lines[:y+1], v.lines[y+2:]...) } return nil }
go
func (v *View) mergeLines(y int) error { v.tainted = true _, y, err := v.realPosition(0, y) if err != nil { return err } if y < 0 || y >= len(v.lines) { return errors.New("invalid point") } if y < len(v.lines)-1 { // otherwise we don't need to merge anything v.lines[y] = append(v.lines[y], v.lines[y+1]...) v.lines = append(v.lines[:y+1], v.lines[y+2:]...) } return nil }
[ "func", "(", "v", "*", "View", ")", "mergeLines", "(", "y", "int", ")", "error", "{", "v", ".", "tainted", "=", "true", "\n", "_", ",", "y", ",", "err", ":=", "v", ".", "realPosition", "(", "0", ",", "y", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "y", "<", "0", "||", "y", ">=", "len", "(", "v", ".", "lines", ")", "{", "return", "errors", ".", "New", "(", "\"invalid point\"", ")", "\n", "}", "\n", "if", "y", "<", "len", "(", "v", ".", "lines", ")", "-", "1", "{", "v", ".", "lines", "[", "y", "]", "=", "append", "(", "v", ".", "lines", "[", "y", "]", ",", "v", ".", "lines", "[", "y", "+", "1", "]", "...", ")", "\n", "v", ".", "lines", "=", "append", "(", "v", ".", "lines", "[", ":", "y", "+", "1", "]", ",", "v", ".", "lines", "[", "y", "+", "2", ":", "]", "...", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// mergeLines merges the lines "y" and "y+1" if possible.
[ "mergeLines", "merges", "the", "lines", "y", "and", "y", "+", "1", "if", "possible", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/edit.go#L294-L311
train
jroimartin/gocui
keybinding.go
newKeybinding
func newKeybinding(viewname string, key Key, ch rune, mod Modifier, handler func(*Gui, *View) error) (kb *keybinding) { kb = &keybinding{ viewName: viewname, key: key, ch: ch, mod: mod, handler: handler, } return kb }
go
func newKeybinding(viewname string, key Key, ch rune, mod Modifier, handler func(*Gui, *View) error) (kb *keybinding) { kb = &keybinding{ viewName: viewname, key: key, ch: ch, mod: mod, handler: handler, } return kb }
[ "func", "newKeybinding", "(", "viewname", "string", ",", "key", "Key", ",", "ch", "rune", ",", "mod", "Modifier", ",", "handler", "func", "(", "*", "Gui", ",", "*", "View", ")", "error", ")", "(", "kb", "*", "keybinding", ")", "{", "kb", "=", "&", "keybinding", "{", "viewName", ":", "viewname", ",", "key", ":", "key", ",", "ch", ":", "ch", ",", "mod", ":", "mod", ",", "handler", ":", "handler", ",", "}", "\n", "return", "kb", "\n", "}" ]
// newKeybinding returns a new Keybinding object.
[ "newKeybinding", "returns", "a", "new", "Keybinding", "object", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/keybinding.go#L19-L28
train
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", "(", "\"invalid point\"", ")", "\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", "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", "termbox", ".", "SetCell", "(", "v", ".", "x0", "+", "x", "+", "1", ",", "v", ".", "y0", "+", "y", "+", "1", ",", "ch", ",", "termbox", ".", "Attribute", "(", "fgColor", ")", ",", "termbox", ".", "Attribute", "(", "bgColor", ")", ")", "\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", "(", "\"invalid point\"", ")", "\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", "(", "\"invalid point\"", ")", "\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", "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", "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", "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", "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", "if", "v", ".", "Wrap", "{", "if", "maxX", "==", "0", "{", "return", "errors", ".", "New", "(", "\"X size of the view cannot be 0\"", ")", "\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", "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", "fgColor", ":=", "c", ".", "fgColor", "\n", "if", "fgColor", "==", "ColorDefault", "{", "fgColor", "=", "v", ".", "FgColor", "\n", "}", "\n", "bgColor", ":=", "c", ".", "bgColor", "\n", "if", "bgColor", "==", "ColorDefault", "{", "bgColor", "=", "v", ".", "BgColor", "\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", "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\"", ",", "\\x00", ",", "\" \"", ")", "\n", "-", "1", "\n", "}", "\n", "lines", "[", "i", "]", "=", "str", "\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", "\\n", "\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\"", ",", "\\x00", ",", "\" \"", ")", "\n", "-", "1", "\n", "}", "\n", "lines", "[", "i", "]", "=", "str", "\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", "\\n", "\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", ")", "{", "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", "ei", ".", "curch", "=", "ch", "\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", ",", "\"0\"", ")", "\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", "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", "g", ":=", "&", "Gui", "{", "}", "\n", "g", ".", "outputMode", "=", "mode", "\n", "termbox", ".", "SetOutputMode", "(", "termbox", ".", "OutputMode", "(", "mode", ")", ")", "\n", "g", ".", "tbEvents", "=", "make", "(", "chan", "termbox", ".", "Event", ",", "20", ")", "\n", "g", ".", "userEvents", "=", "make", "(", "chan", "userEvent", ",", "20", ")", "\n", "g", ".", "maxX", ",", "g", ".", "maxY", "=", "termbox", ".", "Size", "(", ")", "\n", "g", ".", "BgColor", ",", "g", ".", "FgColor", "=", "ColorDefault", ",", "ColorDefault", "\n", "g", ".", "SelBgColor", ",", "g", ".", "SelFgColor", "=", "ColorDefault", ",", "ColorDefault", "\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", "(", "\"invalid point\"", ")", "\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", "(", "\"invalid point\"", ")", "\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", ")", "{", "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", "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", "(", "\"keybinding not found\"", ")", "\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", "(", "\"unknown type\"", ")", "\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", "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", "inputMode", ":=", "termbox", ".", "InputAlt", "\n", "if", "g", ".", "InputEsc", "{", "inputMode", "=", "termbox", ".", "InputEsc", "\n", "}", "\n", "if", "g", ".", "Mouse", "{", "inputMode", "|=", "termbox", ".", "InputMouse", "\n", "}", "\n", "termbox", ".", "SetInputMode", "(", "inputMode", ")", "\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", "maxX", ",", "maxY", ":=", "termbox", ".", "Size", "(", ")", "\n", "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", "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", "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", "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", ":=", "'┌', ", "'", "', '└", "'", " '┘'", ",", "rune_literal", "\n", "if", "g", ".", "ASCII", "{", "runeTL", ",", "runeTR", ",", "runeBL", ",", "runeBR", "=", "'+'", ",", "'+'", ",", "'+'", ",", "'+'", "\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", "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", "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", "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", "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", "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", "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", "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", "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", "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", "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", "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", "if", "err", ":=", "s", ".", "Send", "(", "req", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "pid", ",", "err", ":=", "s", ".", "GetPid", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "res", "[", "]", "[", "]", "byte", "\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", "(", "\"Wrong Seq nr %d, expected %d\"", ",", "m", ".", "Header", ".", "Seq", ",", "req", ".", "Seq", ")", "\n", "}", "\n", "if", "m", ".", "Header", ".", "Pid", "!=", "pid", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"Wrong pid %d, expected %d\"", ",", "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", "{", "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", "{", "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", "msgs", ",", "err", ":=", "req", ".", "Execute", "(", "unix", ".", "NETLINK_ROUTE", ",", "unix", ".", "RTM_NEWNEIGH", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "res", "[", "]", "Neigh", "\n", "for", "_", ",", "m", ":=", "range", "msgs", "{", "ndm", ":=", "deserializeNdmsg", "(", "m", ")", "\n", "if", "msg", ".", "Index", "!=", "0", "&&", "ndm", ".", "Index", "!=", "msg", ".", "Index", "{", "continue", "\n", "}", "\n", "neigh", ",", "err", ":=", "NeighDeserialize", "(", "m", ")", "\n", "if", "err", "!=", "nil", "{", "continue", "\n", "}", "\n", "res", "=", "append", "(", "res", ",", "*", "neigh", ")", "\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", "(", "\"Filter attribute already present\"", ")", "\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", "{", "return", "false", "\n", "}", "\n", "match", ":=", "true", "\n", "if", "elem", ",", "found", ":=", "f", ".", "ipFilter", "[", "ConntrackOrigSrcIP", "]", ";", "found", "{", "match", "=", "match", "&&", "elem", ".", "Equal", "(", "flow", ".", "Forward", ".", "SrcIP", ")", "\n", "}", "\n", "if", "elem", ",", "found", ":=", "f", ".", "ipFilter", "[", "ConntrackOrigDstIP", "]", ";", "match", "&&", "found", "{", "match", "=", "match", "&&", "elem", ".", "Equal", "(", "flow", ".", "Forward", ".", "DstIP", ")", "\n", "}", "\n", "if", "elem", ",", "found", ":=", "f", ".", "ipFilter", "[", "ConntrackReplySrcIP", "]", ";", "match", "&&", "found", "{", "match", "=", "match", "&&", "elem", ".", "Equal", "(", "flow", ".", "Reverse", ".", "SrcIP", ")", "\n", "}", "\n", "if", "elem", ",", "found", ":=", "f", ".", "ipFilter", "[", "ConntrackReplyDstIP", "]", ";", "match", "&&", "found", "{", "match", "=", "match", "&&", "elem", ".", "Equal", "(", "flow", ".", "Reverse", ".", "DstIP", ")", "\n", "}", "\n", "if", "elem", ",", "found", ":=", "f", ".", "ipFilter", "[", "ConntrackReplyAnyIP", "]", ";", "match", "&&", "found", "{", "match", "=", "match", "&&", "(", "elem", ".", "Equal", "(", "flow", ".", "Reverse", ".", "SrcIP", ")", "||", "elem", ".", "Equal", "(", "flow", ".", "Reverse", ".", "DstIP", ")", ")", "\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", "\"<nil>\"", "\n", "}", "\n", "var", "boolStrings", "[", "]", "string", "\n", "if", "prot", ".", "Hairpin", "{", "boolStrings", "=", "append", "(", "boolStrings", ",", "\"Hairpin\"", ")", "\n", "}", "\n", "if", "prot", ".", "Guard", "{", "boolStrings", "=", "append", "(", "boolStrings", ",", "\"Guard\"", ")", "\n", "}", "\n", "if", "prot", ".", "FastLeave", "{", "boolStrings", "=", "append", "(", "boolStrings", ",", "\"FastLeave\"", ")", "\n", "}", "\n", "if", "prot", ".", "RootBlock", "{", "boolStrings", "=", "append", "(", "boolStrings", ",", "\"RootBlock\"", ")", "\n", "}", "\n", "if", "prot", ".", "Learning", "{", "boolStrings", "=", "append", "(", "boolStrings", ",", "\"Learning\"", ")", "\n", "}", "\n", "if", "prot", ".", "Flood", "{", "boolStrings", "=", "append", "(", "boolStrings", ",", "\"Flood\"", ")", "\n", "}", "\n", "if", "prot", ".", "ProxyArp", "{", "boolStrings", "=", "append", "(", "boolStrings", ",", "\"ProxyArp\"", ")", "\n", "}", "\n", "if", "prot", ".", "ProxyArpWiFi", "{", "boolStrings", "=", "append", "(", "boolStrings", ",", "\"ProxyArpWiFi\"", ")", "\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