id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequencelengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
sequencelengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
6,500
opencontainers/selinux
go-selinux/selinux_linux.go
FileLabel
func FileLabel(fpath string) (string, error) { if fpath == "" { return "", ErrEmptyPath } label, err := lgetxattr(fpath, xattrNameSelinux) if err != nil { return "", err } // Trim the NUL byte at the end of the byte buffer, if present. if len(label) > 0 && label[len(label)-1] == '\x00' { label = label[:len(label)-1] } return string(label), nil }
go
func FileLabel(fpath string) (string, error) { if fpath == "" { return "", ErrEmptyPath } label, err := lgetxattr(fpath, xattrNameSelinux) if err != nil { return "", err } // Trim the NUL byte at the end of the byte buffer, if present. if len(label) > 0 && label[len(label)-1] == '\x00' { label = label[:len(label)-1] } return string(label), nil }
[ "func", "FileLabel", "(", "fpath", "string", ")", "(", "string", ",", "error", ")", "{", "if", "fpath", "==", "\"", "\"", "{", "return", "\"", "\"", ",", "ErrEmptyPath", "\n", "}", "\n\n", "label", ",", "err", ":=", "lgetxattr", "(", "fpath", ",", "xattrNameSelinux", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "// Trim the NUL byte at the end of the byte buffer, if present.", "if", "len", "(", "label", ")", ">", "0", "&&", "label", "[", "len", "(", "label", ")", "-", "1", "]", "==", "'\\x00'", "{", "label", "=", "label", "[", ":", "len", "(", "label", ")", "-", "1", "]", "\n", "}", "\n", "return", "string", "(", "label", ")", ",", "nil", "\n", "}" ]
// FileLabel returns the SELinux label for this path or returns an error.
[ "FileLabel", "returns", "the", "SELinux", "label", "for", "this", "path", "or", "returns", "an", "error", "." ]
bed85457b2045f53cd0d11ef8b5a8af23079720e
https://github.com/opencontainers/selinux/blob/bed85457b2045f53cd0d11ef8b5a8af23079720e/go-selinux/selinux_linux.go#L282-L296
6,501
opencontainers/selinux
go-selinux/selinux_linux.go
SetKeyLabel
func SetKeyLabel(label string) error { err := writeCon("/proc/self/attr/keycreate", label) if os.IsNotExist(err) { return nil } if label == "" && os.IsPermission(err) && !GetEnabled() { return nil } return err }
go
func SetKeyLabel(label string) error { err := writeCon("/proc/self/attr/keycreate", label) if os.IsNotExist(err) { return nil } if label == "" && os.IsPermission(err) && !GetEnabled() { return nil } return err }
[ "func", "SetKeyLabel", "(", "label", "string", ")", "error", "{", "err", ":=", "writeCon", "(", "\"", "\"", ",", "label", ")", "\n", "if", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "nil", "\n", "}", "\n", "if", "label", "==", "\"", "\"", "&&", "os", ".", "IsPermission", "(", "err", ")", "&&", "!", "GetEnabled", "(", ")", "{", "return", "nil", "\n", "}", "\n", "return", "err", "\n", "}" ]
// SetKeyLabel takes a process label and tells the kernel to assign the // label to the next kernel keyring that gets created
[ "SetKeyLabel", "takes", "a", "process", "label", "and", "tells", "the", "kernel", "to", "assign", "the", "label", "to", "the", "next", "kernel", "keyring", "that", "gets", "created" ]
bed85457b2045f53cd0d11ef8b5a8af23079720e
https://github.com/opencontainers/selinux/blob/bed85457b2045f53cd0d11ef8b5a8af23079720e/go-selinux/selinux_linux.go#L408-L417
6,502
opencontainers/selinux
go-selinux/selinux_linux.go
Get
func (c Context) Get() string { if c["level"] != "" { return fmt.Sprintf("%s:%s:%s:%s", c["user"], c["role"], c["type"], c["level"]) } return fmt.Sprintf("%s:%s:%s", c["user"], c["role"], c["type"]) }
go
func (c Context) Get() string { if c["level"] != "" { return fmt.Sprintf("%s:%s:%s:%s", c["user"], c["role"], c["type"], c["level"]) } return fmt.Sprintf("%s:%s:%s", c["user"], c["role"], c["type"]) }
[ "func", "(", "c", "Context", ")", "Get", "(", ")", "string", "{", "if", "c", "[", "\"", "\"", "]", "!=", "\"", "\"", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", "[", "\"", "\"", "]", ",", "c", "[", "\"", "\"", "]", ",", "c", "[", "\"", "\"", "]", ",", "c", "[", "\"", "\"", "]", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", "[", "\"", "\"", "]", ",", "c", "[", "\"", "\"", "]", ",", "c", "[", "\"", "\"", "]", ")", "\n", "}" ]
// Get returns the Context as a string
[ "Get", "returns", "the", "Context", "as", "a", "string" ]
bed85457b2045f53cd0d11ef8b5a8af23079720e
https://github.com/opencontainers/selinux/blob/bed85457b2045f53cd0d11ef8b5a8af23079720e/go-selinux/selinux_linux.go#L425-L430
6,503
opencontainers/selinux
go-selinux/selinux_linux.go
ClearLabels
func ClearLabels() { state.Lock() state.mcsList = make(map[string]bool) state.Unlock() }
go
func ClearLabels() { state.Lock() state.mcsList = make(map[string]bool) state.Unlock() }
[ "func", "ClearLabels", "(", ")", "{", "state", ".", "Lock", "(", ")", "\n", "state", ".", "mcsList", "=", "make", "(", "map", "[", "string", "]", "bool", ")", "\n", "state", ".", "Unlock", "(", ")", "\n", "}" ]
// ClearLabels clears all reserved labels
[ "ClearLabels", "clears", "all", "reserved", "labels" ]
bed85457b2045f53cd0d11ef8b5a8af23079720e
https://github.com/opencontainers/selinux/blob/bed85457b2045f53cd0d11ef8b5a8af23079720e/go-selinux/selinux_linux.go#L452-L456
6,504
opencontainers/selinux
go-selinux/selinux_linux.go
EnforceMode
func EnforceMode() int { var enforce int enforceS, err := readCon(selinuxEnforcePath()) if err != nil { return -1 } enforce, err = strconv.Atoi(string(enforceS)) if err != nil { return -1 } return enforce }
go
func EnforceMode() int { var enforce int enforceS, err := readCon(selinuxEnforcePath()) if err != nil { return -1 } enforce, err = strconv.Atoi(string(enforceS)) if err != nil { return -1 } return enforce }
[ "func", "EnforceMode", "(", ")", "int", "{", "var", "enforce", "int", "\n\n", "enforceS", ",", "err", ":=", "readCon", "(", "selinuxEnforcePath", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", "\n", "}", "\n\n", "enforce", ",", "err", "=", "strconv", ".", "Atoi", "(", "string", "(", "enforceS", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", "\n", "}", "\n", "return", "enforce", "\n", "}" ]
// EnforceMode returns the current SELinux mode Enforcing, Permissive, Disabled
[ "EnforceMode", "returns", "the", "current", "SELinux", "mode", "Enforcing", "Permissive", "Disabled" ]
bed85457b2045f53cd0d11ef8b5a8af23079720e
https://github.com/opencontainers/selinux/blob/bed85457b2045f53cd0d11ef8b5a8af23079720e/go-selinux/selinux_linux.go#L473-L486
6,505
opencontainers/selinux
go-selinux/selinux_linux.go
badPrefix
func badPrefix(fpath string) error { if fpath == "" { return ErrEmptyPath } badPrefixes := []string{"/usr"} for _, prefix := range badPrefixes { if strings.HasPrefix(fpath, prefix) { return fmt.Errorf("relabeling content in %s is not allowed", prefix) } } return nil }
go
func badPrefix(fpath string) error { if fpath == "" { return ErrEmptyPath } badPrefixes := []string{"/usr"} for _, prefix := range badPrefixes { if strings.HasPrefix(fpath, prefix) { return fmt.Errorf("relabeling content in %s is not allowed", prefix) } } return nil }
[ "func", "badPrefix", "(", "fpath", "string", ")", "error", "{", "if", "fpath", "==", "\"", "\"", "{", "return", "ErrEmptyPath", "\n", "}", "\n\n", "badPrefixes", ":=", "[", "]", "string", "{", "\"", "\"", "}", "\n", "for", "_", ",", "prefix", ":=", "range", "badPrefixes", "{", "if", "strings", ".", "HasPrefix", "(", "fpath", ",", "prefix", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "prefix", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Prevent users from relabing system files
[ "Prevent", "users", "from", "relabing", "system", "files" ]
bed85457b2045f53cd0d11ef8b5a8af23079720e
https://github.com/opencontainers/selinux/blob/bed85457b2045f53cd0d11ef8b5a8af23079720e/go-selinux/selinux_linux.go#L707-L719
6,506
opencontainers/selinux
go-selinux/selinux_linux.go
Chcon
func Chcon(fpath string, label string, recurse bool) error { if fpath == "" { return ErrEmptyPath } if label == "" { return nil } if err := badPrefix(fpath); err != nil { return err } callback := func(p string, info os.FileInfo, err error) error { e := SetFileLabel(p, label) if os.IsNotExist(e) { return nil } return e } if recurse { return filepath.Walk(fpath, callback) } return SetFileLabel(fpath, label) }
go
func Chcon(fpath string, label string, recurse bool) error { if fpath == "" { return ErrEmptyPath } if label == "" { return nil } if err := badPrefix(fpath); err != nil { return err } callback := func(p string, info os.FileInfo, err error) error { e := SetFileLabel(p, label) if os.IsNotExist(e) { return nil } return e } if recurse { return filepath.Walk(fpath, callback) } return SetFileLabel(fpath, label) }
[ "func", "Chcon", "(", "fpath", "string", ",", "label", "string", ",", "recurse", "bool", ")", "error", "{", "if", "fpath", "==", "\"", "\"", "{", "return", "ErrEmptyPath", "\n", "}", "\n", "if", "label", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n", "if", "err", ":=", "badPrefix", "(", "fpath", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "callback", ":=", "func", "(", "p", "string", ",", "info", "os", ".", "FileInfo", ",", "err", "error", ")", "error", "{", "e", ":=", "SetFileLabel", "(", "p", ",", "label", ")", "\n", "if", "os", ".", "IsNotExist", "(", "e", ")", "{", "return", "nil", "\n", "}", "\n", "return", "e", "\n", "}", "\n\n", "if", "recurse", "{", "return", "filepath", ".", "Walk", "(", "fpath", ",", "callback", ")", "\n", "}", "\n\n", "return", "SetFileLabel", "(", "fpath", ",", "label", ")", "\n", "}" ]
// Chcon changes the `fpath` file object to the SELinux label `label`. // If `fpath` is a directory and `recurse`` is true, Chcon will walk the // directory tree setting the label.
[ "Chcon", "changes", "the", "fpath", "file", "object", "to", "the", "SELinux", "label", "label", ".", "If", "fpath", "is", "a", "directory", "and", "recurse", "is", "true", "Chcon", "will", "walk", "the", "directory", "tree", "setting", "the", "label", "." ]
bed85457b2045f53cd0d11ef8b5a8af23079720e
https://github.com/opencontainers/selinux/blob/bed85457b2045f53cd0d11ef8b5a8af23079720e/go-selinux/selinux_linux.go#L724-L747
6,507
opencontainers/selinux
go-selinux/selinux_linux.go
DupSecOpt
func DupSecOpt(src string) ([]string, error) { if src == "" { return nil, nil } con, err := NewContext(src) if err != nil { return nil, err } if con["user"] == "" || con["role"] == "" || con["type"] == "" { return nil, nil } dup := []string{"user:" + con["user"], "role:" + con["role"], "type:" + con["type"], } if con["level"] != "" { dup = append(dup, "level:"+con["level"]) } return dup, nil }
go
func DupSecOpt(src string) ([]string, error) { if src == "" { return nil, nil } con, err := NewContext(src) if err != nil { return nil, err } if con["user"] == "" || con["role"] == "" || con["type"] == "" { return nil, nil } dup := []string{"user:" + con["user"], "role:" + con["role"], "type:" + con["type"], } if con["level"] != "" { dup = append(dup, "level:"+con["level"]) } return dup, nil }
[ "func", "DupSecOpt", "(", "src", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "src", "==", "\"", "\"", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "con", ",", "err", ":=", "NewContext", "(", "src", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "con", "[", "\"", "\"", "]", "==", "\"", "\"", "||", "con", "[", "\"", "\"", "]", "==", "\"", "\"", "||", "con", "[", "\"", "\"", "]", "==", "\"", "\"", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "dup", ":=", "[", "]", "string", "{", "\"", "\"", "+", "con", "[", "\"", "\"", "]", ",", "\"", "\"", "+", "con", "[", "\"", "\"", "]", ",", "\"", "\"", "+", "con", "[", "\"", "\"", "]", ",", "}", "\n\n", "if", "con", "[", "\"", "\"", "]", "!=", "\"", "\"", "{", "dup", "=", "append", "(", "dup", ",", "\"", "\"", "+", "con", "[", "\"", "\"", "]", ")", "\n", "}", "\n\n", "return", "dup", ",", "nil", "\n", "}" ]
// DupSecOpt takes an SELinux process label and returns security options that // can be used to set the SELinux Type and Level for future container processes.
[ "DupSecOpt", "takes", "an", "SELinux", "process", "label", "and", "returns", "security", "options", "that", "can", "be", "used", "to", "set", "the", "SELinux", "Type", "and", "Level", "for", "future", "container", "processes", "." ]
bed85457b2045f53cd0d11ef8b5a8af23079720e
https://github.com/opencontainers/selinux/blob/bed85457b2045f53cd0d11ef8b5a8af23079720e/go-selinux/selinux_linux.go#L751-L774
6,508
moul/protoc-gen-gotemplate
helpers/helpers.go
addToPathMap
func addToPathMap(info *descriptor.SourceCodeInfo, i interface{}, path []int32) { loc := findLoc(info, path) if loc != nil { pathMap[i] = loc } switch d := i.(type) { case *descriptor.FileDescriptorProto: for index, descriptor := range d.MessageType { addToPathMap(info, descriptor, newPath(path, 4, index)) } for index, descriptor := range d.EnumType { addToPathMap(info, descriptor, newPath(path, 5, index)) } for index, descriptor := range d.Service { addToPathMap(info, descriptor, newPath(path, 6, index)) } case *descriptor.DescriptorProto: for index, descriptor := range d.Field { addToPathMap(info, descriptor, newPath(path, 2, index)) } for index, descriptor := range d.NestedType { addToPathMap(info, descriptor, newPath(path, 3, index)) } for index, descriptor := range d.EnumType { addToPathMap(info, descriptor, newPath(path, 4, index)) } case *descriptor.EnumDescriptorProto: for index, descriptor := range d.Value { addToPathMap(info, descriptor, newPath(path, 2, index)) } case *descriptor.ServiceDescriptorProto: for index, descriptor := range d.Method { addToPathMap(info, descriptor, newPath(path, 2, index)) } } }
go
func addToPathMap(info *descriptor.SourceCodeInfo, i interface{}, path []int32) { loc := findLoc(info, path) if loc != nil { pathMap[i] = loc } switch d := i.(type) { case *descriptor.FileDescriptorProto: for index, descriptor := range d.MessageType { addToPathMap(info, descriptor, newPath(path, 4, index)) } for index, descriptor := range d.EnumType { addToPathMap(info, descriptor, newPath(path, 5, index)) } for index, descriptor := range d.Service { addToPathMap(info, descriptor, newPath(path, 6, index)) } case *descriptor.DescriptorProto: for index, descriptor := range d.Field { addToPathMap(info, descriptor, newPath(path, 2, index)) } for index, descriptor := range d.NestedType { addToPathMap(info, descriptor, newPath(path, 3, index)) } for index, descriptor := range d.EnumType { addToPathMap(info, descriptor, newPath(path, 4, index)) } case *descriptor.EnumDescriptorProto: for index, descriptor := range d.Value { addToPathMap(info, descriptor, newPath(path, 2, index)) } case *descriptor.ServiceDescriptorProto: for index, descriptor := range d.Method { addToPathMap(info, descriptor, newPath(path, 2, index)) } } }
[ "func", "addToPathMap", "(", "info", "*", "descriptor", ".", "SourceCodeInfo", ",", "i", "interface", "{", "}", ",", "path", "[", "]", "int32", ")", "{", "loc", ":=", "findLoc", "(", "info", ",", "path", ")", "\n", "if", "loc", "!=", "nil", "{", "pathMap", "[", "i", "]", "=", "loc", "\n", "}", "\n", "switch", "d", ":=", "i", ".", "(", "type", ")", "{", "case", "*", "descriptor", ".", "FileDescriptorProto", ":", "for", "index", ",", "descriptor", ":=", "range", "d", ".", "MessageType", "{", "addToPathMap", "(", "info", ",", "descriptor", ",", "newPath", "(", "path", ",", "4", ",", "index", ")", ")", "\n", "}", "\n", "for", "index", ",", "descriptor", ":=", "range", "d", ".", "EnumType", "{", "addToPathMap", "(", "info", ",", "descriptor", ",", "newPath", "(", "path", ",", "5", ",", "index", ")", ")", "\n", "}", "\n", "for", "index", ",", "descriptor", ":=", "range", "d", ".", "Service", "{", "addToPathMap", "(", "info", ",", "descriptor", ",", "newPath", "(", "path", ",", "6", ",", "index", ")", ")", "\n", "}", "\n", "case", "*", "descriptor", ".", "DescriptorProto", ":", "for", "index", ",", "descriptor", ":=", "range", "d", ".", "Field", "{", "addToPathMap", "(", "info", ",", "descriptor", ",", "newPath", "(", "path", ",", "2", ",", "index", ")", ")", "\n", "}", "\n", "for", "index", ",", "descriptor", ":=", "range", "d", ".", "NestedType", "{", "addToPathMap", "(", "info", ",", "descriptor", ",", "newPath", "(", "path", ",", "3", ",", "index", ")", ")", "\n", "}", "\n", "for", "index", ",", "descriptor", ":=", "range", "d", ".", "EnumType", "{", "addToPathMap", "(", "info", ",", "descriptor", ",", "newPath", "(", "path", ",", "4", ",", "index", ")", ")", "\n", "}", "\n", "case", "*", "descriptor", ".", "EnumDescriptorProto", ":", "for", "index", ",", "descriptor", ":=", "range", "d", ".", "Value", "{", "addToPathMap", "(", "info", ",", "descriptor", ",", "newPath", "(", "path", ",", "2", ",", "index", ")", ")", "\n", "}", "\n", "case", "*", "descriptor", ".", "ServiceDescriptorProto", ":", "for", "index", ",", "descriptor", ":=", "range", "d", ".", "Method", "{", "addToPathMap", "(", "info", ",", "descriptor", ",", "newPath", "(", "path", ",", "2", ",", "index", ")", ")", "\n", "}", "\n", "}", "\n", "}" ]
// addToPathMap traverses through the AST adding SourceCodeInfo_Location entries to the pathMap. // Since the AST is a tree, the recursion finishes once it has gone through all the nodes.
[ "addToPathMap", "traverses", "through", "the", "AST", "adding", "SourceCodeInfo_Location", "entries", "to", "the", "pathMap", ".", "Since", "the", "AST", "is", "a", "tree", "the", "recursion", "finishes", "once", "it", "has", "gone", "through", "all", "the", "nodes", "." ]
c6eca2356cc0338fcf24624d9c0f36db4b0481a7
https://github.com/moul/protoc-gen-gotemplate/blob/c6eca2356cc0338fcf24624d9c0f36db4b0481a7/helpers/helpers.go#L227-L262
6,509
moul/protoc-gen-gotemplate
helpers/helpers.go
goTypeWithPackage
func goTypeWithPackage(f *descriptor.FieldDescriptorProto) string { pkg := "" if *f.Type == descriptor.FieldDescriptorProto_TYPE_MESSAGE || *f.Type == descriptor.FieldDescriptorProto_TYPE_ENUM { if isTimestampPackage(*f.TypeName) { pkg = "timestamp" } else { pkg = getPackageTypeName(*f.TypeName) } } return goType(pkg, f) }
go
func goTypeWithPackage(f *descriptor.FieldDescriptorProto) string { pkg := "" if *f.Type == descriptor.FieldDescriptorProto_TYPE_MESSAGE || *f.Type == descriptor.FieldDescriptorProto_TYPE_ENUM { if isTimestampPackage(*f.TypeName) { pkg = "timestamp" } else { pkg = getPackageTypeName(*f.TypeName) } } return goType(pkg, f) }
[ "func", "goTypeWithPackage", "(", "f", "*", "descriptor", ".", "FieldDescriptorProto", ")", "string", "{", "pkg", ":=", "\"", "\"", "\n", "if", "*", "f", ".", "Type", "==", "descriptor", ".", "FieldDescriptorProto_TYPE_MESSAGE", "||", "*", "f", ".", "Type", "==", "descriptor", ".", "FieldDescriptorProto_TYPE_ENUM", "{", "if", "isTimestampPackage", "(", "*", "f", ".", "TypeName", ")", "{", "pkg", "=", "\"", "\"", "\n", "}", "else", "{", "pkg", "=", "getPackageTypeName", "(", "*", "f", ".", "TypeName", ")", "\n", "}", "\n", "}", "\n", "return", "goType", "(", "pkg", ",", "f", ")", "\n", "}" ]
// Warning does not handle message embedded like goTypeWithGoPackage does.
[ "Warning", "does", "not", "handle", "message", "embedded", "like", "goTypeWithGoPackage", "does", "." ]
c6eca2356cc0338fcf24624d9c0f36db4b0481a7
https://github.com/moul/protoc-gen-gotemplate/blob/c6eca2356cc0338fcf24624d9c0f36db4b0481a7/helpers/helpers.go#L797-L807
6,510
moul/protoc-gen-gotemplate
helpers/helpers.go
goType
func goType(pkg string, f *descriptor.FieldDescriptorProto) string { if pkg != "" { pkg = pkg + "." } switch *f.Type { case descriptor.FieldDescriptorProto_TYPE_DOUBLE: if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED { return "[]float64" } return "float64" case descriptor.FieldDescriptorProto_TYPE_FLOAT: if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED { return "[]float32" } return "float32" case descriptor.FieldDescriptorProto_TYPE_INT64: if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED { return "[]int64" } return "int64" case descriptor.FieldDescriptorProto_TYPE_UINT64: if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED { return "[]uint64" } return "uint64" case descriptor.FieldDescriptorProto_TYPE_INT32: if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED { return "[]int32" } return "int32" case descriptor.FieldDescriptorProto_TYPE_UINT32: if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED { return "[]uint32" } return "uint32" case descriptor.FieldDescriptorProto_TYPE_BOOL: if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED { return "[]bool" } return "bool" case descriptor.FieldDescriptorProto_TYPE_STRING: if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED { return "[]string" } return "string" case descriptor.FieldDescriptorProto_TYPE_MESSAGE: if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED { return fmt.Sprintf("[]*%s%s", pkg, shortType(*f.TypeName)) } return fmt.Sprintf("*%s%s", pkg, shortType(*f.TypeName)) case descriptor.FieldDescriptorProto_TYPE_BYTES: if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED { return "[]byte" } return "byte" case descriptor.FieldDescriptorProto_TYPE_ENUM: return fmt.Sprintf("*%s%s", pkg, shortType(*f.TypeName)) default: return "interface{}" } }
go
func goType(pkg string, f *descriptor.FieldDescriptorProto) string { if pkg != "" { pkg = pkg + "." } switch *f.Type { case descriptor.FieldDescriptorProto_TYPE_DOUBLE: if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED { return "[]float64" } return "float64" case descriptor.FieldDescriptorProto_TYPE_FLOAT: if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED { return "[]float32" } return "float32" case descriptor.FieldDescriptorProto_TYPE_INT64: if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED { return "[]int64" } return "int64" case descriptor.FieldDescriptorProto_TYPE_UINT64: if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED { return "[]uint64" } return "uint64" case descriptor.FieldDescriptorProto_TYPE_INT32: if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED { return "[]int32" } return "int32" case descriptor.FieldDescriptorProto_TYPE_UINT32: if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED { return "[]uint32" } return "uint32" case descriptor.FieldDescriptorProto_TYPE_BOOL: if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED { return "[]bool" } return "bool" case descriptor.FieldDescriptorProto_TYPE_STRING: if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED { return "[]string" } return "string" case descriptor.FieldDescriptorProto_TYPE_MESSAGE: if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED { return fmt.Sprintf("[]*%s%s", pkg, shortType(*f.TypeName)) } return fmt.Sprintf("*%s%s", pkg, shortType(*f.TypeName)) case descriptor.FieldDescriptorProto_TYPE_BYTES: if *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED { return "[]byte" } return "byte" case descriptor.FieldDescriptorProto_TYPE_ENUM: return fmt.Sprintf("*%s%s", pkg, shortType(*f.TypeName)) default: return "interface{}" } }
[ "func", "goType", "(", "pkg", "string", ",", "f", "*", "descriptor", ".", "FieldDescriptorProto", ")", "string", "{", "if", "pkg", "!=", "\"", "\"", "{", "pkg", "=", "pkg", "+", "\"", "\"", "\n", "}", "\n", "switch", "*", "f", ".", "Type", "{", "case", "descriptor", ".", "FieldDescriptorProto_TYPE_DOUBLE", ":", "if", "*", "f", ".", "Label", "==", "descriptor", ".", "FieldDescriptorProto_LABEL_REPEATED", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "\"", "\"", "\n", "case", "descriptor", ".", "FieldDescriptorProto_TYPE_FLOAT", ":", "if", "*", "f", ".", "Label", "==", "descriptor", ".", "FieldDescriptorProto_LABEL_REPEATED", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "\"", "\"", "\n", "case", "descriptor", ".", "FieldDescriptorProto_TYPE_INT64", ":", "if", "*", "f", ".", "Label", "==", "descriptor", ".", "FieldDescriptorProto_LABEL_REPEATED", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "\"", "\"", "\n", "case", "descriptor", ".", "FieldDescriptorProto_TYPE_UINT64", ":", "if", "*", "f", ".", "Label", "==", "descriptor", ".", "FieldDescriptorProto_LABEL_REPEATED", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "\"", "\"", "\n", "case", "descriptor", ".", "FieldDescriptorProto_TYPE_INT32", ":", "if", "*", "f", ".", "Label", "==", "descriptor", ".", "FieldDescriptorProto_LABEL_REPEATED", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "\"", "\"", "\n", "case", "descriptor", ".", "FieldDescriptorProto_TYPE_UINT32", ":", "if", "*", "f", ".", "Label", "==", "descriptor", ".", "FieldDescriptorProto_LABEL_REPEATED", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "\"", "\"", "\n", "case", "descriptor", ".", "FieldDescriptorProto_TYPE_BOOL", ":", "if", "*", "f", ".", "Label", "==", "descriptor", ".", "FieldDescriptorProto_LABEL_REPEATED", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "\"", "\"", "\n", "case", "descriptor", ".", "FieldDescriptorProto_TYPE_STRING", ":", "if", "*", "f", ".", "Label", "==", "descriptor", ".", "FieldDescriptorProto_LABEL_REPEATED", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "\"", "\"", "\n", "case", "descriptor", ".", "FieldDescriptorProto_TYPE_MESSAGE", ":", "if", "*", "f", ".", "Label", "==", "descriptor", ".", "FieldDescriptorProto_LABEL_REPEATED", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "pkg", ",", "shortType", "(", "*", "f", ".", "TypeName", ")", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "pkg", ",", "shortType", "(", "*", "f", ".", "TypeName", ")", ")", "\n", "case", "descriptor", ".", "FieldDescriptorProto_TYPE_BYTES", ":", "if", "*", "f", ".", "Label", "==", "descriptor", ".", "FieldDescriptorProto_LABEL_REPEATED", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "\"", "\"", "\n", "case", "descriptor", ".", "FieldDescriptorProto_TYPE_ENUM", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "pkg", ",", "shortType", "(", "*", "f", ".", "TypeName", ")", ")", "\n", "default", ":", "return", "\"", "\"", "\n", "}", "\n", "}" ]
//Deprecated. Instead use goTypeWithEmbedded
[ "Deprecated", ".", "Instead", "use", "goTypeWithEmbedded" ]
c6eca2356cc0338fcf24624d9c0f36db4b0481a7
https://github.com/moul/protoc-gen-gotemplate/blob/c6eca2356cc0338fcf24624d9c0f36db4b0481a7/helpers/helpers.go#L949-L1009
6,511
moul/protoc-gen-gotemplate
helpers/helpers.go
lowerGoNormalize
func lowerGoNormalize(s string) string { fmtd := xstrings.ToCamelCase(s) fmtd = xstrings.FirstRuneToLower(fmtd) return formatID(s, fmtd) }
go
func lowerGoNormalize(s string) string { fmtd := xstrings.ToCamelCase(s) fmtd = xstrings.FirstRuneToLower(fmtd) return formatID(s, fmtd) }
[ "func", "lowerGoNormalize", "(", "s", "string", ")", "string", "{", "fmtd", ":=", "xstrings", ".", "ToCamelCase", "(", "s", ")", "\n", "fmtd", "=", "xstrings", ".", "FirstRuneToLower", "(", "fmtd", ")", "\n", "return", "formatID", "(", "s", ",", "fmtd", ")", "\n", "}" ]
// lowerGoNormalize takes a string and applies formatting // rules to conform to Golang convention. It applies a camel // case filter, lowers the first character and formats fields // with `id` to `ID`.
[ "lowerGoNormalize", "takes", "a", "string", "and", "applies", "formatting", "rules", "to", "conform", "to", "Golang", "convention", ".", "It", "applies", "a", "camel", "case", "filter", "lowers", "the", "first", "character", "and", "formats", "fields", "with", "id", "to", "ID", "." ]
c6eca2356cc0338fcf24624d9c0f36db4b0481a7
https://github.com/moul/protoc-gen-gotemplate/blob/c6eca2356cc0338fcf24624d9c0f36db4b0481a7/helpers/helpers.go#L1229-L1233
6,512
moul/protoc-gen-gotemplate
helpers/helpers.go
goNormalize
func goNormalize(s string) string { fmtd := xstrings.ToCamelCase(s) return formatID(s, fmtd) }
go
func goNormalize(s string) string { fmtd := xstrings.ToCamelCase(s) return formatID(s, fmtd) }
[ "func", "goNormalize", "(", "s", "string", ")", "string", "{", "fmtd", ":=", "xstrings", ".", "ToCamelCase", "(", "s", ")", "\n", "return", "formatID", "(", "s", ",", "fmtd", ")", "\n", "}" ]
// goNormalize takes a string and applies formatting rules // to conform to Golang convention. It applies a camel case // filter and formats fields with `id` to `ID`.
[ "goNormalize", "takes", "a", "string", "and", "applies", "formatting", "rules", "to", "conform", "to", "Golang", "convention", ".", "It", "applies", "a", "camel", "case", "filter", "and", "formats", "fields", "with", "id", "to", "ID", "." ]
c6eca2356cc0338fcf24624d9c0f36db4b0481a7
https://github.com/moul/protoc-gen-gotemplate/blob/c6eca2356cc0338fcf24624d9c0f36db4b0481a7/helpers/helpers.go#L1238-L1241
6,513
moul/protoc-gen-gotemplate
helpers/helpers.go
formatID
func formatID(base string, formatted string) string { if formatted == "" { return formatted } switch { case base == "id": // id -> ID return "ID" case strings.HasPrefix(base, "id_"): // id_some -> IDSome return "ID" + formatted[2:] case strings.HasSuffix(base, "_id"): // some_id -> SomeID return formatted[:len(formatted)-2] + "ID" case strings.HasSuffix(base, "_ids"): // some_ids -> SomeIDs return formatted[:len(formatted)-3] + "IDs" } return formatted }
go
func formatID(base string, formatted string) string { if formatted == "" { return formatted } switch { case base == "id": // id -> ID return "ID" case strings.HasPrefix(base, "id_"): // id_some -> IDSome return "ID" + formatted[2:] case strings.HasSuffix(base, "_id"): // some_id -> SomeID return formatted[:len(formatted)-2] + "ID" case strings.HasSuffix(base, "_ids"): // some_ids -> SomeIDs return formatted[:len(formatted)-3] + "IDs" } return formatted }
[ "func", "formatID", "(", "base", "string", ",", "formatted", "string", ")", "string", "{", "if", "formatted", "==", "\"", "\"", "{", "return", "formatted", "\n", "}", "\n", "switch", "{", "case", "base", "==", "\"", "\"", ":", "// id -> ID", "return", "\"", "\"", "\n", "case", "strings", ".", "HasPrefix", "(", "base", ",", "\"", "\"", ")", ":", "// id_some -> IDSome", "return", "\"", "\"", "+", "formatted", "[", "2", ":", "]", "\n", "case", "strings", ".", "HasSuffix", "(", "base", ",", "\"", "\"", ")", ":", "// some_id -> SomeID", "return", "formatted", "[", ":", "len", "(", "formatted", ")", "-", "2", "]", "+", "\"", "\"", "\n", "case", "strings", ".", "HasSuffix", "(", "base", ",", "\"", "\"", ")", ":", "// some_ids -> SomeIDs", "return", "formatted", "[", ":", "len", "(", "formatted", ")", "-", "3", "]", "+", "\"", "\"", "\n", "}", "\n", "return", "formatted", "\n", "}" ]
// formatID takes a base string alonsgide a formatted string. // It acts as a transformation filter for fields containing // `id` in order to conform to Golang convention.
[ "formatID", "takes", "a", "base", "string", "alonsgide", "a", "formatted", "string", ".", "It", "acts", "as", "a", "transformation", "filter", "for", "fields", "containing", "id", "in", "order", "to", "conform", "to", "Golang", "convention", "." ]
c6eca2356cc0338fcf24624d9c0f36db4b0481a7
https://github.com/moul/protoc-gen-gotemplate/blob/c6eca2356cc0338fcf24624d9c0f36db4b0481a7/helpers/helpers.go#L1246-L1265
6,514
marcusolsson/tui-go
widget.go
SetSizePolicy
func (w *WidgetBase) SetSizePolicy(h, v SizePolicy) { w.sizePolicyX = h w.sizePolicyY = v }
go
func (w *WidgetBase) SetSizePolicy(h, v SizePolicy) { w.sizePolicyX = h w.sizePolicyY = v }
[ "func", "(", "w", "*", "WidgetBase", ")", "SetSizePolicy", "(", "h", ",", "v", "SizePolicy", ")", "{", "w", ".", "sizePolicyX", "=", "h", "\n", "w", ".", "sizePolicyY", "=", "v", "\n", "}" ]
// SetSizePolicy sets the size policy for horizontal and vertical directions.
[ "SetSizePolicy", "sets", "the", "size", "policy", "for", "horizontal", "and", "vertical", "directions", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/widget.go#L72-L75
6,515
marcusolsson/tui-go
progress.go
Draw
func (p *Progress) Draw(painter *Painter) { painter.DrawRune(0, 0, '[') painter.DrawRune(p.Size().X-1, 0, ']') start := 1 end := p.Size().X - 1 curr := int((float64(p.current) / float64(p.max)) * float64(end-start)) for i := start; i < curr; i++ { painter.DrawRune(i, 0, '=') } for i := curr + start; i < end; i++ { painter.DrawRune(i, 0, '-') } painter.DrawRune(curr, 0, '>') }
go
func (p *Progress) Draw(painter *Painter) { painter.DrawRune(0, 0, '[') painter.DrawRune(p.Size().X-1, 0, ']') start := 1 end := p.Size().X - 1 curr := int((float64(p.current) / float64(p.max)) * float64(end-start)) for i := start; i < curr; i++ { painter.DrawRune(i, 0, '=') } for i := curr + start; i < end; i++ { painter.DrawRune(i, 0, '-') } painter.DrawRune(curr, 0, '>') }
[ "func", "(", "p", "*", "Progress", ")", "Draw", "(", "painter", "*", "Painter", ")", "{", "painter", ".", "DrawRune", "(", "0", ",", "0", ",", "'['", ")", "\n", "painter", ".", "DrawRune", "(", "p", ".", "Size", "(", ")", ".", "X", "-", "1", ",", "0", ",", "']'", ")", "\n\n", "start", ":=", "1", "\n", "end", ":=", "p", ".", "Size", "(", ")", ".", "X", "-", "1", "\n", "curr", ":=", "int", "(", "(", "float64", "(", "p", ".", "current", ")", "/", "float64", "(", "p", ".", "max", ")", ")", "*", "float64", "(", "end", "-", "start", ")", ")", "\n\n", "for", "i", ":=", "start", ";", "i", "<", "curr", ";", "i", "++", "{", "painter", ".", "DrawRune", "(", "i", ",", "0", ",", "'='", ")", "\n", "}", "\n", "for", "i", ":=", "curr", "+", "start", ";", "i", "<", "end", ";", "i", "++", "{", "painter", ".", "DrawRune", "(", "i", ",", "0", ",", "'-'", ")", "\n", "}", "\n", "painter", ".", "DrawRune", "(", "curr", ",", "0", ",", "'>'", ")", "\n", "}" ]
// Draw draws the progress bar.
[ "Draw", "draws", "the", "progress", "bar", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/progress.go#L22-L37
6,516
marcusolsson/tui-go
painter.go
NewPainter
func NewPainter(s Surface, p *Theme) *Painter { return &Painter{ theme: p, surface: s, style: p.Style("normal"), mask: image.Rectangle{ Min: image.ZP, Max: s.Size(), }, } }
go
func NewPainter(s Surface, p *Theme) *Painter { return &Painter{ theme: p, surface: s, style: p.Style("normal"), mask: image.Rectangle{ Min: image.ZP, Max: s.Size(), }, } }
[ "func", "NewPainter", "(", "s", "Surface", ",", "p", "*", "Theme", ")", "*", "Painter", "{", "return", "&", "Painter", "{", "theme", ":", "p", ",", "surface", ":", "s", ",", "style", ":", "p", ".", "Style", "(", "\"", "\"", ")", ",", "mask", ":", "image", ".", "Rectangle", "{", "Min", ":", "image", ".", "ZP", ",", "Max", ":", "s", ".", "Size", "(", ")", ",", "}", ",", "}", "\n", "}" ]
// NewPainter returns a new instance of Painter.
[ "NewPainter", "returns", "a", "new", "instance", "of", "Painter", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/painter.go#L34-L44
6,517
marcusolsson/tui-go
painter.go
Translate
func (p *Painter) Translate(x, y int) { p.transforms = append(p.transforms, image.Point{x, y}) }
go
func (p *Painter) Translate(x, y int) { p.transforms = append(p.transforms, image.Point{x, y}) }
[ "func", "(", "p", "*", "Painter", ")", "Translate", "(", "x", ",", "y", "int", ")", "{", "p", ".", "transforms", "=", "append", "(", "p", ".", "transforms", ",", "image", ".", "Point", "{", "x", ",", "y", "}", ")", "\n", "}" ]
// Translate pushes a new translation transform to the stack.
[ "Translate", "pushes", "a", "new", "translation", "transform", "to", "the", "stack", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/painter.go#L47-L49
6,518
marcusolsson/tui-go
painter.go
Restore
func (p *Painter) Restore() { if len(p.transforms) > 0 { p.transforms = p.transforms[:len(p.transforms)-1] } }
go
func (p *Painter) Restore() { if len(p.transforms) > 0 { p.transforms = p.transforms[:len(p.transforms)-1] } }
[ "func", "(", "p", "*", "Painter", ")", "Restore", "(", ")", "{", "if", "len", "(", "p", ".", "transforms", ")", ">", "0", "{", "p", ".", "transforms", "=", "p", ".", "transforms", "[", ":", "len", "(", "p", ".", "transforms", ")", "-", "1", "]", "\n", "}", "\n", "}" ]
// Restore pops the latest transform from the stack.
[ "Restore", "pops", "the", "latest", "transform", "from", "the", "stack", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/painter.go#L52-L56
6,519
marcusolsson/tui-go
painter.go
Repaint
func (p *Painter) Repaint(w Widget) { p.mask = image.Rectangle{ Min: image.ZP, Max: p.surface.Size(), } p.surface.HideCursor() w.Resize(p.surface.Size()) p.Begin() w.Draw(p) p.End() }
go
func (p *Painter) Repaint(w Widget) { p.mask = image.Rectangle{ Min: image.ZP, Max: p.surface.Size(), } p.surface.HideCursor() w.Resize(p.surface.Size()) p.Begin() w.Draw(p) p.End() }
[ "func", "(", "p", "*", "Painter", ")", "Repaint", "(", "w", "Widget", ")", "{", "p", ".", "mask", "=", "image", ".", "Rectangle", "{", "Min", ":", "image", ".", "ZP", ",", "Max", ":", "p", ".", "surface", ".", "Size", "(", ")", ",", "}", "\n\n", "p", ".", "surface", ".", "HideCursor", "(", ")", "\n\n", "w", ".", "Resize", "(", "p", ".", "surface", ".", "Size", "(", ")", ")", "\n\n", "p", ".", "Begin", "(", ")", "\n", "w", ".", "Draw", "(", "p", ")", "\n", "p", ".", "End", "(", ")", "\n", "}" ]
// Repaint clears the surface, draws the scene and flushes it.
[ "Repaint", "clears", "the", "surface", "draws", "the", "scene", "and", "flushes", "it", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/painter.go#L69-L82
6,520
marcusolsson/tui-go
painter.go
DrawCursor
func (p *Painter) DrawCursor(x, y int) { wp := p.mapLocalToWorld(image.Point{x, y}) p.surface.SetCursor(wp.X, wp.Y) }
go
func (p *Painter) DrawCursor(x, y int) { wp := p.mapLocalToWorld(image.Point{x, y}) p.surface.SetCursor(wp.X, wp.Y) }
[ "func", "(", "p", "*", "Painter", ")", "DrawCursor", "(", "x", ",", "y", "int", ")", "{", "wp", ":=", "p", ".", "mapLocalToWorld", "(", "image", ".", "Point", "{", "x", ",", "y", "}", ")", "\n", "p", ".", "surface", ".", "SetCursor", "(", "wp", ".", "X", ",", "wp", ".", "Y", ")", "\n", "}" ]
// DrawCursor draws the cursor at the given position.
[ "DrawCursor", "draws", "the", "cursor", "at", "the", "given", "position", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/painter.go#L85-L88
6,521
marcusolsson/tui-go
painter.go
DrawRune
func (p *Painter) DrawRune(x, y int, r rune) { wp := p.mapLocalToWorld(image.Point{x, y}) if (p.mask.Min.X <= wp.X) && (wp.X < p.mask.Max.X) && (p.mask.Min.Y <= wp.Y) && (wp.Y < p.mask.Max.Y) { p.surface.SetCell(wp.X, wp.Y, r, p.style) } }
go
func (p *Painter) DrawRune(x, y int, r rune) { wp := p.mapLocalToWorld(image.Point{x, y}) if (p.mask.Min.X <= wp.X) && (wp.X < p.mask.Max.X) && (p.mask.Min.Y <= wp.Y) && (wp.Y < p.mask.Max.Y) { p.surface.SetCell(wp.X, wp.Y, r, p.style) } }
[ "func", "(", "p", "*", "Painter", ")", "DrawRune", "(", "x", ",", "y", "int", ",", "r", "rune", ")", "{", "wp", ":=", "p", ".", "mapLocalToWorld", "(", "image", ".", "Point", "{", "x", ",", "y", "}", ")", "\n", "if", "(", "p", ".", "mask", ".", "Min", ".", "X", "<=", "wp", ".", "X", ")", "&&", "(", "wp", ".", "X", "<", "p", ".", "mask", ".", "Max", ".", "X", ")", "&&", "(", "p", ".", "mask", ".", "Min", ".", "Y", "<=", "wp", ".", "Y", ")", "&&", "(", "wp", ".", "Y", "<", "p", ".", "mask", ".", "Max", ".", "Y", ")", "{", "p", ".", "surface", ".", "SetCell", "(", "wp", ".", "X", ",", "wp", ".", "Y", ",", "r", ",", "p", ".", "style", ")", "\n", "}", "\n", "}" ]
// DrawRune paints a rune at the given coordinate.
[ "DrawRune", "paints", "a", "rune", "at", "the", "given", "coordinate", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/painter.go#L91-L96
6,522
marcusolsson/tui-go
painter.go
DrawText
func (p *Painter) DrawText(x, y int, text string) { for _, r := range text { p.DrawRune(x, y, r) x += runeWidth(r) } }
go
func (p *Painter) DrawText(x, y int, text string) { for _, r := range text { p.DrawRune(x, y, r) x += runeWidth(r) } }
[ "func", "(", "p", "*", "Painter", ")", "DrawText", "(", "x", ",", "y", "int", ",", "text", "string", ")", "{", "for", "_", ",", "r", ":=", "range", "text", "{", "p", ".", "DrawRune", "(", "x", ",", "y", ",", "r", ")", "\n", "x", "+=", "runeWidth", "(", "r", ")", "\n", "}", "\n", "}" ]
// DrawText paints a string starting at the given coordinate.
[ "DrawText", "paints", "a", "string", "starting", "at", "the", "given", "coordinate", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/painter.go#L99-L104
6,523
marcusolsson/tui-go
painter.go
DrawHorizontalLine
func (p *Painter) DrawHorizontalLine(x1, x2, y int) { for x := x1; x < x2; x++ { p.DrawRune(x, y, '─') } }
go
func (p *Painter) DrawHorizontalLine(x1, x2, y int) { for x := x1; x < x2; x++ { p.DrawRune(x, y, '─') } }
[ "func", "(", "p", "*", "Painter", ")", "DrawHorizontalLine", "(", "x1", ",", "x2", ",", "y", "int", ")", "{", "for", "x", ":=", "x1", ";", "x", "<", "x2", ";", "x", "++", "{", "p", ".", "DrawRune", "(", "x", ",", "y", ",", "'─')", "", "\n", "}", "\n", "}" ]
// DrawHorizontalLine paints a horizontal line using box characters.
[ "DrawHorizontalLine", "paints", "a", "horizontal", "line", "using", "box", "characters", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/painter.go#L107-L111
6,524
marcusolsson/tui-go
painter.go
DrawVerticalLine
func (p *Painter) DrawVerticalLine(x, y1, y2 int) { for y := y1; y < y2; y++ { p.DrawRune(x, y, '│') } }
go
func (p *Painter) DrawVerticalLine(x, y1, y2 int) { for y := y1; y < y2; y++ { p.DrawRune(x, y, '│') } }
[ "func", "(", "p", "*", "Painter", ")", "DrawVerticalLine", "(", "x", ",", "y1", ",", "y2", "int", ")", "{", "for", "y", ":=", "y1", ";", "y", "<", "y2", ";", "y", "++", "{", "p", ".", "DrawRune", "(", "x", ",", "y", ",", "'│')", "", "\n", "}", "\n", "}" ]
// DrawVerticalLine paints a vertical line using box characters.
[ "DrawVerticalLine", "paints", "a", "vertical", "line", "using", "box", "characters", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/painter.go#L114-L118
6,525
marcusolsson/tui-go
painter.go
DrawRect
func (p *Painter) DrawRect(x, y, w, h int) { for j := 0; j < h; j++ { for i := 0; i < w; i++ { m := i + x n := j + y switch { case i == 0 && j == 0: p.DrawRune(m, n, '┌') case i == w-1 && j == 0: p.DrawRune(m, n, '┐') case i == 0 && j == h-1: p.DrawRune(m, n, '└') case i == w-1 && j == h-1: p.DrawRune(m, n, '┘') case i == 0 || i == w-1: p.DrawRune(m, n, '│') case j == 0 || j == h-1: p.DrawRune(m, n, '─') } } } }
go
func (p *Painter) DrawRect(x, y, w, h int) { for j := 0; j < h; j++ { for i := 0; i < w; i++ { m := i + x n := j + y switch { case i == 0 && j == 0: p.DrawRune(m, n, '┌') case i == w-1 && j == 0: p.DrawRune(m, n, '┐') case i == 0 && j == h-1: p.DrawRune(m, n, '└') case i == w-1 && j == h-1: p.DrawRune(m, n, '┘') case i == 0 || i == w-1: p.DrawRune(m, n, '│') case j == 0 || j == h-1: p.DrawRune(m, n, '─') } } } }
[ "func", "(", "p", "*", "Painter", ")", "DrawRect", "(", "x", ",", "y", ",", "w", ",", "h", "int", ")", "{", "for", "j", ":=", "0", ";", "j", "<", "h", ";", "j", "++", "{", "for", "i", ":=", "0", ";", "i", "<", "w", ";", "i", "++", "{", "m", ":=", "i", "+", "x", "\n", "n", ":=", "j", "+", "y", "\n\n", "switch", "{", "case", "i", "==", "0", "&&", "j", "==", "0", ":", "p", ".", "DrawRune", "(", "m", ",", "n", ",", "'┌')", "", "\n", "case", "i", "==", "w", "-", "1", "&&", "j", "==", "0", ":", "p", ".", "DrawRune", "(", "m", ",", "n", ",", "'┐')", "", "\n", "case", "i", "==", "0", "&&", "j", "==", "h", "-", "1", ":", "p", ".", "DrawRune", "(", "m", ",", "n", ",", "'└')", "", "\n", "case", "i", "==", "w", "-", "1", "&&", "j", "==", "h", "-", "1", ":", "p", ".", "DrawRune", "(", "m", ",", "n", ",", "'┘')", "", "\n", "case", "i", "==", "0", "||", "i", "==", "w", "-", "1", ":", "p", ".", "DrawRune", "(", "m", ",", "n", ",", "'│')", "", "\n", "case", "j", "==", "0", "||", "j", "==", "h", "-", "1", ":", "p", ".", "DrawRune", "(", "m", ",", "n", ",", "'─')", "", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// DrawRect paints a rectangle using box characters.
[ "DrawRect", "paints", "a", "rectangle", "using", "box", "characters", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/painter.go#L121-L143
6,526
marcusolsson/tui-go
painter.go
FillRect
func (p *Painter) FillRect(x, y, w, h int) { for j := 0; j < h; j++ { for i := 0; i < w; i++ { p.DrawRune(i+x, j+y, ' ') } } }
go
func (p *Painter) FillRect(x, y, w, h int) { for j := 0; j < h; j++ { for i := 0; i < w; i++ { p.DrawRune(i+x, j+y, ' ') } } }
[ "func", "(", "p", "*", "Painter", ")", "FillRect", "(", "x", ",", "y", ",", "w", ",", "h", "int", ")", "{", "for", "j", ":=", "0", ";", "j", "<", "h", ";", "j", "++", "{", "for", "i", ":=", "0", ";", "i", "<", "w", ";", "i", "++", "{", "p", ".", "DrawRune", "(", "i", "+", "x", ",", "j", "+", "y", ",", "' '", ")", "\n", "}", "\n", "}", "\n", "}" ]
// FillRect clears a rectangular area with whitespace.
[ "FillRect", "clears", "a", "rectangular", "area", "with", "whitespace", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/painter.go#L146-L152
6,527
marcusolsson/tui-go
painter.go
WithStyle
func (p *Painter) WithStyle(n string, fn func(*Painter)) { prev := p.style new := prev.mergeIn(p.theme.Style(n)) p.SetStyle(new) fn(p) p.SetStyle(prev) }
go
func (p *Painter) WithStyle(n string, fn func(*Painter)) { prev := p.style new := prev.mergeIn(p.theme.Style(n)) p.SetStyle(new) fn(p) p.SetStyle(prev) }
[ "func", "(", "p", "*", "Painter", ")", "WithStyle", "(", "n", "string", ",", "fn", "func", "(", "*", "Painter", ")", ")", "{", "prev", ":=", "p", ".", "style", "\n", "new", ":=", "prev", ".", "mergeIn", "(", "p", ".", "theme", ".", "Style", "(", "n", ")", ")", "\n", "p", ".", "SetStyle", "(", "new", ")", "\n", "fn", "(", "p", ")", "\n", "p", ".", "SetStyle", "(", "prev", ")", "\n", "}" ]
// WithStyle executes the provided function with the named Style applied on top of the current one.
[ "WithStyle", "executes", "the", "provided", "function", "with", "the", "named", "Style", "applied", "on", "top", "of", "the", "current", "one", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/painter.go#L160-L166
6,528
marcusolsson/tui-go
painter.go
WithMask
func (p *Painter) WithMask(r image.Rectangle, fn func(*Painter)) { tmp := p.mask defer func() { p.mask = tmp }() p.mask = p.mask.Intersect(image.Rectangle{ Min: p.mapLocalToWorld(r.Min), Max: p.mapLocalToWorld(r.Max), }) fn(p) }
go
func (p *Painter) WithMask(r image.Rectangle, fn func(*Painter)) { tmp := p.mask defer func() { p.mask = tmp }() p.mask = p.mask.Intersect(image.Rectangle{ Min: p.mapLocalToWorld(r.Min), Max: p.mapLocalToWorld(r.Max), }) fn(p) }
[ "func", "(", "p", "*", "Painter", ")", "WithMask", "(", "r", "image", ".", "Rectangle", ",", "fn", "func", "(", "*", "Painter", ")", ")", "{", "tmp", ":=", "p", ".", "mask", "\n", "defer", "func", "(", ")", "{", "p", ".", "mask", "=", "tmp", "}", "(", ")", "\n\n", "p", ".", "mask", "=", "p", ".", "mask", ".", "Intersect", "(", "image", ".", "Rectangle", "{", "Min", ":", "p", ".", "mapLocalToWorld", "(", "r", ".", "Min", ")", ",", "Max", ":", "p", ".", "mapLocalToWorld", "(", "r", ".", "Max", ")", ",", "}", ")", "\n\n", "fn", "(", "p", ")", "\n", "}" ]
// WithMask masks a painter to restrict painting within the given rectangle.
[ "WithMask", "masks", "a", "painter", "to", "restrict", "painting", "within", "the", "given", "rectangle", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/painter.go#L169-L179
6,529
marcusolsson/tui-go
runebuf.go
CursorPos
func (r *RuneBuffer) CursorPos() image.Point { if r.width == 0 { return image.ZP } sp := r.SplitByLine() var x, y int remaining := r.idx for _, l := range sp { if utf8.RuneCountInString(l) < remaining { y++ remaining -= utf8.RuneCountInString(l) + 1 } else { x = remaining break } } return image.Pt(stringWidth(string(r.buf[:x])), y) }
go
func (r *RuneBuffer) CursorPos() image.Point { if r.width == 0 { return image.ZP } sp := r.SplitByLine() var x, y int remaining := r.idx for _, l := range sp { if utf8.RuneCountInString(l) < remaining { y++ remaining -= utf8.RuneCountInString(l) + 1 } else { x = remaining break } } return image.Pt(stringWidth(string(r.buf[:x])), y) }
[ "func", "(", "r", "*", "RuneBuffer", ")", "CursorPos", "(", ")", "image", ".", "Point", "{", "if", "r", ".", "width", "==", "0", "{", "return", "image", ".", "ZP", "\n", "}", "\n\n", "sp", ":=", "r", ".", "SplitByLine", "(", ")", "\n", "var", "x", ",", "y", "int", "\n", "remaining", ":=", "r", ".", "idx", "\n", "for", "_", ",", "l", ":=", "range", "sp", "{", "if", "utf8", ".", "RuneCountInString", "(", "l", ")", "<", "remaining", "{", "y", "++", "\n", "remaining", "-=", "utf8", ".", "RuneCountInString", "(", "l", ")", "+", "1", "\n", "}", "else", "{", "x", "=", "remaining", "\n", "break", "\n", "}", "\n", "}", "\n", "return", "image", ".", "Pt", "(", "stringWidth", "(", "string", "(", "r", ".", "buf", "[", ":", "x", "]", ")", ")", ",", "y", ")", "\n", "}" ]
// CursorPos returns the coordinate for the cursor for a given width.
[ "CursorPos", "returns", "the", "coordinate", "for", "the", "cursor", "for", "a", "given", "width", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/runebuf.go#L81-L99
6,530
marcusolsson/tui-go
runebuf.go
MoveForward
func (r *RuneBuffer) MoveForward() { if r.idx == len(r.buf) { return } r.idx++ }
go
func (r *RuneBuffer) MoveForward() { if r.idx == len(r.buf) { return } r.idx++ }
[ "func", "(", "r", "*", "RuneBuffer", ")", "MoveForward", "(", ")", "{", "if", "r", ".", "idx", "==", "len", "(", "r", ".", "buf", ")", "{", "return", "\n", "}", "\n", "r", ".", "idx", "++", "\n", "}" ]
// MoveForward moves the cursor forward by one rune.
[ "MoveForward", "moves", "the", "cursor", "forward", "by", "one", "rune", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/runebuf.go#L119-L124
6,531
marcusolsson/tui-go
runebuf.go
MoveToLineStart
func (r *RuneBuffer) MoveToLineStart() { for i := r.idx; i > 0; i-- { if r.buf[i-1] == '\n' { r.idx = i return } } r.idx = 0 }
go
func (r *RuneBuffer) MoveToLineStart() { for i := r.idx; i > 0; i-- { if r.buf[i-1] == '\n' { r.idx = i return } } r.idx = 0 }
[ "func", "(", "r", "*", "RuneBuffer", ")", "MoveToLineStart", "(", ")", "{", "for", "i", ":=", "r", ".", "idx", ";", "i", ">", "0", ";", "i", "--", "{", "if", "r", ".", "buf", "[", "i", "-", "1", "]", "==", "'\\n'", "{", "r", ".", "idx", "=", "i", "\n", "return", "\n", "}", "\n", "}", "\n", "r", ".", "idx", "=", "0", "\n", "}" ]
// MoveToLineStart moves the cursor to the start of the current line.
[ "MoveToLineStart", "moves", "the", "cursor", "to", "the", "start", "of", "the", "current", "line", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/runebuf.go#L127-L135
6,532
marcusolsson/tui-go
runebuf.go
MoveToLineEnd
func (r *RuneBuffer) MoveToLineEnd() { for i := r.idx; i < len(r.buf)-1; i++ { if r.buf[i] == '\n' { r.idx = i return } } r.idx = len(r.buf) }
go
func (r *RuneBuffer) MoveToLineEnd() { for i := r.idx; i < len(r.buf)-1; i++ { if r.buf[i] == '\n' { r.idx = i return } } r.idx = len(r.buf) }
[ "func", "(", "r", "*", "RuneBuffer", ")", "MoveToLineEnd", "(", ")", "{", "for", "i", ":=", "r", ".", "idx", ";", "i", "<", "len", "(", "r", ".", "buf", ")", "-", "1", ";", "i", "++", "{", "if", "r", ".", "buf", "[", "i", "]", "==", "'\\n'", "{", "r", ".", "idx", "=", "i", "\n", "return", "\n", "}", "\n", "}", "\n", "r", ".", "idx", "=", "len", "(", "r", ".", "buf", ")", "\n", "}" ]
// MoveToLineEnd moves the cursor to the end of the current line.
[ "MoveToLineEnd", "moves", "the", "cursor", "to", "the", "end", "of", "the", "current", "line", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/runebuf.go#L138-L146
6,533
marcusolsson/tui-go
runebuf.go
Backspace
func (r *RuneBuffer) Backspace() { if r.idx == 0 { return } r.idx-- r.buf = append(r.buf[:r.idx], r.buf[r.idx+1:]...) }
go
func (r *RuneBuffer) Backspace() { if r.idx == 0 { return } r.idx-- r.buf = append(r.buf[:r.idx], r.buf[r.idx+1:]...) }
[ "func", "(", "r", "*", "RuneBuffer", ")", "Backspace", "(", ")", "{", "if", "r", ".", "idx", "==", "0", "{", "return", "\n", "}", "\n", "r", ".", "idx", "--", "\n", "r", ".", "buf", "=", "append", "(", "r", ".", "buf", "[", ":", "r", ".", "idx", "]", ",", "r", ".", "buf", "[", "r", ".", "idx", "+", "1", ":", "]", "...", ")", "\n", "}" ]
// Backspace deletes the rune left of the cursor.
[ "Backspace", "deletes", "the", "rune", "left", "of", "the", "cursor", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/runebuf.go#L149-L155
6,534
marcusolsson/tui-go
runebuf.go
Delete
func (r *RuneBuffer) Delete() { if r.idx == len(r.buf) { return } r.buf = append(r.buf[:r.idx], r.buf[r.idx+1:]...) }
go
func (r *RuneBuffer) Delete() { if r.idx == len(r.buf) { return } r.buf = append(r.buf[:r.idx], r.buf[r.idx+1:]...) }
[ "func", "(", "r", "*", "RuneBuffer", ")", "Delete", "(", ")", "{", "if", "r", ".", "idx", "==", "len", "(", "r", ".", "buf", ")", "{", "return", "\n", "}", "\n", "r", ".", "buf", "=", "append", "(", "r", ".", "buf", "[", ":", "r", ".", "idx", "]", ",", "r", ".", "buf", "[", "r", ".", "idx", "+", "1", ":", "]", "...", ")", "\n", "}" ]
// Delete deletes the rune at the current cursor position.
[ "Delete", "deletes", "the", "rune", "at", "the", "current", "cursor", "position", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/runebuf.go#L158-L163
6,535
marcusolsson/tui-go
runebuf.go
Kill
func (r *RuneBuffer) Kill() { newlineIdx := strings.IndexRune(string(r.buf[r.idx:]), '\n') if newlineIdx < 0 { r.buf = r.buf[:r.idx] } else { r.buf = append(r.buf[:r.idx], r.buf[r.idx+newlineIdx+1:]...) } }
go
func (r *RuneBuffer) Kill() { newlineIdx := strings.IndexRune(string(r.buf[r.idx:]), '\n') if newlineIdx < 0 { r.buf = r.buf[:r.idx] } else { r.buf = append(r.buf[:r.idx], r.buf[r.idx+newlineIdx+1:]...) } }
[ "func", "(", "r", "*", "RuneBuffer", ")", "Kill", "(", ")", "{", "newlineIdx", ":=", "strings", ".", "IndexRune", "(", "string", "(", "r", ".", "buf", "[", "r", ".", "idx", ":", "]", ")", ",", "'\\n'", ")", "\n", "if", "newlineIdx", "<", "0", "{", "r", ".", "buf", "=", "r", ".", "buf", "[", ":", "r", ".", "idx", "]", "\n", "}", "else", "{", "r", ".", "buf", "=", "append", "(", "r", ".", "buf", "[", ":", "r", ".", "idx", "]", ",", "r", ".", "buf", "[", "r", ".", "idx", "+", "newlineIdx", "+", "1", ":", "]", "...", ")", "\n", "}", "\n", "}" ]
// Kill deletes all runes from the cursor until the end of the line.
[ "Kill", "deletes", "all", "runes", "from", "the", "cursor", "until", "the", "end", "of", "the", "line", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/runebuf.go#L166-L173
6,536
marcusolsson/tui-go
wordwrap/wordwrap.go
WrapString
func WrapString(s string, width int) string { if len(s) <= 1 { return s } // Output buffer. Does not include the most recent word. var buf bytes.Buffer // Trailing word. var word bytes.Buffer var wordLen int spaceLeft := width var prev rune for _, curr := range s { if curr == rune('\n') { // Received a newline. if word.Len() > spaceLeft { spaceLeft = width buf.WriteRune(curr) } else { spaceLeft = width } word.WriteTo(&buf) wordLen = 0 } else if unicode.IsSpace(prev) && !unicode.IsSpace(curr) { // At the start of a new word. // Does the last word fit on this line, or the next? if wordLen > spaceLeft { spaceLeft = width - wordLen buf.WriteRune('\n') } else { spaceLeft -= wordLen } // fmt.Printf("42: writing %q with %d spaces remaining out of %d\n", word.String(), spaceLeft, width) word.WriteTo(&buf) wordLen = 0 } word.WriteRune(curr) wordLen += runewidth.RuneWidth(curr) prev = curr } // Close out the final word. if wordLen > spaceLeft { buf.WriteRune('\n') } word.WriteTo(&buf) return buf.String() }
go
func WrapString(s string, width int) string { if len(s) <= 1 { return s } // Output buffer. Does not include the most recent word. var buf bytes.Buffer // Trailing word. var word bytes.Buffer var wordLen int spaceLeft := width var prev rune for _, curr := range s { if curr == rune('\n') { // Received a newline. if word.Len() > spaceLeft { spaceLeft = width buf.WriteRune(curr) } else { spaceLeft = width } word.WriteTo(&buf) wordLen = 0 } else if unicode.IsSpace(prev) && !unicode.IsSpace(curr) { // At the start of a new word. // Does the last word fit on this line, or the next? if wordLen > spaceLeft { spaceLeft = width - wordLen buf.WriteRune('\n') } else { spaceLeft -= wordLen } // fmt.Printf("42: writing %q with %d spaces remaining out of %d\n", word.String(), spaceLeft, width) word.WriteTo(&buf) wordLen = 0 } word.WriteRune(curr) wordLen += runewidth.RuneWidth(curr) prev = curr } // Close out the final word. if wordLen > spaceLeft { buf.WriteRune('\n') } word.WriteTo(&buf) return buf.String() }
[ "func", "WrapString", "(", "s", "string", ",", "width", "int", ")", "string", "{", "if", "len", "(", "s", ")", "<=", "1", "{", "return", "s", "\n", "}", "\n\n", "// Output buffer. Does not include the most recent word.", "var", "buf", "bytes", ".", "Buffer", "\n", "// Trailing word.", "var", "word", "bytes", ".", "Buffer", "\n", "var", "wordLen", "int", "\n\n", "spaceLeft", ":=", "width", "\n", "var", "prev", "rune", "\n\n", "for", "_", ",", "curr", ":=", "range", "s", "{", "if", "curr", "==", "rune", "(", "'\\n'", ")", "{", "// Received a newline.", "if", "word", ".", "Len", "(", ")", ">", "spaceLeft", "{", "spaceLeft", "=", "width", "\n", "buf", ".", "WriteRune", "(", "curr", ")", "\n", "}", "else", "{", "spaceLeft", "=", "width", "\n", "}", "\n", "word", ".", "WriteTo", "(", "&", "buf", ")", "\n", "wordLen", "=", "0", "\n", "}", "else", "if", "unicode", ".", "IsSpace", "(", "prev", ")", "&&", "!", "unicode", ".", "IsSpace", "(", "curr", ")", "{", "// At the start of a new word.", "// Does the last word fit on this line, or the next?", "if", "wordLen", ">", "spaceLeft", "{", "spaceLeft", "=", "width", "-", "wordLen", "\n", "buf", ".", "WriteRune", "(", "'\\n'", ")", "\n", "}", "else", "{", "spaceLeft", "-=", "wordLen", "\n", "}", "\n", "// fmt.Printf(\"42: writing %q with %d spaces remaining out of %d\\n\", word.String(), spaceLeft, width)", "word", ".", "WriteTo", "(", "&", "buf", ")", "\n", "wordLen", "=", "0", "\n", "}", "\n", "word", ".", "WriteRune", "(", "curr", ")", "\n", "wordLen", "+=", "runewidth", ".", "RuneWidth", "(", "curr", ")", "\n\n", "prev", "=", "curr", "\n", "}", "\n\n", "// Close out the final word.", "if", "wordLen", ">", "spaceLeft", "{", "buf", ".", "WriteRune", "(", "'\\n'", ")", "\n", "}", "\n", "word", ".", "WriteTo", "(", "&", "buf", ")", "\n\n", "return", "buf", ".", "String", "(", ")", "\n", "}" ]
// WrapString wraps the input string by inserting newline characters. It does // not remove whitespace, but preserves the original text.
[ "WrapString", "wraps", "the", "input", "string", "by", "inserting", "newline", "characters", ".", "It", "does", "not", "remove", "whitespace", "but", "preserves", "the", "original", "text", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/wordwrap/wordwrap.go#L12-L63
6,537
marcusolsson/tui-go
scroll_area.go
Scroll
func (s *ScrollArea) Scroll(dx, dy int) { s.topLeft.X += dx s.topLeft.Y += dy }
go
func (s *ScrollArea) Scroll(dx, dy int) { s.topLeft.X += dx s.topLeft.Y += dy }
[ "func", "(", "s", "*", "ScrollArea", ")", "Scroll", "(", "dx", ",", "dy", "int", ")", "{", "s", ".", "topLeft", ".", "X", "+=", "dx", "\n", "s", ".", "topLeft", ".", "Y", "+=", "dy", "\n", "}" ]
// Scroll shifts the views over the content.
[ "Scroll", "shifts", "the", "views", "over", "the", "content", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/scroll_area.go#L37-L40
6,538
marcusolsson/tui-go
scroll_area.go
ScrollToBottom
func (s *ScrollArea) ScrollToBottom() { s.topLeft.Y = s.Widget.SizeHint().Y - s.Size().Y }
go
func (s *ScrollArea) ScrollToBottom() { s.topLeft.Y = s.Widget.SizeHint().Y - s.Size().Y }
[ "func", "(", "s", "*", "ScrollArea", ")", "ScrollToBottom", "(", ")", "{", "s", ".", "topLeft", ".", "Y", "=", "s", ".", "Widget", ".", "SizeHint", "(", ")", ".", "Y", "-", "s", ".", "Size", "(", ")", ".", "Y", "\n", "}" ]
// ScrollToBottom ensures the bottom-most part of the scroll area is visible.
[ "ScrollToBottom", "ensures", "the", "bottom", "-", "most", "part", "of", "the", "scroll", "area", "is", "visible", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/scroll_area.go#L43-L45
6,539
marcusolsson/tui-go
scroll_area.go
Draw
func (s *ScrollArea) Draw(p *Painter) { p.Translate(-s.topLeft.X, -s.topLeft.Y) defer p.Restore() off := image.Point{s.topLeft.X, s.topLeft.Y} p.WithMask(image.Rectangle{Min: off, Max: s.Size().Add(off)}, func(p *Painter) { s.Widget.Draw(p) }) }
go
func (s *ScrollArea) Draw(p *Painter) { p.Translate(-s.topLeft.X, -s.topLeft.Y) defer p.Restore() off := image.Point{s.topLeft.X, s.topLeft.Y} p.WithMask(image.Rectangle{Min: off, Max: s.Size().Add(off)}, func(p *Painter) { s.Widget.Draw(p) }) }
[ "func", "(", "s", "*", "ScrollArea", ")", "Draw", "(", "p", "*", "Painter", ")", "{", "p", ".", "Translate", "(", "-", "s", ".", "topLeft", ".", "X", ",", "-", "s", ".", "topLeft", ".", "Y", ")", "\n", "defer", "p", ".", "Restore", "(", ")", "\n\n", "off", ":=", "image", ".", "Point", "{", "s", ".", "topLeft", ".", "X", ",", "s", ".", "topLeft", ".", "Y", "}", "\n", "p", ".", "WithMask", "(", "image", ".", "Rectangle", "{", "Min", ":", "off", ",", "Max", ":", "s", ".", "Size", "(", ")", ".", "Add", "(", "off", ")", "}", ",", "func", "(", "p", "*", "Painter", ")", "{", "s", ".", "Widget", ".", "Draw", "(", "p", ")", "\n", "}", ")", "\n", "}" ]
// Draw draws the scroll area.
[ "Draw", "draws", "the", "scroll", "area", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/scroll_area.go#L58-L66
6,540
marcusolsson/tui-go
scroll_area.go
Resize
func (s *ScrollArea) Resize(size image.Point) { s.Widget.Resize(s.Widget.SizeHint()) s.WidgetBase.Resize(size) if s.autoscroll { s.ScrollToBottom() } }
go
func (s *ScrollArea) Resize(size image.Point) { s.Widget.Resize(s.Widget.SizeHint()) s.WidgetBase.Resize(size) if s.autoscroll { s.ScrollToBottom() } }
[ "func", "(", "s", "*", "ScrollArea", ")", "Resize", "(", "size", "image", ".", "Point", ")", "{", "s", ".", "Widget", ".", "Resize", "(", "s", ".", "Widget", ".", "SizeHint", "(", ")", ")", "\n", "s", ".", "WidgetBase", ".", "Resize", "(", "size", ")", "\n\n", "if", "s", ".", "autoscroll", "{", "s", ".", "ScrollToBottom", "(", ")", "\n", "}", "\n", "}" ]
// Resize resizes the scroll area and the underlying widget.
[ "Resize", "resizes", "the", "scroll", "area", "and", "the", "underlying", "widget", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/scroll_area.go#L69-L76
6,541
marcusolsson/tui-go
focus.go
FocusNext
func (c *SimpleFocusChain) FocusNext(current Widget) Widget { for i, w := range c.widgets { if w != current { continue } if i < len(c.widgets)-1 { return c.widgets[i+1] } return c.widgets[0] } return nil }
go
func (c *SimpleFocusChain) FocusNext(current Widget) Widget { for i, w := range c.widgets { if w != current { continue } if i < len(c.widgets)-1 { return c.widgets[i+1] } return c.widgets[0] } return nil }
[ "func", "(", "c", "*", "SimpleFocusChain", ")", "FocusNext", "(", "current", "Widget", ")", "Widget", "{", "for", "i", ",", "w", ":=", "range", "c", ".", "widgets", "{", "if", "w", "!=", "current", "{", "continue", "\n", "}", "\n", "if", "i", "<", "len", "(", "c", ".", "widgets", ")", "-", "1", "{", "return", "c", ".", "widgets", "[", "i", "+", "1", "]", "\n", "}", "\n", "return", "c", ".", "widgets", "[", "0", "]", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// FocusNext returns the widget in the ring that is after the given widget.
[ "FocusNext", "returns", "the", "widget", "in", "the", "ring", "that", "is", "after", "the", "given", "widget", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/focus.go#L54-L65
6,542
marcusolsson/tui-go
focus.go
FocusDefault
func (c *SimpleFocusChain) FocusDefault() Widget { if len(c.widgets) == 0 { return nil } return c.widgets[0] }
go
func (c *SimpleFocusChain) FocusDefault() Widget { if len(c.widgets) == 0 { return nil } return c.widgets[0] }
[ "func", "(", "c", "*", "SimpleFocusChain", ")", "FocusDefault", "(", ")", "Widget", "{", "if", "len", "(", "c", ".", "widgets", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "return", "c", ".", "widgets", "[", "0", "]", "\n", "}" ]
// FocusDefault returns the default widget for when there is no widget // currently focused.
[ "FocusDefault", "returns", "the", "default", "widget", "for", "when", "there", "is", "no", "widget", "currently", "focused", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/focus.go#L83-L88
6,543
marcusolsson/tui-go
label.go
Resize
func (l *Label) Resize(size image.Point) { if l.Size() != size { l.cacheSizeHint = nil } l.WidgetBase.Resize(size) }
go
func (l *Label) Resize(size image.Point) { if l.Size() != size { l.cacheSizeHint = nil } l.WidgetBase.Resize(size) }
[ "func", "(", "l", "*", "Label", ")", "Resize", "(", "size", "image", ".", "Point", ")", "{", "if", "l", ".", "Size", "(", ")", "!=", "size", "{", "l", ".", "cacheSizeHint", "=", "nil", "\n", "}", "\n", "l", ".", "WidgetBase", ".", "Resize", "(", "size", ")", "\n", "}" ]
// Resize changes the size of the Widget.
[ "Resize", "changes", "the", "size", "of", "the", "Widget", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/label.go#L33-L38
6,544
marcusolsson/tui-go
label.go
Draw
func (l *Label) Draw(p *Painter) { lines := l.lines() style := "label" if l.styleName != "" { style += "." + l.styleName } p.WithStyle(style, func(p *Painter) { for i, line := range lines { p.DrawText(0, i, line) } }) }
go
func (l *Label) Draw(p *Painter) { lines := l.lines() style := "label" if l.styleName != "" { style += "." + l.styleName } p.WithStyle(style, func(p *Painter) { for i, line := range lines { p.DrawText(0, i, line) } }) }
[ "func", "(", "l", "*", "Label", ")", "Draw", "(", "p", "*", "Painter", ")", "{", "lines", ":=", "l", ".", "lines", "(", ")", "\n\n", "style", ":=", "\"", "\"", "\n", "if", "l", ".", "styleName", "!=", "\"", "\"", "{", "style", "+=", "\"", "\"", "+", "l", ".", "styleName", "\n", "}", "\n\n", "p", ".", "WithStyle", "(", "style", ",", "func", "(", "p", "*", "Painter", ")", "{", "for", "i", ",", "line", ":=", "range", "lines", "{", "p", ".", "DrawText", "(", "0", ",", "i", ",", "line", ")", "\n", "}", "\n", "}", ")", "\n", "}" ]
// Draw draws the label.
[ "Draw", "draws", "the", "label", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/label.go#L41-L54
6,545
marcusolsson/tui-go
label.go
SizeHint
func (l *Label) SizeHint() image.Point { if l.cacheSizeHint != nil { return *l.cacheSizeHint } var max int lines := l.lines() for _, line := range lines { if w := stringWidth(line); w > max { max = w } } sizeHint := image.Point{max, len(lines)} l.cacheSizeHint = &sizeHint return sizeHint }
go
func (l *Label) SizeHint() image.Point { if l.cacheSizeHint != nil { return *l.cacheSizeHint } var max int lines := l.lines() for _, line := range lines { if w := stringWidth(line); w > max { max = w } } sizeHint := image.Point{max, len(lines)} l.cacheSizeHint = &sizeHint return sizeHint }
[ "func", "(", "l", "*", "Label", ")", "SizeHint", "(", ")", "image", ".", "Point", "{", "if", "l", ".", "cacheSizeHint", "!=", "nil", "{", "return", "*", "l", ".", "cacheSizeHint", "\n", "}", "\n", "var", "max", "int", "\n", "lines", ":=", "l", ".", "lines", "(", ")", "\n", "for", "_", ",", "line", ":=", "range", "lines", "{", "if", "w", ":=", "stringWidth", "(", "line", ")", ";", "w", ">", "max", "{", "max", "=", "w", "\n", "}", "\n", "}", "\n", "sizeHint", ":=", "image", ".", "Point", "{", "max", ",", "len", "(", "lines", ")", "}", "\n", "l", ".", "cacheSizeHint", "=", "&", "sizeHint", "\n", "return", "sizeHint", "\n", "}" ]
// SizeHint returns the recommended size for the label.
[ "SizeHint", "returns", "the", "recommended", "size", "for", "the", "label", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/label.go#L62-L76
6,546
marcusolsson/tui-go
label.go
SetText
func (l *Label) SetText(text string) { l.cacheSizeHint = nil l.text = text }
go
func (l *Label) SetText(text string) { l.cacheSizeHint = nil l.text = text }
[ "func", "(", "l", "*", "Label", ")", "SetText", "(", "text", "string", ")", "{", "l", ".", "cacheSizeHint", "=", "nil", "\n", "l", ".", "text", "=", "text", "\n", "}" ]
// SetText sets the text content of the label.
[ "SetText", "sets", "the", "text", "content", "of", "the", "label", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/label.go#L92-L95
6,547
marcusolsson/tui-go
box.go
Append
func (b *Box) Append(w Widget) { b.children = append(b.children, w) }
go
func (b *Box) Append(w Widget) { b.children = append(b.children, w) }
[ "func", "(", "b", "*", "Box", ")", "Append", "(", "w", "Widget", ")", "{", "b", ".", "children", "=", "append", "(", "b", ".", "children", ",", "w", ")", "\n", "}" ]
// Append adds the given widget at the end of the Box.
[ "Append", "adds", "the", "given", "widget", "at", "the", "end", "of", "the", "Box", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/box.go#L49-L51
6,548
marcusolsson/tui-go
box.go
Prepend
func (b *Box) Prepend(w Widget) { b.children = append([]Widget{w}, b.children...) }
go
func (b *Box) Prepend(w Widget) { b.children = append([]Widget{w}, b.children...) }
[ "func", "(", "b", "*", "Box", ")", "Prepend", "(", "w", "Widget", ")", "{", "b", ".", "children", "=", "append", "(", "[", "]", "Widget", "{", "w", "}", ",", "b", ".", "children", "...", ")", "\n", "}" ]
// Prepend adds the given widget at the start of the Box.
[ "Prepend", "adds", "the", "given", "widget", "at", "the", "start", "of", "the", "Box", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/box.go#L54-L56
6,549
marcusolsson/tui-go
box.go
Insert
func (b *Box) Insert(i int, w Widget) { if len(b.children) < i || i < 0 { return } b.children = append(b.children, nil) copy(b.children[i+1:], b.children[i:]) b.children[i] = w }
go
func (b *Box) Insert(i int, w Widget) { if len(b.children) < i || i < 0 { return } b.children = append(b.children, nil) copy(b.children[i+1:], b.children[i:]) b.children[i] = w }
[ "func", "(", "b", "*", "Box", ")", "Insert", "(", "i", "int", ",", "w", "Widget", ")", "{", "if", "len", "(", "b", ".", "children", ")", "<", "i", "||", "i", "<", "0", "{", "return", "\n", "}", "\n\n", "b", ".", "children", "=", "append", "(", "b", ".", "children", ",", "nil", ")", "\n", "copy", "(", "b", ".", "children", "[", "i", "+", "1", ":", "]", ",", "b", ".", "children", "[", "i", ":", "]", ")", "\n", "b", ".", "children", "[", "i", "]", "=", "w", "\n", "}" ]
// Insert adds the widget into the Box at a given index.
[ "Insert", "adds", "the", "widget", "into", "the", "Box", "at", "a", "given", "index", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/box.go#L59-L67
6,550
marcusolsson/tui-go
box.go
Remove
func (b *Box) Remove(i int) { if len(b.children) <= i || i < 0 { return } b.children = append(b.children[:i], b.children[i+1:]...) }
go
func (b *Box) Remove(i int) { if len(b.children) <= i || i < 0 { return } b.children = append(b.children[:i], b.children[i+1:]...) }
[ "func", "(", "b", "*", "Box", ")", "Remove", "(", "i", "int", ")", "{", "if", "len", "(", "b", ".", "children", ")", "<=", "i", "||", "i", "<", "0", "{", "return", "\n", "}", "\n\n", "b", ".", "children", "=", "append", "(", "b", ".", "children", "[", ":", "i", "]", ",", "b", ".", "children", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "}" ]
// Remove deletes the widget from the Box at a given index.
[ "Remove", "deletes", "the", "widget", "from", "the", "Box", "at", "a", "given", "index", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/box.go#L70-L76
6,551
marcusolsson/tui-go
box.go
IsFocused
func (b *Box) IsFocused() bool { for _, w := range b.children { if w.IsFocused() { return true } } return false }
go
func (b *Box) IsFocused() bool { for _, w := range b.children { if w.IsFocused() { return true } } return false }
[ "func", "(", "b", "*", "Box", ")", "IsFocused", "(", ")", "bool", "{", "for", "_", ",", "w", ":=", "range", "b", ".", "children", "{", "if", "w", ".", "IsFocused", "(", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// IsFocused return true if one of the children is focused.
[ "IsFocused", "return", "true", "if", "one", "of", "the", "children", "is", "focused", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/box.go#L99-L106
6,552
marcusolsson/tui-go
box.go
Draw
func (b *Box) Draw(p *Painter) { style := "box" if b.IsFocused() { style += ".focused" } p.WithStyle(style, func(p *Painter) { sz := b.Size() if b.border { p.WithStyle(style+".border", func(p *Painter) { p.DrawRect(0, 0, sz.X, sz.Y) }) p.WithStyle(style, func(p *Painter) { p.WithMask(image.Rect(0, 0, sz.X-1, 1), func(p *Painter) { p.DrawText(1, 0, b.title) }) }) p.FillRect(1, 1, sz.X-2, sz.Y-2) p.Translate(1, 1) defer p.Restore() } else { p.FillRect(0, 0, sz.X, sz.Y) } var off image.Point for _, child := range b.children { switch b.Alignment() { case Horizontal: p.Translate(off.X, 0) case Vertical: p.Translate(0, off.Y) } p.WithMask(image.Rectangle{ Min: image.ZP, Max: child.Size(), }, func(p *Painter) { child.Draw(p) }) p.Restore() off = off.Add(child.Size()) } }) }
go
func (b *Box) Draw(p *Painter) { style := "box" if b.IsFocused() { style += ".focused" } p.WithStyle(style, func(p *Painter) { sz := b.Size() if b.border { p.WithStyle(style+".border", func(p *Painter) { p.DrawRect(0, 0, sz.X, sz.Y) }) p.WithStyle(style, func(p *Painter) { p.WithMask(image.Rect(0, 0, sz.X-1, 1), func(p *Painter) { p.DrawText(1, 0, b.title) }) }) p.FillRect(1, 1, sz.X-2, sz.Y-2) p.Translate(1, 1) defer p.Restore() } else { p.FillRect(0, 0, sz.X, sz.Y) } var off image.Point for _, child := range b.children { switch b.Alignment() { case Horizontal: p.Translate(off.X, 0) case Vertical: p.Translate(0, off.Y) } p.WithMask(image.Rectangle{ Min: image.ZP, Max: child.Size(), }, func(p *Painter) { child.Draw(p) }) p.Restore() off = off.Add(child.Size()) } }) }
[ "func", "(", "b", "*", "Box", ")", "Draw", "(", "p", "*", "Painter", ")", "{", "style", ":=", "\"", "\"", "\n", "if", "b", ".", "IsFocused", "(", ")", "{", "style", "+=", "\"", "\"", "\n", "}", "\n\n", "p", ".", "WithStyle", "(", "style", ",", "func", "(", "p", "*", "Painter", ")", "{", "sz", ":=", "b", ".", "Size", "(", ")", "\n\n", "if", "b", ".", "border", "{", "p", ".", "WithStyle", "(", "style", "+", "\"", "\"", ",", "func", "(", "p", "*", "Painter", ")", "{", "p", ".", "DrawRect", "(", "0", ",", "0", ",", "sz", ".", "X", ",", "sz", ".", "Y", ")", "\n", "}", ")", "\n", "p", ".", "WithStyle", "(", "style", ",", "func", "(", "p", "*", "Painter", ")", "{", "p", ".", "WithMask", "(", "image", ".", "Rect", "(", "0", ",", "0", ",", "sz", ".", "X", "-", "1", ",", "1", ")", ",", "func", "(", "p", "*", "Painter", ")", "{", "p", ".", "DrawText", "(", "1", ",", "0", ",", "b", ".", "title", ")", "\n", "}", ")", "\n", "}", ")", "\n", "p", ".", "FillRect", "(", "1", ",", "1", ",", "sz", ".", "X", "-", "2", ",", "sz", ".", "Y", "-", "2", ")", "\n", "p", ".", "Translate", "(", "1", ",", "1", ")", "\n", "defer", "p", ".", "Restore", "(", ")", "\n", "}", "else", "{", "p", ".", "FillRect", "(", "0", ",", "0", ",", "sz", ".", "X", ",", "sz", ".", "Y", ")", "\n", "}", "\n\n", "var", "off", "image", ".", "Point", "\n", "for", "_", ",", "child", ":=", "range", "b", ".", "children", "{", "switch", "b", ".", "Alignment", "(", ")", "{", "case", "Horizontal", ":", "p", ".", "Translate", "(", "off", ".", "X", ",", "0", ")", "\n", "case", "Vertical", ":", "p", ".", "Translate", "(", "0", ",", "off", ".", "Y", ")", "\n", "}", "\n\n", "p", ".", "WithMask", "(", "image", ".", "Rectangle", "{", "Min", ":", "image", ".", "ZP", ",", "Max", ":", "child", ".", "Size", "(", ")", ",", "}", ",", "func", "(", "p", "*", "Painter", ")", "{", "child", ".", "Draw", "(", "p", ")", "\n", "}", ")", "\n\n", "p", ".", "Restore", "(", ")", "\n\n", "off", "=", "off", ".", "Add", "(", "child", ".", "Size", "(", ")", ")", "\n", "}", "\n", "}", ")", "\n", "}" ]
// Draw recursively draws the widgets it contains.
[ "Draw", "recursively", "draws", "the", "widgets", "it", "contains", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/box.go#L109-L156
6,553
marcusolsson/tui-go
box.go
MinSizeHint
func (b *Box) MinSizeHint() image.Point { var minSize image.Point for _, child := range b.children { size := child.MinSizeHint() if b.Alignment() == Horizontal { minSize.X += size.X if size.Y > minSize.Y { minSize.Y = size.Y } } else { minSize.Y += size.Y if size.X > minSize.X { minSize.X = size.X } } } if b.border { minSize = minSize.Add(image.Point{2, 2}) } return minSize }
go
func (b *Box) MinSizeHint() image.Point { var minSize image.Point for _, child := range b.children { size := child.MinSizeHint() if b.Alignment() == Horizontal { minSize.X += size.X if size.Y > minSize.Y { minSize.Y = size.Y } } else { minSize.Y += size.Y if size.X > minSize.X { minSize.X = size.X } } } if b.border { minSize = minSize.Add(image.Point{2, 2}) } return minSize }
[ "func", "(", "b", "*", "Box", ")", "MinSizeHint", "(", ")", "image", ".", "Point", "{", "var", "minSize", "image", ".", "Point", "\n\n", "for", "_", ",", "child", ":=", "range", "b", ".", "children", "{", "size", ":=", "child", ".", "MinSizeHint", "(", ")", "\n", "if", "b", ".", "Alignment", "(", ")", "==", "Horizontal", "{", "minSize", ".", "X", "+=", "size", ".", "X", "\n", "if", "size", ".", "Y", ">", "minSize", ".", "Y", "{", "minSize", ".", "Y", "=", "size", ".", "Y", "\n", "}", "\n", "}", "else", "{", "minSize", ".", "Y", "+=", "size", ".", "Y", "\n", "if", "size", ".", "X", ">", "minSize", ".", "X", "{", "minSize", ".", "X", "=", "size", ".", "X", "\n", "}", "\n", "}", "\n", "}", "\n\n", "if", "b", ".", "border", "{", "minSize", "=", "minSize", ".", "Add", "(", "image", ".", "Point", "{", "2", ",", "2", "}", ")", "\n", "}", "\n\n", "return", "minSize", "\n", "}" ]
// MinSizeHint returns the minimum size hint for the layout.
[ "MinSizeHint", "returns", "the", "minimum", "size", "hint", "for", "the", "layout", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/box.go#L159-L182
6,554
marcusolsson/tui-go
box.go
SizeHint
func (b *Box) SizeHint() image.Point { var sizeHint image.Point for _, child := range b.children { size := child.SizeHint() if b.Alignment() == Horizontal { sizeHint.X += size.X if size.Y > sizeHint.Y { sizeHint.Y = size.Y } } else { sizeHint.Y += size.Y if size.X > sizeHint.X { sizeHint.X = size.X } } } if b.border { sizeHint = sizeHint.Add(image.Point{2, 2}) } return sizeHint }
go
func (b *Box) SizeHint() image.Point { var sizeHint image.Point for _, child := range b.children { size := child.SizeHint() if b.Alignment() == Horizontal { sizeHint.X += size.X if size.Y > sizeHint.Y { sizeHint.Y = size.Y } } else { sizeHint.Y += size.Y if size.X > sizeHint.X { sizeHint.X = size.X } } } if b.border { sizeHint = sizeHint.Add(image.Point{2, 2}) } return sizeHint }
[ "func", "(", "b", "*", "Box", ")", "SizeHint", "(", ")", "image", ".", "Point", "{", "var", "sizeHint", "image", ".", "Point", "\n\n", "for", "_", ",", "child", ":=", "range", "b", ".", "children", "{", "size", ":=", "child", ".", "SizeHint", "(", ")", "\n", "if", "b", ".", "Alignment", "(", ")", "==", "Horizontal", "{", "sizeHint", ".", "X", "+=", "size", ".", "X", "\n", "if", "size", ".", "Y", ">", "sizeHint", ".", "Y", "{", "sizeHint", ".", "Y", "=", "size", ".", "Y", "\n", "}", "\n", "}", "else", "{", "sizeHint", ".", "Y", "+=", "size", ".", "Y", "\n", "if", "size", ".", "X", ">", "sizeHint", ".", "X", "{", "sizeHint", ".", "X", "=", "size", ".", "X", "\n", "}", "\n", "}", "\n", "}", "\n\n", "if", "b", ".", "border", "{", "sizeHint", "=", "sizeHint", ".", "Add", "(", "image", ".", "Point", "{", "2", ",", "2", "}", ")", "\n", "}", "\n\n", "return", "sizeHint", "\n", "}" ]
// SizeHint returns the recommended size hint for the layout.
[ "SizeHint", "returns", "the", "recommended", "size", "hint", "for", "the", "layout", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/box.go#L185-L208
6,555
marcusolsson/tui-go
box.go
Resize
func (b *Box) Resize(size image.Point) { b.size = size inner := b.size if b.border { inner = b.size.Sub(image.Point{2, 2}) } b.layoutChildren(inner) }
go
func (b *Box) Resize(size image.Point) { b.size = size inner := b.size if b.border { inner = b.size.Sub(image.Point{2, 2}) } b.layoutChildren(inner) }
[ "func", "(", "b", "*", "Box", ")", "Resize", "(", "size", "image", ".", "Point", ")", "{", "b", ".", "size", "=", "size", "\n", "inner", ":=", "b", ".", "size", "\n", "if", "b", ".", "border", "{", "inner", "=", "b", ".", "size", ".", "Sub", "(", "image", ".", "Point", "{", "2", ",", "2", "}", ")", "\n", "}", "\n", "b", ".", "layoutChildren", "(", "inner", ")", "\n", "}" ]
// Resize recursively updates the size of the Box and all the widgets it // contains. This is a potentially expensive operation and should be invoked // with restraint. // // Resize is called by the layout engine and is not intended to be used by end // users.
[ "Resize", "recursively", "updates", "the", "size", "of", "the", "Box", "and", "all", "the", "widgets", "it", "contains", ".", "This", "is", "a", "potentially", "expensive", "operation", "and", "should", "be", "invoked", "with", "restraint", ".", "Resize", "is", "called", "by", "the", "layout", "engine", "and", "is", "not", "intended", "to", "be", "used", "by", "end", "users", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/box.go#L223-L230
6,556
marcusolsson/tui-go
event.go
Name
func (ev *KeyEvent) Name() string { s := "" m := []string{} if ev.Modifiers&ModShift != 0 { m = append(m, "Shift") } if ev.Modifiers&ModAlt != 0 { m = append(m, "Alt") } if ev.Modifiers&ModMeta != 0 { m = append(m, "Meta") } if ev.Modifiers&ModCtrl != 0 { m = append(m, "Ctrl") } ok := false if s, ok = keyNames[ev.Key]; !ok { if ev.Key == KeyRune { s = string(ev.Rune) } else { s = "Unknown" } } if len(m) != 0 { if ev.Modifiers&ModCtrl != 0 && strings.HasPrefix(s, "Ctrl-") { s = s[5:] } return fmt.Sprintf("%s+%s", strings.Join(m, "+"), s) } return s }
go
func (ev *KeyEvent) Name() string { s := "" m := []string{} if ev.Modifiers&ModShift != 0 { m = append(m, "Shift") } if ev.Modifiers&ModAlt != 0 { m = append(m, "Alt") } if ev.Modifiers&ModMeta != 0 { m = append(m, "Meta") } if ev.Modifiers&ModCtrl != 0 { m = append(m, "Ctrl") } ok := false if s, ok = keyNames[ev.Key]; !ok { if ev.Key == KeyRune { s = string(ev.Rune) } else { s = "Unknown" } } if len(m) != 0 { if ev.Modifiers&ModCtrl != 0 && strings.HasPrefix(s, "Ctrl-") { s = s[5:] } return fmt.Sprintf("%s+%s", strings.Join(m, "+"), s) } return s }
[ "func", "(", "ev", "*", "KeyEvent", ")", "Name", "(", ")", "string", "{", "s", ":=", "\"", "\"", "\n", "m", ":=", "[", "]", "string", "{", "}", "\n", "if", "ev", ".", "Modifiers", "&", "ModShift", "!=", "0", "{", "m", "=", "append", "(", "m", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "ev", ".", "Modifiers", "&", "ModAlt", "!=", "0", "{", "m", "=", "append", "(", "m", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "ev", ".", "Modifiers", "&", "ModMeta", "!=", "0", "{", "m", "=", "append", "(", "m", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "ev", ".", "Modifiers", "&", "ModCtrl", "!=", "0", "{", "m", "=", "append", "(", "m", ",", "\"", "\"", ")", "\n", "}", "\n\n", "ok", ":=", "false", "\n", "if", "s", ",", "ok", "=", "keyNames", "[", "ev", ".", "Key", "]", ";", "!", "ok", "{", "if", "ev", ".", "Key", "==", "KeyRune", "{", "s", "=", "string", "(", "ev", ".", "Rune", ")", "\n", "}", "else", "{", "s", "=", "\"", "\"", "\n", "}", "\n", "}", "\n", "if", "len", "(", "m", ")", "!=", "0", "{", "if", "ev", ".", "Modifiers", "&", "ModCtrl", "!=", "0", "&&", "strings", ".", "HasPrefix", "(", "s", ",", "\"", "\"", ")", "{", "s", "=", "s", "[", "5", ":", "]", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "strings", ".", "Join", "(", "m", ",", "\"", "\"", ")", ",", "s", ")", "\n", "}", "\n", "return", "s", "\n", "}" ]
// Name returns a user-friendly description of the key press.
[ "Name", "returns", "a", "user", "-", "friendly", "description", "of", "the", "key", "press", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/event.go#L29-L60
6,557
marcusolsson/tui-go
grid.go
NewGrid
func NewGrid(cols, rows int) *Grid { return &Grid{ cols: cols, rows: rows, cells: make(map[image.Point]Widget), columnStretch: make(map[int]int), rowStretch: make(map[int]int), } }
go
func NewGrid(cols, rows int) *Grid { return &Grid{ cols: cols, rows: rows, cells: make(map[image.Point]Widget), columnStretch: make(map[int]int), rowStretch: make(map[int]int), } }
[ "func", "NewGrid", "(", "cols", ",", "rows", "int", ")", "*", "Grid", "{", "return", "&", "Grid", "{", "cols", ":", "cols", ",", "rows", ":", "rows", ",", "cells", ":", "make", "(", "map", "[", "image", ".", "Point", "]", "Widget", ")", ",", "columnStretch", ":", "make", "(", "map", "[", "int", "]", "int", ")", ",", "rowStretch", ":", "make", "(", "map", "[", "int", "]", "int", ")", ",", "}", "\n", "}" ]
// NewGrid returns a new Grid.
[ "NewGrid", "returns", "a", "new", "Grid", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/grid.go#L27-L35
6,558
marcusolsson/tui-go
grid.go
Draw
func (g *Grid) Draw(p *Painter) { s := g.Size() if g.hasBorder { border := 1 // Draw outmost border. p.DrawRect(0, 0, s.X, s.Y) // Draw column dividers. var coloff int for i := 0; i < g.cols-1; i++ { x := g.colWidths[i] + coloff + border p.DrawVerticalLine(x, 0, s.Y-1) p.DrawRune(x, 0, '┬') p.DrawRune(x, s.Y-1, '┴') coloff = x } // Draw row dividers. var rowoff int for j := 0; j < g.rows-1; j++ { y := g.rowHeights[j] + rowoff + border p.DrawHorizontalLine(0, s.X-1, y) p.DrawRune(0, y, '├') p.DrawRune(s.X-1, y, '┤') rowoff = y } // Polish the intersections. rowoff = 0 for j := 0; j < g.rows-1; j++ { y := g.rowHeights[j] + rowoff + border coloff = 0 for i := 0; i < g.cols-1; i++ { x := g.colWidths[i] + coloff + border p.DrawRune(x, y, '┼') coloff = x } rowoff = y } } // Draw cell content. for i := 0; i < g.cols; i++ { for j := 0; j < g.rows; j++ { pos := image.Point{i, j} wp := g.mapCellToLocal(pos) if w, ok := g.cells[pos]; ok { p.Translate(wp.X, wp.Y) p.WithMask(image.Rectangle{ Min: image.ZP, Max: w.Size(), }, func(p *Painter) { w.Draw(p) }) p.Restore() } } } }
go
func (g *Grid) Draw(p *Painter) { s := g.Size() if g.hasBorder { border := 1 // Draw outmost border. p.DrawRect(0, 0, s.X, s.Y) // Draw column dividers. var coloff int for i := 0; i < g.cols-1; i++ { x := g.colWidths[i] + coloff + border p.DrawVerticalLine(x, 0, s.Y-1) p.DrawRune(x, 0, '┬') p.DrawRune(x, s.Y-1, '┴') coloff = x } // Draw row dividers. var rowoff int for j := 0; j < g.rows-1; j++ { y := g.rowHeights[j] + rowoff + border p.DrawHorizontalLine(0, s.X-1, y) p.DrawRune(0, y, '├') p.DrawRune(s.X-1, y, '┤') rowoff = y } // Polish the intersections. rowoff = 0 for j := 0; j < g.rows-1; j++ { y := g.rowHeights[j] + rowoff + border coloff = 0 for i := 0; i < g.cols-1; i++ { x := g.colWidths[i] + coloff + border p.DrawRune(x, y, '┼') coloff = x } rowoff = y } } // Draw cell content. for i := 0; i < g.cols; i++ { for j := 0; j < g.rows; j++ { pos := image.Point{i, j} wp := g.mapCellToLocal(pos) if w, ok := g.cells[pos]; ok { p.Translate(wp.X, wp.Y) p.WithMask(image.Rectangle{ Min: image.ZP, Max: w.Size(), }, func(p *Painter) { w.Draw(p) }) p.Restore() } } } }
[ "func", "(", "g", "*", "Grid", ")", "Draw", "(", "p", "*", "Painter", ")", "{", "s", ":=", "g", ".", "Size", "(", ")", "\n\n", "if", "g", ".", "hasBorder", "{", "border", ":=", "1", "\n\n", "// Draw outmost border.", "p", ".", "DrawRect", "(", "0", ",", "0", ",", "s", ".", "X", ",", "s", ".", "Y", ")", "\n\n", "// Draw column dividers.", "var", "coloff", "int", "\n", "for", "i", ":=", "0", ";", "i", "<", "g", ".", "cols", "-", "1", ";", "i", "++", "{", "x", ":=", "g", ".", "colWidths", "[", "i", "]", "+", "coloff", "+", "border", "\n", "p", ".", "DrawVerticalLine", "(", "x", ",", "0", ",", "s", ".", "Y", "-", "1", ")", "\n", "p", ".", "DrawRune", "(", "x", ",", "0", ",", "'┬')", "", "\n", "p", ".", "DrawRune", "(", "x", ",", "s", ".", "Y", "-", "1", ",", "'┴')", "", "\n", "coloff", "=", "x", "\n", "}", "\n\n", "// Draw row dividers.", "var", "rowoff", "int", "\n", "for", "j", ":=", "0", ";", "j", "<", "g", ".", "rows", "-", "1", ";", "j", "++", "{", "y", ":=", "g", ".", "rowHeights", "[", "j", "]", "+", "rowoff", "+", "border", "\n", "p", ".", "DrawHorizontalLine", "(", "0", ",", "s", ".", "X", "-", "1", ",", "y", ")", "\n", "p", ".", "DrawRune", "(", "0", ",", "y", ",", "'├')", "", "\n", "p", ".", "DrawRune", "(", "s", ".", "X", "-", "1", ",", "y", ",", "'┤')", "", "\n", "rowoff", "=", "y", "\n", "}", "\n\n", "// Polish the intersections.", "rowoff", "=", "0", "\n", "for", "j", ":=", "0", ";", "j", "<", "g", ".", "rows", "-", "1", ";", "j", "++", "{", "y", ":=", "g", ".", "rowHeights", "[", "j", "]", "+", "rowoff", "+", "border", "\n", "coloff", "=", "0", "\n", "for", "i", ":=", "0", ";", "i", "<", "g", ".", "cols", "-", "1", ";", "i", "++", "{", "x", ":=", "g", ".", "colWidths", "[", "i", "]", "+", "coloff", "+", "border", "\n", "p", ".", "DrawRune", "(", "x", ",", "y", ",", "'┼')", "", "\n", "coloff", "=", "x", "\n", "}", "\n", "rowoff", "=", "y", "\n", "}", "\n", "}", "\n\n", "// Draw cell content.", "for", "i", ":=", "0", ";", "i", "<", "g", ".", "cols", ";", "i", "++", "{", "for", "j", ":=", "0", ";", "j", "<", "g", ".", "rows", ";", "j", "++", "{", "pos", ":=", "image", ".", "Point", "{", "i", ",", "j", "}", "\n", "wp", ":=", "g", ".", "mapCellToLocal", "(", "pos", ")", "\n\n", "if", "w", ",", "ok", ":=", "g", ".", "cells", "[", "pos", "]", ";", "ok", "{", "p", ".", "Translate", "(", "wp", ".", "X", ",", "wp", ".", "Y", ")", "\n", "p", ".", "WithMask", "(", "image", ".", "Rectangle", "{", "Min", ":", "image", ".", "ZP", ",", "Max", ":", "w", ".", "Size", "(", ")", ",", "}", ",", "func", "(", "p", "*", "Painter", ")", "{", "w", ".", "Draw", "(", "p", ")", "\n", "}", ")", "\n", "p", ".", "Restore", "(", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// Draw draws the grid.
[ "Draw", "draws", "the", "grid", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/grid.go#L38-L99
6,559
marcusolsson/tui-go
grid.go
MinSizeHint
func (g *Grid) MinSizeHint() image.Point { if g.cols == 0 || g.rows == 0 { return image.Point{} } var width int for i := 0; i < g.cols; i++ { width += g.minColumnWidth(i) } var height int for j := 0; j < g.rows; j++ { height += g.minRowHeight(j) } if g.hasBorder { width += g.cols + 1 height += g.rows + 1 } return image.Point{width, height} }
go
func (g *Grid) MinSizeHint() image.Point { if g.cols == 0 || g.rows == 0 { return image.Point{} } var width int for i := 0; i < g.cols; i++ { width += g.minColumnWidth(i) } var height int for j := 0; j < g.rows; j++ { height += g.minRowHeight(j) } if g.hasBorder { width += g.cols + 1 height += g.rows + 1 } return image.Point{width, height} }
[ "func", "(", "g", "*", "Grid", ")", "MinSizeHint", "(", ")", "image", ".", "Point", "{", "if", "g", ".", "cols", "==", "0", "||", "g", ".", "rows", "==", "0", "{", "return", "image", ".", "Point", "{", "}", "\n", "}", "\n\n", "var", "width", "int", "\n", "for", "i", ":=", "0", ";", "i", "<", "g", ".", "cols", ";", "i", "++", "{", "width", "+=", "g", ".", "minColumnWidth", "(", "i", ")", "\n", "}", "\n\n", "var", "height", "int", "\n", "for", "j", ":=", "0", ";", "j", "<", "g", ".", "rows", ";", "j", "++", "{", "height", "+=", "g", ".", "minRowHeight", "(", "j", ")", "\n", "}", "\n\n", "if", "g", ".", "hasBorder", "{", "width", "+=", "g", ".", "cols", "+", "1", "\n", "height", "+=", "g", ".", "rows", "+", "1", "\n", "}", "\n\n", "return", "image", ".", "Point", "{", "width", ",", "height", "}", "\n", "}" ]
// MinSizeHint returns the minimum size hint for the grid.
[ "MinSizeHint", "returns", "the", "minimum", "size", "hint", "for", "the", "grid", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/grid.go#L102-L123
6,560
marcusolsson/tui-go
grid.go
SizeHint
func (g *Grid) SizeHint() image.Point { if g.cols == 0 || g.rows == 0 { return image.Point{} } var maxWidth int for i := 0; i < g.cols; i++ { if w := g.columnWidth(i); w > maxWidth { maxWidth = w } } var maxHeight int for j := 0; j < g.rows; j++ { if h := g.rowHeight(j); h > maxHeight { maxHeight = h } } width := maxWidth * g.cols height := maxHeight * g.rows if g.hasBorder { width += g.cols + 1 height += g.rows + 1 } return image.Point{width, height} }
go
func (g *Grid) SizeHint() image.Point { if g.cols == 0 || g.rows == 0 { return image.Point{} } var maxWidth int for i := 0; i < g.cols; i++ { if w := g.columnWidth(i); w > maxWidth { maxWidth = w } } var maxHeight int for j := 0; j < g.rows; j++ { if h := g.rowHeight(j); h > maxHeight { maxHeight = h } } width := maxWidth * g.cols height := maxHeight * g.rows if g.hasBorder { width += g.cols + 1 height += g.rows + 1 } return image.Point{width, height} }
[ "func", "(", "g", "*", "Grid", ")", "SizeHint", "(", ")", "image", ".", "Point", "{", "if", "g", ".", "cols", "==", "0", "||", "g", ".", "rows", "==", "0", "{", "return", "image", ".", "Point", "{", "}", "\n", "}", "\n\n", "var", "maxWidth", "int", "\n", "for", "i", ":=", "0", ";", "i", "<", "g", ".", "cols", ";", "i", "++", "{", "if", "w", ":=", "g", ".", "columnWidth", "(", "i", ")", ";", "w", ">", "maxWidth", "{", "maxWidth", "=", "w", "\n", "}", "\n", "}", "\n\n", "var", "maxHeight", "int", "\n", "for", "j", ":=", "0", ";", "j", "<", "g", ".", "rows", ";", "j", "++", "{", "if", "h", ":=", "g", ".", "rowHeight", "(", "j", ")", ";", "h", ">", "maxHeight", "{", "maxHeight", "=", "h", "\n", "}", "\n", "}", "\n\n", "width", ":=", "maxWidth", "*", "g", ".", "cols", "\n", "height", ":=", "maxHeight", "*", "g", ".", "rows", "\n\n", "if", "g", ".", "hasBorder", "{", "width", "+=", "g", ".", "cols", "+", "1", "\n", "height", "+=", "g", ".", "rows", "+", "1", "\n", "}", "\n\n", "return", "image", ".", "Point", "{", "width", ",", "height", "}", "\n", "}" ]
// SizeHint returns the recommended size hint for the grid.
[ "SizeHint", "returns", "the", "recommended", "size", "hint", "for", "the", "grid", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/grid.go#L126-L154
6,561
marcusolsson/tui-go
grid.go
Resize
func (g *Grid) Resize(size image.Point) { g.size = size inner := g.size if g.hasBorder { inner.X = g.size.X - (g.cols + 1) inner.Y = g.size.Y - (g.rows + 1) } g.layoutChildren(inner) }
go
func (g *Grid) Resize(size image.Point) { g.size = size inner := g.size if g.hasBorder { inner.X = g.size.X - (g.cols + 1) inner.Y = g.size.Y - (g.rows + 1) } g.layoutChildren(inner) }
[ "func", "(", "g", "*", "Grid", ")", "Resize", "(", "size", "image", ".", "Point", ")", "{", "g", ".", "size", "=", "size", "\n", "inner", ":=", "g", ".", "size", "\n", "if", "g", ".", "hasBorder", "{", "inner", ".", "X", "=", "g", ".", "size", ".", "X", "-", "(", "g", ".", "cols", "+", "1", ")", "\n", "inner", ".", "Y", "=", "g", ".", "size", ".", "Y", "-", "(", "g", ".", "rows", "+", "1", ")", "\n", "}", "\n", "g", ".", "layoutChildren", "(", "inner", ")", "\n", "}" ]
// Resize recursively updates the size of the Grid and all the widgets it // contains. This is a potentially expensive operation and should be invoked // with restraint. // // Resize is called by the layout engine and is not intended to be used by end // users.
[ "Resize", "recursively", "updates", "the", "size", "of", "the", "Grid", "and", "all", "the", "widgets", "it", "contains", ".", "This", "is", "a", "potentially", "expensive", "operation", "and", "should", "be", "invoked", "with", "restraint", ".", "Resize", "is", "called", "by", "the", "layout", "engine", "and", "is", "not", "intended", "to", "be", "used", "by", "end", "users", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/grid.go#L162-L170
6,562
marcusolsson/tui-go
grid.go
SetCell
func (g *Grid) SetCell(pos image.Point, w Widget) { g.cells[pos] = w }
go
func (g *Grid) SetCell(pos image.Point, w Widget) { g.cells[pos] = w }
[ "func", "(", "g", "*", "Grid", ")", "SetCell", "(", "pos", "image", ".", "Point", ",", "w", "Widget", ")", "{", "g", ".", "cells", "[", "pos", "]", "=", "w", "\n", "}" ]
// SetCell sets or replaces the contents of a cell.
[ "SetCell", "sets", "or", "replaces", "the", "contents", "of", "a", "cell", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/grid.go#L403-L405
6,563
marcusolsson/tui-go
grid.go
AppendRow
func (g *Grid) AppendRow(row ...Widget) { g.rows++ if len(row) > g.cols { g.cols = len(row) } for i, cell := range row { pos := image.Point{i, g.rows - 1} g.SetCell(pos, cell) } }
go
func (g *Grid) AppendRow(row ...Widget) { g.rows++ if len(row) > g.cols { g.cols = len(row) } for i, cell := range row { pos := image.Point{i, g.rows - 1} g.SetCell(pos, cell) } }
[ "func", "(", "g", "*", "Grid", ")", "AppendRow", "(", "row", "...", "Widget", ")", "{", "g", ".", "rows", "++", "\n\n", "if", "len", "(", "row", ")", ">", "g", ".", "cols", "{", "g", ".", "cols", "=", "len", "(", "row", ")", "\n", "}", "\n\n", "for", "i", ",", "cell", ":=", "range", "row", "{", "pos", ":=", "image", ".", "Point", "{", "i", ",", "g", ".", "rows", "-", "1", "}", "\n", "g", ".", "SetCell", "(", "pos", ",", "cell", ")", "\n", "}", "\n", "}" ]
// AppendRow adds a new row at the end.
[ "AppendRow", "adds", "a", "new", "row", "at", "the", "end", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/grid.go#L413-L424
6,564
marcusolsson/tui-go
grid.go
RemoveRows
func (g *Grid) RemoveRows() { g.rows = 0 g.cells = make(map[image.Point]Widget) }
go
func (g *Grid) RemoveRows() { g.rows = 0 g.cells = make(map[image.Point]Widget) }
[ "func", "(", "g", "*", "Grid", ")", "RemoveRows", "(", ")", "{", "g", ".", "rows", "=", "0", "\n", "g", ".", "cells", "=", "make", "(", "map", "[", "image", ".", "Point", "]", "Widget", ")", "\n", "}" ]
// RemoveRows will remove all the rows in grid
[ "RemoveRows", "will", "remove", "all", "the", "rows", "in", "grid" ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/grid.go#L443-L446
6,565
marcusolsson/tui-go
grid.go
SetRowStretch
func (g *Grid) SetRowStretch(row, stretch int) { g.rowStretch[row] = stretch }
go
func (g *Grid) SetRowStretch(row, stretch int) { g.rowStretch[row] = stretch }
[ "func", "(", "g", "*", "Grid", ")", "SetRowStretch", "(", "row", ",", "stretch", "int", ")", "{", "g", ".", "rowStretch", "[", "row", "]", "=", "stretch", "\n", "}" ]
// SetRowStretch sets the stretch factor for a given row. For more on stretch // factors, see SetColumnStretch.
[ "SetRowStretch", "sets", "the", "stretch", "factor", "for", "a", "given", "row", ".", "For", "more", "on", "stretch", "factors", "see", "SetColumnStretch", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/grid.go#L460-L462
6,566
marcusolsson/tui-go
ui_tcell.go
Quit
func (ui *tcellUI) Quit() { logger.Printf("Quitting") ui.screen.Fini() ui.quit <- struct{}{} }
go
func (ui *tcellUI) Quit() { logger.Printf("Quitting") ui.screen.Fini() ui.quit <- struct{}{} }
[ "func", "(", "ui", "*", "tcellUI", ")", "Quit", "(", ")", "{", "logger", ".", "Printf", "(", "\"", "\"", ")", "\n", "ui", ".", "screen", ".", "Fini", "(", ")", "\n", "ui", ".", "quit", "<-", "struct", "{", "}", "{", "}", "\n", "}" ]
// Quit signals to the UI to start shutting down.
[ "Quit", "signals", "to", "the", "UI", "to", "start", "shutting", "down", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/ui_tcell.go#L172-L176
6,567
marcusolsson/tui-go
text.go
trimRightLen
func trimRightLen(s string, n int) string { if n <= 0 { return s } c := utf8.RuneCountInString(s) runeCount := 0 var i int for i = range s { if runeCount >= c-n { break } runeCount++ } return s[:i] }
go
func trimRightLen(s string, n int) string { if n <= 0 { return s } c := utf8.RuneCountInString(s) runeCount := 0 var i int for i = range s { if runeCount >= c-n { break } runeCount++ } return s[:i] }
[ "func", "trimRightLen", "(", "s", "string", ",", "n", "int", ")", "string", "{", "if", "n", "<=", "0", "{", "return", "s", "\n", "}", "\n", "c", ":=", "utf8", ".", "RuneCountInString", "(", "s", ")", "\n", "runeCount", ":=", "0", "\n", "var", "i", "int", "\n", "for", "i", "=", "range", "s", "{", "if", "runeCount", ">=", "c", "-", "n", "{", "break", "\n", "}", "\n", "runeCount", "++", "\n", "}", "\n", "return", "s", "[", ":", "i", "]", "\n", "}" ]
// trimRightLen returns s with n runes trimmed off
[ "trimRightLen", "returns", "s", "with", "n", "runes", "trimmed", "off" ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/text.go#L20-L34
6,568
marcusolsson/tui-go
statusbar.go
Draw
func (b *StatusBar) Draw(p *Painter) { p.WithStyle("statusbar", func(p *Painter) { p.FillRect(0, 0, b.Size().X, 1) p.DrawText(0, 0, b.text) p.DrawText(b.Size().X-stringWidth(b.permText), 0, b.permText) }) }
go
func (b *StatusBar) Draw(p *Painter) { p.WithStyle("statusbar", func(p *Painter) { p.FillRect(0, 0, b.Size().X, 1) p.DrawText(0, 0, b.text) p.DrawText(b.Size().X-stringWidth(b.permText), 0, b.permText) }) }
[ "func", "(", "b", "*", "StatusBar", ")", "Draw", "(", "p", "*", "Painter", ")", "{", "p", ".", "WithStyle", "(", "\"", "\"", ",", "func", "(", "p", "*", "Painter", ")", "{", "p", ".", "FillRect", "(", "0", ",", "0", ",", "b", ".", "Size", "(", ")", ".", "X", ",", "1", ")", "\n", "p", ".", "DrawText", "(", "0", ",", "0", ",", "b", ".", "text", ")", "\n", "p", ".", "DrawText", "(", "b", ".", "Size", "(", ")", ".", "X", "-", "stringWidth", "(", "b", ".", "permText", ")", ",", "0", ",", "b", ".", "permText", ")", "\n", "}", ")", "\n", "}" ]
// Draw draws the status bar.
[ "Draw", "draws", "the", "status", "bar", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/statusbar.go#L26-L32
6,569
marcusolsson/tui-go
example/color/main.go
Draw
func (s *StyledBox) Draw(p *tui.Painter) { p.WithStyle(s.Style, func(p *tui.Painter) { s.Box.Draw(p) }) }
go
func (s *StyledBox) Draw(p *tui.Painter) { p.WithStyle(s.Style, func(p *tui.Painter) { s.Box.Draw(p) }) }
[ "func", "(", "s", "*", "StyledBox", ")", "Draw", "(", "p", "*", "tui", ".", "Painter", ")", "{", "p", ".", "WithStyle", "(", "s", ".", "Style", ",", "func", "(", "p", "*", "tui", ".", "Painter", ")", "{", "s", ".", "Box", ".", "Draw", "(", "p", ")", "\n", "}", ")", "\n", "}" ]
// Draw decorates the Draw call to the widget with a style.
[ "Draw", "decorates", "the", "Draw", "call", "to", "the", "widget", "with", "a", "style", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/example/color/main.go#L17-L21
6,570
marcusolsson/tui-go
text_edit.go
SizeHint
func (e *TextEdit) SizeHint() image.Point { var max int lines := strings.Split(e.text.String(), "\n") for _, line := range lines { if w := stringWidth(line); w > max { max = w } } return image.Point{max, e.text.heightForWidth(max)} }
go
func (e *TextEdit) SizeHint() image.Point { var max int lines := strings.Split(e.text.String(), "\n") for _, line := range lines { if w := stringWidth(line); w > max { max = w } } return image.Point{max, e.text.heightForWidth(max)} }
[ "func", "(", "e", "*", "TextEdit", ")", "SizeHint", "(", ")", "image", ".", "Point", "{", "var", "max", "int", "\n", "lines", ":=", "strings", ".", "Split", "(", "e", ".", "text", ".", "String", "(", ")", ",", "\"", "\\n", "\"", ")", "\n", "for", "_", ",", "line", ":=", "range", "lines", "{", "if", "w", ":=", "stringWidth", "(", "line", ")", ";", "w", ">", "max", "{", "max", "=", "w", "\n", "}", "\n", "}", "\n", "return", "image", ".", "Point", "{", "max", ",", "e", ".", "text", ".", "heightForWidth", "(", "max", ")", "}", "\n", "}" ]
// SizeHint returns the recommended size for the entry.
[ "SizeHint", "returns", "the", "recommended", "size", "for", "the", "entry", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/text_edit.go#L48-L57
6,571
marcusolsson/tui-go
padder.go
NewPadder
func NewPadder(x, y int, w Widget) *Padder { return &Padder{ widget: w, padding: image.Point{x, y}, } }
go
func NewPadder(x, y int, w Widget) *Padder { return &Padder{ widget: w, padding: image.Point{x, y}, } }
[ "func", "NewPadder", "(", "x", ",", "y", "int", ",", "w", "Widget", ")", "*", "Padder", "{", "return", "&", "Padder", "{", "widget", ":", "w", ",", "padding", ":", "image", ".", "Point", "{", "x", ",", "y", "}", ",", "}", "\n", "}" ]
// NewPadder returns a new Padder. // The enclosed Widget is given horizontal margin of x on the right and x on the left, // and a vertical margin of y on the top and y on the bottom.
[ "NewPadder", "returns", "a", "new", "Padder", ".", "The", "enclosed", "Widget", "is", "given", "horizontal", "margin", "of", "x", "on", "the", "right", "and", "x", "on", "the", "left", "and", "a", "vertical", "margin", "of", "y", "on", "the", "top", "and", "y", "on", "the", "bottom", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/padder.go#L18-L23
6,572
marcusolsson/tui-go
padder.go
Draw
func (p *Padder) Draw(painter *Painter) { painter.Translate(p.padding.X, p.padding.Y) defer painter.Restore() p.widget.Draw(painter) }
go
func (p *Padder) Draw(painter *Painter) { painter.Translate(p.padding.X, p.padding.Y) defer painter.Restore() p.widget.Draw(painter) }
[ "func", "(", "p", "*", "Padder", ")", "Draw", "(", "painter", "*", "Painter", ")", "{", "painter", ".", "Translate", "(", "p", ".", "padding", ".", "X", ",", "p", ".", "padding", ".", "Y", ")", "\n", "defer", "painter", ".", "Restore", "(", ")", "\n\n", "p", ".", "widget", ".", "Draw", "(", "painter", ")", "\n", "}" ]
// Draw draws the padded widget.
[ "Draw", "draws", "the", "padded", "widget", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/padder.go#L26-L31
6,573
marcusolsson/tui-go
padder.go
Size
func (p *Padder) Size() image.Point { return p.widget.Size().Add(p.padding.Mul(2)) }
go
func (p *Padder) Size() image.Point { return p.widget.Size().Add(p.padding.Mul(2)) }
[ "func", "(", "p", "*", "Padder", ")", "Size", "(", ")", "image", ".", "Point", "{", "return", "p", ".", "widget", ".", "Size", "(", ")", ".", "Add", "(", "p", ".", "padding", ".", "Mul", "(", "2", ")", ")", "\n", "}" ]
// Size returns the size of the padded widget.
[ "Size", "returns", "the", "size", "of", "the", "padded", "widget", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/padder.go#L34-L36
6,574
marcusolsson/tui-go
padder.go
Resize
func (p *Padder) Resize(size image.Point) { p.widget.Resize(size.Sub(p.padding.Mul(2))) }
go
func (p *Padder) Resize(size image.Point) { p.widget.Resize(size.Sub(p.padding.Mul(2))) }
[ "func", "(", "p", "*", "Padder", ")", "Resize", "(", "size", "image", ".", "Point", ")", "{", "p", ".", "widget", ".", "Resize", "(", "size", ".", "Sub", "(", "p", ".", "padding", ".", "Mul", "(", "2", ")", ")", ")", "\n", "}" ]
// Resize updates the size of the padded widget.
[ "Resize", "updates", "the", "size", "of", "the", "padded", "widget", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/padder.go#L54-L56
6,575
marcusolsson/tui-go
button.go
Draw
func (b *Button) Draw(p *Painter) { style := "button" if b.IsFocused() { style += ".focused" } p.WithStyle(style, func(p *Painter) { lines := strings.Split(b.text, "\n") for i, line := range lines { p.FillRect(0, i, b.Size().X, 1) p.DrawText(0, i, line) } }) }
go
func (b *Button) Draw(p *Painter) { style := "button" if b.IsFocused() { style += ".focused" } p.WithStyle(style, func(p *Painter) { lines := strings.Split(b.text, "\n") for i, line := range lines { p.FillRect(0, i, b.Size().X, 1) p.DrawText(0, i, line) } }) }
[ "func", "(", "b", "*", "Button", ")", "Draw", "(", "p", "*", "Painter", ")", "{", "style", ":=", "\"", "\"", "\n", "if", "b", ".", "IsFocused", "(", ")", "{", "style", "+=", "\"", "\"", "\n", "}", "\n", "p", ".", "WithStyle", "(", "style", ",", "func", "(", "p", "*", "Painter", ")", "{", "lines", ":=", "strings", ".", "Split", "(", "b", ".", "text", ",", "\"", "\\n", "\"", ")", "\n", "for", "i", ",", "line", ":=", "range", "lines", "{", "p", ".", "FillRect", "(", "0", ",", "i", ",", "b", ".", "Size", "(", ")", ".", "X", ",", "1", ")", "\n", "p", ".", "DrawText", "(", "0", ",", "i", ",", "line", ")", "\n", "}", "\n", "}", ")", "\n", "}" ]
// Draw draws the button.
[ "Draw", "draws", "the", "button", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/button.go#L28-L40
6,576
marcusolsson/tui-go
button.go
SizeHint
func (b *Button) SizeHint() image.Point { if len(b.text) == 0 { return b.MinSizeHint() } var size image.Point lines := strings.Split(b.text, "\n") for _, line := range lines { if w := stringWidth(line); w > size.X { size.X = w } } size.Y = len(lines) return size }
go
func (b *Button) SizeHint() image.Point { if len(b.text) == 0 { return b.MinSizeHint() } var size image.Point lines := strings.Split(b.text, "\n") for _, line := range lines { if w := stringWidth(line); w > size.X { size.X = w } } size.Y = len(lines) return size }
[ "func", "(", "b", "*", "Button", ")", "SizeHint", "(", ")", "image", ".", "Point", "{", "if", "len", "(", "b", ".", "text", ")", "==", "0", "{", "return", "b", ".", "MinSizeHint", "(", ")", "\n", "}", "\n\n", "var", "size", "image", ".", "Point", "\n", "lines", ":=", "strings", ".", "Split", "(", "b", ".", "text", ",", "\"", "\\n", "\"", ")", "\n", "for", "_", ",", "line", ":=", "range", "lines", "{", "if", "w", ":=", "stringWidth", "(", "line", ")", ";", "w", ">", "size", ".", "X", "{", "size", ".", "X", "=", "w", "\n", "}", "\n", "}", "\n", "size", ".", "Y", "=", "len", "(", "lines", ")", "\n\n", "return", "size", "\n", "}" ]
// SizeHint returns the recommended size hint for the button.
[ "SizeHint", "returns", "the", "recommended", "size", "hint", "for", "the", "button", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/button.go#L43-L58
6,577
marcusolsson/tui-go
button.go
OnKeyEvent
func (b *Button) OnKeyEvent(ev KeyEvent) { if !b.IsFocused() { return } if ev.Key == KeyEnter && b.onActivated != nil { b.onActivated(b) } }
go
func (b *Button) OnKeyEvent(ev KeyEvent) { if !b.IsFocused() { return } if ev.Key == KeyEnter && b.onActivated != nil { b.onActivated(b) } }
[ "func", "(", "b", "*", "Button", ")", "OnKeyEvent", "(", "ev", "KeyEvent", ")", "{", "if", "!", "b", ".", "IsFocused", "(", ")", "{", "return", "\n", "}", "\n", "if", "ev", ".", "Key", "==", "KeyEnter", "&&", "b", ".", "onActivated", "!=", "nil", "{", "b", ".", "onActivated", "(", "b", ")", "\n", "}", "\n", "}" ]
// OnKeyEvent handles keys events.
[ "OnKeyEvent", "handles", "keys", "events", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/button.go#L61-L68
6,578
marcusolsson/tui-go
theme.go
mergeIn
func (s Style) mergeIn(delta Style) Style { result := s if delta.Fg != ColorDefault { result.Fg = delta.Fg } if delta.Bg != ColorDefault { result.Bg = delta.Bg } if delta.Reverse != DecorationInherit { result.Reverse = delta.Reverse } if delta.Bold != DecorationInherit { result.Bold = delta.Bold } if delta.Underline != DecorationInherit { result.Underline = delta.Underline } return result }
go
func (s Style) mergeIn(delta Style) Style { result := s if delta.Fg != ColorDefault { result.Fg = delta.Fg } if delta.Bg != ColorDefault { result.Bg = delta.Bg } if delta.Reverse != DecorationInherit { result.Reverse = delta.Reverse } if delta.Bold != DecorationInherit { result.Bold = delta.Bold } if delta.Underline != DecorationInherit { result.Underline = delta.Underline } return result }
[ "func", "(", "s", "Style", ")", "mergeIn", "(", "delta", "Style", ")", "Style", "{", "result", ":=", "s", "\n", "if", "delta", ".", "Fg", "!=", "ColorDefault", "{", "result", ".", "Fg", "=", "delta", ".", "Fg", "\n", "}", "\n", "if", "delta", ".", "Bg", "!=", "ColorDefault", "{", "result", ".", "Bg", "=", "delta", ".", "Bg", "\n", "}", "\n", "if", "delta", ".", "Reverse", "!=", "DecorationInherit", "{", "result", ".", "Reverse", "=", "delta", ".", "Reverse", "\n", "}", "\n", "if", "delta", ".", "Bold", "!=", "DecorationInherit", "{", "result", ".", "Bold", "=", "delta", ".", "Bold", "\n", "}", "\n", "if", "delta", ".", "Underline", "!=", "DecorationInherit", "{", "result", ".", "Underline", "=", "delta", ".", "Underline", "\n", "}", "\n", "return", "result", "\n", "}" ]
// mergeIn returns the receiver Style, with any changes in delta applied.
[ "mergeIn", "returns", "the", "receiver", "Style", "with", "any", "changes", "in", "delta", "applied", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/theme.go#L41-L59
6,579
marcusolsson/tui-go
theme.go
SetStyle
func (p *Theme) SetStyle(n string, i Style) { p.styles[n] = i }
go
func (p *Theme) SetStyle(n string, i Style) { p.styles[n] = i }
[ "func", "(", "p", "*", "Theme", ")", "SetStyle", "(", "n", "string", ",", "i", "Style", ")", "{", "p", ".", "styles", "[", "n", "]", "=", "i", "\n", "}" ]
// SetStyle sets a style for a given identifier.
[ "SetStyle", "sets", "a", "style", "for", "a", "given", "identifier", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/theme.go#L83-L85
6,580
marcusolsson/tui-go
theme.go
HasStyle
func (p *Theme) HasStyle(name string) bool { _, ok := p.styles[name] return ok }
go
func (p *Theme) HasStyle(name string) bool { _, ok := p.styles[name] return ok }
[ "func", "(", "p", "*", "Theme", ")", "HasStyle", "(", "name", "string", ")", "bool", "{", "_", ",", "ok", ":=", "p", ".", "styles", "[", "name", "]", "\n", "return", "ok", "\n", "}" ]
// HasStyle returns whether an identifier is associated with an identifier.
[ "HasStyle", "returns", "whether", "an", "identifier", "is", "associated", "with", "an", "identifier", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/theme.go#L94-L97
6,581
marcusolsson/tui-go
table.go
NewTable
func NewTable(cols, rows int) *Table { return &Table{ Grid: NewGrid(cols, rows), } }
go
func NewTable(cols, rows int) *Table { return &Table{ Grid: NewGrid(cols, rows), } }
[ "func", "NewTable", "(", "cols", ",", "rows", "int", ")", "*", "Table", "{", "return", "&", "Table", "{", "Grid", ":", "NewGrid", "(", "cols", ",", "rows", ")", ",", "}", "\n", "}" ]
// NewTable returns a new Table.
[ "NewTable", "returns", "a", "new", "Table", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/table.go#L17-L21
6,582
marcusolsson/tui-go
table.go
RemoveRow
func (t *Table) RemoveRow(index int) { t.Grid.RemoveRow(index) if t.selected == index { t.selected = -1 } else if t.selected > index { t.selected-- } }
go
func (t *Table) RemoveRow(index int) { t.Grid.RemoveRow(index) if t.selected == index { t.selected = -1 } else if t.selected > index { t.selected-- } }
[ "func", "(", "t", "*", "Table", ")", "RemoveRow", "(", "index", "int", ")", "{", "t", ".", "Grid", ".", "RemoveRow", "(", "index", ")", "\n", "if", "t", ".", "selected", "==", "index", "{", "t", ".", "selected", "=", "-", "1", "\n", "}", "else", "if", "t", ".", "selected", ">", "index", "{", "t", ".", "selected", "--", "\n", "}", "\n", "}" ]
// RemoveRow removes specific row from the table
[ "RemoveRow", "removes", "specific", "row", "from", "the", "table" ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/table.go#L162-L169
6,583
marcusolsson/tui-go
list.go
Draw
func (l *List) Draw(p *Painter) { for i, item := range l.items { style := "list.item" if i == l.selected-l.pos { style += ".selected" } p.WithStyle(style, func(p *Painter) { p.FillRect(0, i, l.Size().X, 1) p.DrawText(0, i, item) }) } }
go
func (l *List) Draw(p *Painter) { for i, item := range l.items { style := "list.item" if i == l.selected-l.pos { style += ".selected" } p.WithStyle(style, func(p *Painter) { p.FillRect(0, i, l.Size().X, 1) p.DrawText(0, i, item) }) } }
[ "func", "(", "l", "*", "List", ")", "Draw", "(", "p", "*", "Painter", ")", "{", "for", "i", ",", "item", ":=", "range", "l", ".", "items", "{", "style", ":=", "\"", "\"", "\n", "if", "i", "==", "l", ".", "selected", "-", "l", ".", "pos", "{", "style", "+=", "\"", "\"", "\n", "}", "\n", "p", ".", "WithStyle", "(", "style", ",", "func", "(", "p", "*", "Painter", ")", "{", "p", ".", "FillRect", "(", "0", ",", "i", ",", "l", ".", "Size", "(", ")", ".", "X", ",", "1", ")", "\n", "p", ".", "DrawText", "(", "0", ",", "i", ",", "item", ")", "\n", "}", ")", "\n", "}", "\n", "}" ]
// Draw draws the list.
[ "Draw", "draws", "the", "list", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/list.go#L27-L38
6,584
marcusolsson/tui-go
list.go
SizeHint
func (l *List) SizeHint() image.Point { var width int for _, item := range l.items { if w := stringWidth(item); w > width { width = w } } return image.Point{width, len(l.items)} }
go
func (l *List) SizeHint() image.Point { var width int for _, item := range l.items { if w := stringWidth(item); w > width { width = w } } return image.Point{width, len(l.items)} }
[ "func", "(", "l", "*", "List", ")", "SizeHint", "(", ")", "image", ".", "Point", "{", "var", "width", "int", "\n", "for", "_", ",", "item", ":=", "range", "l", ".", "items", "{", "if", "w", ":=", "stringWidth", "(", "item", ")", ";", "w", ">", "width", "{", "width", "=", "w", "\n", "}", "\n", "}", "\n", "return", "image", ".", "Point", "{", "width", ",", "len", "(", "l", ".", "items", ")", "}", "\n", "}" ]
// SizeHint returns the recommended size for the list.
[ "SizeHint", "returns", "the", "recommended", "size", "for", "the", "list", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/list.go#L41-L49
6,585
marcusolsson/tui-go
list.go
OnKeyEvent
func (l *List) OnKeyEvent(ev KeyEvent) { if !l.IsFocused() { return } switch ev.Key { case KeyUp: l.moveUp() case KeyDown: l.moveDown() case KeyEnter: if l.onItemActivated != nil { l.onItemActivated(l) } } switch ev.Rune { case 'k': l.moveUp() case 'j': l.moveDown() } }
go
func (l *List) OnKeyEvent(ev KeyEvent) { if !l.IsFocused() { return } switch ev.Key { case KeyUp: l.moveUp() case KeyDown: l.moveDown() case KeyEnter: if l.onItemActivated != nil { l.onItemActivated(l) } } switch ev.Rune { case 'k': l.moveUp() case 'j': l.moveDown() } }
[ "func", "(", "l", "*", "List", ")", "OnKeyEvent", "(", "ev", "KeyEvent", ")", "{", "if", "!", "l", ".", "IsFocused", "(", ")", "{", "return", "\n", "}", "\n\n", "switch", "ev", ".", "Key", "{", "case", "KeyUp", ":", "l", ".", "moveUp", "(", ")", "\n", "case", "KeyDown", ":", "l", ".", "moveDown", "(", ")", "\n", "case", "KeyEnter", ":", "if", "l", ".", "onItemActivated", "!=", "nil", "{", "l", ".", "onItemActivated", "(", "l", ")", "\n", "}", "\n", "}", "\n\n", "switch", "ev", ".", "Rune", "{", "case", "'k'", ":", "l", ".", "moveUp", "(", ")", "\n", "case", "'j'", ":", "l", ".", "moveDown", "(", ")", "\n", "}", "\n", "}" ]
// OnKeyEvent handles terminal events.
[ "OnKeyEvent", "handles", "terminal", "events", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/list.go#L52-L74
6,586
marcusolsson/tui-go
list.go
AddItems
func (l *List) AddItems(items ...string) { l.items = append(l.items, items...) }
go
func (l *List) AddItems(items ...string) { l.items = append(l.items, items...) }
[ "func", "(", "l", "*", "List", ")", "AddItems", "(", "items", "...", "string", ")", "{", "l", ".", "items", "=", "append", "(", "l", ".", "items", ",", "items", "...", ")", "\n", "}" ]
// AddItems appends items to the end of the list.
[ "AddItems", "appends", "items", "to", "the", "end", "of", "the", "list", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/list.go#L102-L104
6,587
marcusolsson/tui-go
list.go
RemoveItems
func (l *List) RemoveItems() { l.items = []string{} l.pos = 0 l.selected = -1 if l.onSelectionChanged != nil { l.onSelectionChanged(l) } }
go
func (l *List) RemoveItems() { l.items = []string{} l.pos = 0 l.selected = -1 if l.onSelectionChanged != nil { l.onSelectionChanged(l) } }
[ "func", "(", "l", "*", "List", ")", "RemoveItems", "(", ")", "{", "l", ".", "items", "=", "[", "]", "string", "{", "}", "\n", "l", ".", "pos", "=", "0", "\n", "l", ".", "selected", "=", "-", "1", "\n", "if", "l", ".", "onSelectionChanged", "!=", "nil", "{", "l", ".", "onSelectionChanged", "(", "l", ")", "\n", "}", "\n", "}" ]
// RemoveItems clears all the items from the list.
[ "RemoveItems", "clears", "all", "the", "items", "from", "the", "list", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/list.go#L107-L114
6,588
marcusolsson/tui-go
list.go
RemoveItem
func (l *List) RemoveItem(i int) { // Adjust pos and selected before removing. if l.pos >= len(l.items) { l.pos-- } if l.selected == i { l.selected = -1 } else if l.selected > i { l.selected-- } // Copy items following i to position i. copy(l.items[i:], l.items[i+1:]) // Shrink items by one. l.items[len(l.items)-1] = "" l.items = l.items[:len(l.items)-1] if l.onSelectionChanged != nil { l.onSelectionChanged(l) } }
go
func (l *List) RemoveItem(i int) { // Adjust pos and selected before removing. if l.pos >= len(l.items) { l.pos-- } if l.selected == i { l.selected = -1 } else if l.selected > i { l.selected-- } // Copy items following i to position i. copy(l.items[i:], l.items[i+1:]) // Shrink items by one. l.items[len(l.items)-1] = "" l.items = l.items[:len(l.items)-1] if l.onSelectionChanged != nil { l.onSelectionChanged(l) } }
[ "func", "(", "l", "*", "List", ")", "RemoveItem", "(", "i", "int", ")", "{", "// Adjust pos and selected before removing.", "if", "l", ".", "pos", ">=", "len", "(", "l", ".", "items", ")", "{", "l", ".", "pos", "--", "\n", "}", "\n", "if", "l", ".", "selected", "==", "i", "{", "l", ".", "selected", "=", "-", "1", "\n", "}", "else", "if", "l", ".", "selected", ">", "i", "{", "l", ".", "selected", "--", "\n", "}", "\n\n", "// Copy items following i to position i.", "copy", "(", "l", ".", "items", "[", "i", ":", "]", ",", "l", ".", "items", "[", "i", "+", "1", ":", "]", ")", "\n\n", "// Shrink items by one.", "l", ".", "items", "[", "len", "(", "l", ".", "items", ")", "-", "1", "]", "=", "\"", "\"", "\n", "l", ".", "items", "=", "l", ".", "items", "[", ":", "len", "(", "l", ".", "items", ")", "-", "1", "]", "\n\n", "if", "l", ".", "onSelectionChanged", "!=", "nil", "{", "l", ".", "onSelectionChanged", "(", "l", ")", "\n", "}", "\n", "}" ]
// RemoveItem removes the item at the given position.
[ "RemoveItem", "removes", "the", "item", "at", "the", "given", "position", "." ]
4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0
https://github.com/marcusolsson/tui-go/blob/4bb09120fbbb8b6e7d44d802f1e66f78bb4650a0/list.go#L117-L138
6,589
google/skylark
syntax/quote.go
unquote
func unquote(quoted string) (s string, triple bool, err error) { // Check for raw prefix: means don't interpret the inner \. raw := false if strings.HasPrefix(quoted, "r") { raw = true quoted = quoted[1:] } if len(quoted) < 2 { err = fmt.Errorf("string literal too short") return } if quoted[0] != '"' && quoted[0] != '\'' || quoted[0] != quoted[len(quoted)-1] { err = fmt.Errorf("string literal has invalid quotes") return } // Check for triple quoted string. quote := quoted[0] if len(quoted) >= 6 && quoted[1] == quote && quoted[2] == quote && quoted[:3] == quoted[len(quoted)-3:] { triple = true quoted = quoted[3 : len(quoted)-3] } else { quoted = quoted[1 : len(quoted)-1] } // Now quoted is the quoted data, but no quotes. // If we're in raw mode or there are no escapes or // carriage returns, we're done. var unquoteChars string if raw { unquoteChars = "\r" } else { unquoteChars = "\\\r" } if !strings.ContainsAny(quoted, unquoteChars) { s = quoted return } // Otherwise process quoted string. // Each iteration processes one escape sequence along with the // plain text leading up to it. var buf bytes.Buffer for { // Remove prefix before escape sequence. i := strings.IndexAny(quoted, unquoteChars) if i < 0 { i = len(quoted) } buf.WriteString(quoted[:i]) quoted = quoted[i:] if len(quoted) == 0 { break } // Process carriage return. if quoted[0] == '\r' { buf.WriteByte('\n') if len(quoted) > 1 && quoted[1] == '\n' { quoted = quoted[2:] } else { quoted = quoted[1:] } continue } // Process escape sequence. if len(quoted) == 1 { err = fmt.Errorf(`truncated escape sequence \`) return } switch quoted[1] { default: // In Python, if \z (for some byte z) is not a known escape sequence // then it appears as literal text in the string. buf.WriteString(quoted[:2]) quoted = quoted[2:] case '\n': // Ignore the escape and the line break. quoted = quoted[2:] case 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', '\'', '"': // One-char escape buf.WriteByte(unesc[quoted[1]]) quoted = quoted[2:] case '0', '1', '2', '3', '4', '5', '6', '7': // Octal escape, up to 3 digits. n := int(quoted[1] - '0') quoted = quoted[2:] for i := 1; i < 3; i++ { if len(quoted) == 0 || quoted[0] < '0' || '7' < quoted[0] { break } n = n*8 + int(quoted[0]-'0') quoted = quoted[1:] } if n >= 256 { // NOTE: Python silently discards the high bit, // so that '\541' == '\141' == 'a'. // Let's see if we can avoid doing that in BUILD files. err = fmt.Errorf(`invalid escape sequence \%03o`, n) return } buf.WriteByte(byte(n)) case 'x': // Hexadecimal escape, exactly 2 digits. if len(quoted) < 4 { err = fmt.Errorf(`truncated escape sequence %s`, quoted) return } n, err1 := strconv.ParseInt(quoted[2:4], 16, 0) if err1 != nil { err = fmt.Errorf(`invalid escape sequence %s`, quoted[:4]) return } buf.WriteByte(byte(n)) quoted = quoted[4:] } } s = buf.String() return }
go
func unquote(quoted string) (s string, triple bool, err error) { // Check for raw prefix: means don't interpret the inner \. raw := false if strings.HasPrefix(quoted, "r") { raw = true quoted = quoted[1:] } if len(quoted) < 2 { err = fmt.Errorf("string literal too short") return } if quoted[0] != '"' && quoted[0] != '\'' || quoted[0] != quoted[len(quoted)-1] { err = fmt.Errorf("string literal has invalid quotes") return } // Check for triple quoted string. quote := quoted[0] if len(quoted) >= 6 && quoted[1] == quote && quoted[2] == quote && quoted[:3] == quoted[len(quoted)-3:] { triple = true quoted = quoted[3 : len(quoted)-3] } else { quoted = quoted[1 : len(quoted)-1] } // Now quoted is the quoted data, but no quotes. // If we're in raw mode or there are no escapes or // carriage returns, we're done. var unquoteChars string if raw { unquoteChars = "\r" } else { unquoteChars = "\\\r" } if !strings.ContainsAny(quoted, unquoteChars) { s = quoted return } // Otherwise process quoted string. // Each iteration processes one escape sequence along with the // plain text leading up to it. var buf bytes.Buffer for { // Remove prefix before escape sequence. i := strings.IndexAny(quoted, unquoteChars) if i < 0 { i = len(quoted) } buf.WriteString(quoted[:i]) quoted = quoted[i:] if len(quoted) == 0 { break } // Process carriage return. if quoted[0] == '\r' { buf.WriteByte('\n') if len(quoted) > 1 && quoted[1] == '\n' { quoted = quoted[2:] } else { quoted = quoted[1:] } continue } // Process escape sequence. if len(quoted) == 1 { err = fmt.Errorf(`truncated escape sequence \`) return } switch quoted[1] { default: // In Python, if \z (for some byte z) is not a known escape sequence // then it appears as literal text in the string. buf.WriteString(quoted[:2]) quoted = quoted[2:] case '\n': // Ignore the escape and the line break. quoted = quoted[2:] case 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', '\'', '"': // One-char escape buf.WriteByte(unesc[quoted[1]]) quoted = quoted[2:] case '0', '1', '2', '3', '4', '5', '6', '7': // Octal escape, up to 3 digits. n := int(quoted[1] - '0') quoted = quoted[2:] for i := 1; i < 3; i++ { if len(quoted) == 0 || quoted[0] < '0' || '7' < quoted[0] { break } n = n*8 + int(quoted[0]-'0') quoted = quoted[1:] } if n >= 256 { // NOTE: Python silently discards the high bit, // so that '\541' == '\141' == 'a'. // Let's see if we can avoid doing that in BUILD files. err = fmt.Errorf(`invalid escape sequence \%03o`, n) return } buf.WriteByte(byte(n)) case 'x': // Hexadecimal escape, exactly 2 digits. if len(quoted) < 4 { err = fmt.Errorf(`truncated escape sequence %s`, quoted) return } n, err1 := strconv.ParseInt(quoted[2:4], 16, 0) if err1 != nil { err = fmt.Errorf(`invalid escape sequence %s`, quoted[:4]) return } buf.WriteByte(byte(n)) quoted = quoted[4:] } } s = buf.String() return }
[ "func", "unquote", "(", "quoted", "string", ")", "(", "s", "string", ",", "triple", "bool", ",", "err", "error", ")", "{", "// Check for raw prefix: means don't interpret the inner \\.", "raw", ":=", "false", "\n", "if", "strings", ".", "HasPrefix", "(", "quoted", ",", "\"", "\"", ")", "{", "raw", "=", "true", "\n", "quoted", "=", "quoted", "[", "1", ":", "]", "\n", "}", "\n\n", "if", "len", "(", "quoted", ")", "<", "2", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n\n", "if", "quoted", "[", "0", "]", "!=", "'\"'", "&&", "quoted", "[", "0", "]", "!=", "'\\''", "||", "quoted", "[", "0", "]", "!=", "quoted", "[", "len", "(", "quoted", ")", "-", "1", "]", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n\n", "// Check for triple quoted string.", "quote", ":=", "quoted", "[", "0", "]", "\n", "if", "len", "(", "quoted", ")", ">=", "6", "&&", "quoted", "[", "1", "]", "==", "quote", "&&", "quoted", "[", "2", "]", "==", "quote", "&&", "quoted", "[", ":", "3", "]", "==", "quoted", "[", "len", "(", "quoted", ")", "-", "3", ":", "]", "{", "triple", "=", "true", "\n", "quoted", "=", "quoted", "[", "3", ":", "len", "(", "quoted", ")", "-", "3", "]", "\n", "}", "else", "{", "quoted", "=", "quoted", "[", "1", ":", "len", "(", "quoted", ")", "-", "1", "]", "\n", "}", "\n\n", "// Now quoted is the quoted data, but no quotes.", "// If we're in raw mode or there are no escapes or", "// carriage returns, we're done.", "var", "unquoteChars", "string", "\n", "if", "raw", "{", "unquoteChars", "=", "\"", "\\r", "\"", "\n", "}", "else", "{", "unquoteChars", "=", "\"", "\\\\", "\\r", "\"", "\n", "}", "\n", "if", "!", "strings", ".", "ContainsAny", "(", "quoted", ",", "unquoteChars", ")", "{", "s", "=", "quoted", "\n", "return", "\n", "}", "\n\n", "// Otherwise process quoted string.", "// Each iteration processes one escape sequence along with the", "// plain text leading up to it.", "var", "buf", "bytes", ".", "Buffer", "\n", "for", "{", "// Remove prefix before escape sequence.", "i", ":=", "strings", ".", "IndexAny", "(", "quoted", ",", "unquoteChars", ")", "\n", "if", "i", "<", "0", "{", "i", "=", "len", "(", "quoted", ")", "\n", "}", "\n", "buf", ".", "WriteString", "(", "quoted", "[", ":", "i", "]", ")", "\n", "quoted", "=", "quoted", "[", "i", ":", "]", "\n\n", "if", "len", "(", "quoted", ")", "==", "0", "{", "break", "\n", "}", "\n\n", "// Process carriage return.", "if", "quoted", "[", "0", "]", "==", "'\\r'", "{", "buf", ".", "WriteByte", "(", "'\\n'", ")", "\n", "if", "len", "(", "quoted", ")", ">", "1", "&&", "quoted", "[", "1", "]", "==", "'\\n'", "{", "quoted", "=", "quoted", "[", "2", ":", "]", "\n", "}", "else", "{", "quoted", "=", "quoted", "[", "1", ":", "]", "\n", "}", "\n", "continue", "\n", "}", "\n\n", "// Process escape sequence.", "if", "len", "(", "quoted", ")", "==", "1", "{", "err", "=", "fmt", ".", "Errorf", "(", "`truncated escape sequence \\`", ")", "\n", "return", "\n", "}", "\n\n", "switch", "quoted", "[", "1", "]", "{", "default", ":", "// In Python, if \\z (for some byte z) is not a known escape sequence", "// then it appears as literal text in the string.", "buf", ".", "WriteString", "(", "quoted", "[", ":", "2", "]", ")", "\n", "quoted", "=", "quoted", "[", "2", ":", "]", "\n\n", "case", "'\\n'", ":", "// Ignore the escape and the line break.", "quoted", "=", "quoted", "[", "2", ":", "]", "\n\n", "case", "'a'", ",", "'b'", ",", "'f'", ",", "'n'", ",", "'r'", ",", "'t'", ",", "'v'", ",", "'\\\\'", ",", "'\\''", ",", "'\"'", ":", "// One-char escape", "buf", ".", "WriteByte", "(", "unesc", "[", "quoted", "[", "1", "]", "]", ")", "\n", "quoted", "=", "quoted", "[", "2", ":", "]", "\n\n", "case", "'0'", ",", "'1'", ",", "'2'", ",", "'3'", ",", "'4'", ",", "'5'", ",", "'6'", ",", "'7'", ":", "// Octal escape, up to 3 digits.", "n", ":=", "int", "(", "quoted", "[", "1", "]", "-", "'0'", ")", "\n", "quoted", "=", "quoted", "[", "2", ":", "]", "\n", "for", "i", ":=", "1", ";", "i", "<", "3", ";", "i", "++", "{", "if", "len", "(", "quoted", ")", "==", "0", "||", "quoted", "[", "0", "]", "<", "'0'", "||", "'7'", "<", "quoted", "[", "0", "]", "{", "break", "\n", "}", "\n", "n", "=", "n", "*", "8", "+", "int", "(", "quoted", "[", "0", "]", "-", "'0'", ")", "\n", "quoted", "=", "quoted", "[", "1", ":", "]", "\n", "}", "\n", "if", "n", ">=", "256", "{", "// NOTE: Python silently discards the high bit,", "// so that '\\541' == '\\141' == 'a'.", "// Let's see if we can avoid doing that in BUILD files.", "err", "=", "fmt", ".", "Errorf", "(", "`invalid escape sequence \\%03o`", ",", "n", ")", "\n", "return", "\n", "}", "\n", "buf", ".", "WriteByte", "(", "byte", "(", "n", ")", ")", "\n\n", "case", "'x'", ":", "// Hexadecimal escape, exactly 2 digits.", "if", "len", "(", "quoted", ")", "<", "4", "{", "err", "=", "fmt", ".", "Errorf", "(", "`truncated escape sequence %s`", ",", "quoted", ")", "\n", "return", "\n", "}", "\n", "n", ",", "err1", ":=", "strconv", ".", "ParseInt", "(", "quoted", "[", "2", ":", "4", "]", ",", "16", ",", "0", ")", "\n", "if", "err1", "!=", "nil", "{", "err", "=", "fmt", ".", "Errorf", "(", "`invalid escape sequence %s`", ",", "quoted", "[", ":", "4", "]", ")", "\n", "return", "\n", "}", "\n", "buf", ".", "WriteByte", "(", "byte", "(", "n", ")", ")", "\n", "quoted", "=", "quoted", "[", "4", ":", "]", "\n", "}", "\n", "}", "\n\n", "s", "=", "buf", ".", "String", "(", ")", "\n", "return", "\n", "}" ]
// unquote unquotes the quoted string, returning the actual // string value, whether the original was triple-quoted, and // an error describing invalid input.
[ "unquote", "unquotes", "the", "quoted", "string", "returning", "the", "actual", "string", "value", "whether", "the", "original", "was", "triple", "-", "quoted", "and", "an", "error", "describing", "invalid", "input", "." ]
a5f7082aabed29c0e429c722292c66ec8ecf9591
https://github.com/google/skylark/blob/a5f7082aabed29c0e429c722292c66ec8ecf9591/syntax/quote.go#L54-L183
6,590
google/skylark
syntax/quote.go
indexByte
func indexByte(s string, b byte) int { for i := 0; i < len(s); i++ { if s[i] == b { return i } } return -1 }
go
func indexByte(s string, b byte) int { for i := 0; i < len(s); i++ { if s[i] == b { return i } } return -1 }
[ "func", "indexByte", "(", "s", "string", ",", "b", "byte", ")", "int", "{", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "s", ")", ";", "i", "++", "{", "if", "s", "[", "i", "]", "==", "b", "{", "return", "i", "\n", "}", "\n", "}", "\n", "return", "-", "1", "\n", "}" ]
// indexByte returns the index of the first instance of b in s, or else -1.
[ "indexByte", "returns", "the", "index", "of", "the", "first", "instance", "of", "b", "in", "s", "or", "else", "-", "1", "." ]
a5f7082aabed29c0e429c722292c66ec8ecf9591
https://github.com/google/skylark/blob/a5f7082aabed29c0e429c722292c66ec8ecf9591/syntax/quote.go#L186-L193
6,591
google/skylark
syntax/quote.go
quote
func quote(unquoted string, triple bool) string { q := `"` if triple { q = `"""` } var buf bytes.Buffer buf.WriteString(q) for i := 0; i < len(unquoted); i++ { c := unquoted[i] if c == '"' && triple && (i+1 < len(unquoted) && unquoted[i+1] != '"' || i+2 < len(unquoted) && unquoted[i+2] != '"') { // Can pass up to two quotes through, because they are followed by a non-quote byte. buf.WriteByte(c) if i+1 < len(unquoted) && unquoted[i+1] == '"' { buf.WriteByte(c) i++ } continue } if triple && c == '\n' { // Can allow newline in triple-quoted string. buf.WriteByte(c) continue } if c == '\'' { // Can allow ' since we always use ". buf.WriteByte(c) continue } if c == '\\' { if i+1 < len(unquoted) && indexByte(notEsc, unquoted[i+1]) >= 0 { // Can pass \ through when followed by a byte that // known not to be a valid escape sequence and also // that does not trigger an escape sequence of its own. // Use this, because various BUILD files do. buf.WriteByte('\\') buf.WriteByte(unquoted[i+1]) i++ continue } } if esc[c] != 0 { buf.WriteByte('\\') buf.WriteByte(esc[c]) continue } if c < 0x20 || c >= 0x80 { // BUILD files are supposed to be Latin-1, so escape all control and high bytes. // I'd prefer to use \x here, but Blaze does not implement // \x in quoted strings (b/7272572). buf.WriteByte('\\') buf.WriteByte(hex[c>>6]) // actually octal but reusing hex digits 0-7. buf.WriteByte(hex[(c>>3)&7]) buf.WriteByte(hex[c&7]) /* buf.WriteByte('\\') buf.WriteByte('x') buf.WriteByte(hex[c>>4]) buf.WriteByte(hex[c&0xF]) */ continue } buf.WriteByte(c) continue } buf.WriteString(q) return buf.String() }
go
func quote(unquoted string, triple bool) string { q := `"` if triple { q = `"""` } var buf bytes.Buffer buf.WriteString(q) for i := 0; i < len(unquoted); i++ { c := unquoted[i] if c == '"' && triple && (i+1 < len(unquoted) && unquoted[i+1] != '"' || i+2 < len(unquoted) && unquoted[i+2] != '"') { // Can pass up to two quotes through, because they are followed by a non-quote byte. buf.WriteByte(c) if i+1 < len(unquoted) && unquoted[i+1] == '"' { buf.WriteByte(c) i++ } continue } if triple && c == '\n' { // Can allow newline in triple-quoted string. buf.WriteByte(c) continue } if c == '\'' { // Can allow ' since we always use ". buf.WriteByte(c) continue } if c == '\\' { if i+1 < len(unquoted) && indexByte(notEsc, unquoted[i+1]) >= 0 { // Can pass \ through when followed by a byte that // known not to be a valid escape sequence and also // that does not trigger an escape sequence of its own. // Use this, because various BUILD files do. buf.WriteByte('\\') buf.WriteByte(unquoted[i+1]) i++ continue } } if esc[c] != 0 { buf.WriteByte('\\') buf.WriteByte(esc[c]) continue } if c < 0x20 || c >= 0x80 { // BUILD files are supposed to be Latin-1, so escape all control and high bytes. // I'd prefer to use \x here, but Blaze does not implement // \x in quoted strings (b/7272572). buf.WriteByte('\\') buf.WriteByte(hex[c>>6]) // actually octal but reusing hex digits 0-7. buf.WriteByte(hex[(c>>3)&7]) buf.WriteByte(hex[c&7]) /* buf.WriteByte('\\') buf.WriteByte('x') buf.WriteByte(hex[c>>4]) buf.WriteByte(hex[c&0xF]) */ continue } buf.WriteByte(c) continue } buf.WriteString(q) return buf.String() }
[ "func", "quote", "(", "unquoted", "string", ",", "triple", "bool", ")", "string", "{", "q", ":=", "`\"`", "\n", "if", "triple", "{", "q", "=", "`\"\"\"`", "\n", "}", "\n\n", "var", "buf", "bytes", ".", "Buffer", "\n", "buf", ".", "WriteString", "(", "q", ")", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "unquoted", ")", ";", "i", "++", "{", "c", ":=", "unquoted", "[", "i", "]", "\n", "if", "c", "==", "'\"'", "&&", "triple", "&&", "(", "i", "+", "1", "<", "len", "(", "unquoted", ")", "&&", "unquoted", "[", "i", "+", "1", "]", "!=", "'\"'", "||", "i", "+", "2", "<", "len", "(", "unquoted", ")", "&&", "unquoted", "[", "i", "+", "2", "]", "!=", "'\"'", ")", "{", "// Can pass up to two quotes through, because they are followed by a non-quote byte.", "buf", ".", "WriteByte", "(", "c", ")", "\n", "if", "i", "+", "1", "<", "len", "(", "unquoted", ")", "&&", "unquoted", "[", "i", "+", "1", "]", "==", "'\"'", "{", "buf", ".", "WriteByte", "(", "c", ")", "\n", "i", "++", "\n", "}", "\n", "continue", "\n", "}", "\n", "if", "triple", "&&", "c", "==", "'\\n'", "{", "// Can allow newline in triple-quoted string.", "buf", ".", "WriteByte", "(", "c", ")", "\n", "continue", "\n", "}", "\n", "if", "c", "==", "'\\''", "{", "// Can allow ' since we always use \".", "buf", ".", "WriteByte", "(", "c", ")", "\n", "continue", "\n", "}", "\n", "if", "c", "==", "'\\\\'", "{", "if", "i", "+", "1", "<", "len", "(", "unquoted", ")", "&&", "indexByte", "(", "notEsc", ",", "unquoted", "[", "i", "+", "1", "]", ")", ">=", "0", "{", "// Can pass \\ through when followed by a byte that", "// known not to be a valid escape sequence and also", "// that does not trigger an escape sequence of its own.", "// Use this, because various BUILD files do.", "buf", ".", "WriteByte", "(", "'\\\\'", ")", "\n", "buf", ".", "WriteByte", "(", "unquoted", "[", "i", "+", "1", "]", ")", "\n", "i", "++", "\n", "continue", "\n", "}", "\n", "}", "\n", "if", "esc", "[", "c", "]", "!=", "0", "{", "buf", ".", "WriteByte", "(", "'\\\\'", ")", "\n", "buf", ".", "WriteByte", "(", "esc", "[", "c", "]", ")", "\n", "continue", "\n", "}", "\n", "if", "c", "<", "0x20", "||", "c", ">=", "0x80", "{", "// BUILD files are supposed to be Latin-1, so escape all control and high bytes.", "// I'd prefer to use \\x here, but Blaze does not implement", "// \\x in quoted strings (b/7272572).", "buf", ".", "WriteByte", "(", "'\\\\'", ")", "\n", "buf", ".", "WriteByte", "(", "hex", "[", "c", ">>", "6", "]", ")", "// actually octal but reusing hex digits 0-7.", "\n", "buf", ".", "WriteByte", "(", "hex", "[", "(", "c", ">>", "3", ")", "&", "7", "]", ")", "\n", "buf", ".", "WriteByte", "(", "hex", "[", "c", "&", "7", "]", ")", "\n", "/*\n\t\t\t\tbuf.WriteByte('\\\\')\n\t\t\t\tbuf.WriteByte('x')\n\t\t\t\tbuf.WriteByte(hex[c>>4])\n\t\t\t\tbuf.WriteByte(hex[c&0xF])\n\t\t\t*/", "continue", "\n", "}", "\n", "buf", ".", "WriteByte", "(", "c", ")", "\n", "continue", "\n", "}", "\n\n", "buf", ".", "WriteString", "(", "q", ")", "\n", "return", "buf", ".", "String", "(", ")", "\n", "}" ]
// quote returns the quoted form of the string value "x". // If triple is true, quote uses the triple-quoted form """x""".
[ "quote", "returns", "the", "quoted", "form", "of", "the", "string", "value", "x", ".", "If", "triple", "is", "true", "quote", "uses", "the", "triple", "-", "quoted", "form", "x", "." ]
a5f7082aabed29c0e429c722292c66ec8ecf9591
https://github.com/google/skylark/blob/a5f7082aabed29c0e429c722292c66ec8ecf9591/syntax/quote.go#L201-L270
6,592
google/skylark
syntax/syntax.go
AllocComments
func (cr *commentsRef) AllocComments() { if cr.ref == nil { cr.ref = new(Comments) } }
go
func (cr *commentsRef) AllocComments() { if cr.ref == nil { cr.ref = new(Comments) } }
[ "func", "(", "cr", "*", "commentsRef", ")", "AllocComments", "(", ")", "{", "if", "cr", ".", "ref", "==", "nil", "{", "cr", ".", "ref", "=", "new", "(", "Comments", ")", "\n", "}", "\n", "}" ]
// AllocComments enables comments to be associated with a syntax node.
[ "AllocComments", "enables", "comments", "to", "be", "associated", "with", "a", "syntax", "node", "." ]
a5f7082aabed29c0e429c722292c66ec8ecf9591
https://github.com/google/skylark/blob/a5f7082aabed29c0e429c722292c66ec8ecf9591/syntax/syntax.go#L49-L53
6,593
google/skylark
value.go
AsFloat
func AsFloat(x Value) (f float64, ok bool) { switch x := x.(type) { case Float: return float64(x), true case Int: return float64(x.Float()), true } return 0, false }
go
func AsFloat(x Value) (f float64, ok bool) { switch x := x.(type) { case Float: return float64(x), true case Int: return float64(x.Float()), true } return 0, false }
[ "func", "AsFloat", "(", "x", "Value", ")", "(", "f", "float64", ",", "ok", "bool", ")", "{", "switch", "x", ":=", "x", ".", "(", "type", ")", "{", "case", "Float", ":", "return", "float64", "(", "x", ")", ",", "true", "\n", "case", "Int", ":", "return", "float64", "(", "x", ".", "Float", "(", ")", ")", ",", "true", "\n", "}", "\n", "return", "0", ",", "false", "\n", "}" ]
// AsFloat returns the float64 value closest to x. // The f result is undefined if x is not a float or int.
[ "AsFloat", "returns", "the", "float64", "value", "closest", "to", "x", ".", "The", "f", "result", "is", "undefined", "if", "x", "is", "not", "a", "float", "or", "int", "." ]
a5f7082aabed29c0e429c722292c66ec8ecf9591
https://github.com/google/skylark/blob/a5f7082aabed29c0e429c722292c66ec8ecf9591/value.go#L392-L400
6,594
google/skylark
value.go
Globals
func (fn *Function) Globals() StringDict { m := make(StringDict, len(fn.funcode.Prog.Globals)) for i, id := range fn.funcode.Prog.Globals { if v := fn.globals[i]; v != nil { m[id.Name] = v } } return m }
go
func (fn *Function) Globals() StringDict { m := make(StringDict, len(fn.funcode.Prog.Globals)) for i, id := range fn.funcode.Prog.Globals { if v := fn.globals[i]; v != nil { m[id.Name] = v } } return m }
[ "func", "(", "fn", "*", "Function", ")", "Globals", "(", ")", "StringDict", "{", "m", ":=", "make", "(", "StringDict", ",", "len", "(", "fn", ".", "funcode", ".", "Prog", ".", "Globals", ")", ")", "\n", "for", "i", ",", "id", ":=", "range", "fn", ".", "funcode", ".", "Prog", ".", "Globals", "{", "if", "v", ":=", "fn", ".", "globals", "[", "i", "]", ";", "v", "!=", "nil", "{", "m", "[", "id", ".", "Name", "]", "=", "v", "\n", "}", "\n", "}", "\n", "return", "m", "\n", "}" ]
// Globals returns a new, unfrozen StringDict containing all global // variables so far defined in the function's module.
[ "Globals", "returns", "a", "new", "unfrozen", "StringDict", "containing", "all", "global", "variables", "so", "far", "defined", "in", "the", "function", "s", "module", "." ]
a5f7082aabed29c0e429c722292c66ec8ecf9591
https://github.com/google/skylark/blob/a5f7082aabed29c0e429c722292c66ec8ecf9591/value.go#L540-L548
6,595
google/skylark
value.go
NewBuiltin
func NewBuiltin(name string, fn func(thread *Thread, fn *Builtin, args Tuple, kwargs []Tuple) (Value, error)) *Builtin { return &Builtin{name: name, fn: fn} }
go
func NewBuiltin(name string, fn func(thread *Thread, fn *Builtin, args Tuple, kwargs []Tuple) (Value, error)) *Builtin { return &Builtin{name: name, fn: fn} }
[ "func", "NewBuiltin", "(", "name", "string", ",", "fn", "func", "(", "thread", "*", "Thread", ",", "fn", "*", "Builtin", ",", "args", "Tuple", ",", "kwargs", "[", "]", "Tuple", ")", "(", "Value", ",", "error", ")", ")", "*", "Builtin", "{", "return", "&", "Builtin", "{", "name", ":", "name", ",", "fn", ":", "fn", "}", "\n", "}" ]
// NewBuiltin returns a new 'builtin_function_or_method' value with the specified name // and implementation. It compares unequal with all other values.
[ "NewBuiltin", "returns", "a", "new", "builtin_function_or_method", "value", "with", "the", "specified", "name", "and", "implementation", ".", "It", "compares", "unequal", "with", "all", "other", "values", "." ]
a5f7082aabed29c0e429c722292c66ec8ecf9591
https://github.com/google/skylark/blob/a5f7082aabed29c0e429c722292c66ec8ecf9591/value.go#L589-L591
6,596
google/skylark
value.go
checkMutable
func (l *List) checkMutable(verb string, structural bool) error { if l.frozen { return fmt.Errorf("cannot %s frozen list", verb) } if structural && l.itercount > 0 { return fmt.Errorf("cannot %s list during iteration", verb) } return nil }
go
func (l *List) checkMutable(verb string, structural bool) error { if l.frozen { return fmt.Errorf("cannot %s frozen list", verb) } if structural && l.itercount > 0 { return fmt.Errorf("cannot %s list during iteration", verb) } return nil }
[ "func", "(", "l", "*", "List", ")", "checkMutable", "(", "verb", "string", ",", "structural", "bool", ")", "error", "{", "if", "l", ".", "frozen", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "verb", ")", "\n", "}", "\n", "if", "structural", "&&", "l", ".", "itercount", ">", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "verb", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// checkMutable reports an error if the list should not be mutated. // verb+" list" should describe the operation. // Structural mutations are not permitted during iteration.
[ "checkMutable", "reports", "an", "error", "if", "the", "list", "should", "not", "be", "mutated", ".", "verb", "+", "list", "should", "describe", "the", "operation", ".", "Structural", "mutations", "are", "not", "permitted", "during", "iteration", "." ]
a5f7082aabed29c0e429c722292c66ec8ecf9591
https://github.com/google/skylark/blob/a5f7082aabed29c0e429c722292c66ec8ecf9591/value.go#L690-L698
6,597
google/skylark
value.go
Equal
func Equal(x, y Value) (bool, error) { if x, ok := x.(String); ok { return x == y, nil // fast path for an important special case } return EqualDepth(x, y, maxdepth) }
go
func Equal(x, y Value) (bool, error) { if x, ok := x.(String); ok { return x == y, nil // fast path for an important special case } return EqualDepth(x, y, maxdepth) }
[ "func", "Equal", "(", "x", ",", "y", "Value", ")", "(", "bool", ",", "error", ")", "{", "if", "x", ",", "ok", ":=", "x", ".", "(", "String", ")", ";", "ok", "{", "return", "x", "==", "y", ",", "nil", "// fast path for an important special case", "\n", "}", "\n", "return", "EqualDepth", "(", "x", ",", "y", ",", "maxdepth", ")", "\n", "}" ]
// Equal reports whether two Skylark values are equal.
[ "Equal", "reports", "whether", "two", "Skylark", "values", "are", "equal", "." ]
a5f7082aabed29c0e429c722292c66ec8ecf9591
https://github.com/google/skylark/blob/a5f7082aabed29c0e429c722292c66ec8ecf9591/value.go#L1045-L1050
6,598
google/skylark
value.go
EqualDepth
func EqualDepth(x, y Value, depth int) (bool, error) { return CompareDepth(syntax.EQL, x, y, depth) }
go
func EqualDepth(x, y Value, depth int) (bool, error) { return CompareDepth(syntax.EQL, x, y, depth) }
[ "func", "EqualDepth", "(", "x", ",", "y", "Value", ",", "depth", "int", ")", "(", "bool", ",", "error", ")", "{", "return", "CompareDepth", "(", "syntax", ".", "EQL", ",", "x", ",", "y", ",", "depth", ")", "\n", "}" ]
// EqualDepth reports whether two Skylark values are equal. // // Recursive comparisons by implementations of Value.CompareSameType // should use EqualDepth to prevent infinite recursion.
[ "EqualDepth", "reports", "whether", "two", "Skylark", "values", "are", "equal", ".", "Recursive", "comparisons", "by", "implementations", "of", "Value", ".", "CompareSameType", "should", "use", "EqualDepth", "to", "prevent", "infinite", "recursion", "." ]
a5f7082aabed29c0e429c722292c66ec8ecf9591
https://github.com/google/skylark/blob/a5f7082aabed29c0e429c722292c66ec8ecf9591/value.go#L1056-L1058
6,599
google/skylark
value.go
Compare
func Compare(op syntax.Token, x, y Value) (bool, error) { return CompareDepth(op, x, y, maxdepth) }
go
func Compare(op syntax.Token, x, y Value) (bool, error) { return CompareDepth(op, x, y, maxdepth) }
[ "func", "Compare", "(", "op", "syntax", ".", "Token", ",", "x", ",", "y", "Value", ")", "(", "bool", ",", "error", ")", "{", "return", "CompareDepth", "(", "op", ",", "x", ",", "y", ",", "maxdepth", ")", "\n", "}" ]
// Compare compares two Skylark values. // The comparison operation must be one of EQL, NEQ, LT, LE, GT, or GE. // Compare returns an error if an ordered comparison was // requested for a type that does not support it. // // Recursive comparisons by implementations of Value.CompareSameType // should use CompareDepth to prevent infinite recursion.
[ "Compare", "compares", "two", "Skylark", "values", ".", "The", "comparison", "operation", "must", "be", "one", "of", "EQL", "NEQ", "LT", "LE", "GT", "or", "GE", ".", "Compare", "returns", "an", "error", "if", "an", "ordered", "comparison", "was", "requested", "for", "a", "type", "that", "does", "not", "support", "it", ".", "Recursive", "comparisons", "by", "implementations", "of", "Value", ".", "CompareSameType", "should", "use", "CompareDepth", "to", "prevent", "infinite", "recursion", "." ]
a5f7082aabed29c0e429c722292c66ec8ecf9591
https://github.com/google/skylark/blob/a5f7082aabed29c0e429c722292c66ec8ecf9591/value.go#L1067-L1069