repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
kubernetes-retired/heapster
metrics/sinks/hawkular/client.go
checkCache
func (h *hawkularSink) checkCache(key string, hash uint64) bool { h.regLock.Lock() defer h.regLock.Unlock() _, found := h.expReg[key] if !found || h.expReg[key].hash != hash { return false } // Update the TTL h.expReg[key].ttl = h.runId return true }
go
func (h *hawkularSink) checkCache(key string, hash uint64) bool { h.regLock.Lock() defer h.regLock.Unlock() _, found := h.expReg[key] if !found || h.expReg[key].hash != hash { return false } // Update the TTL h.expReg[key].ttl = h.runId return true }
[ "func", "(", "h", "*", "hawkularSink", ")", "checkCache", "(", "key", "string", ",", "hash", "uint64", ")", "bool", "{", "h", ".", "regLock", ".", "Lock", "(", ")", "\n", "defer", "h", ".", "regLock", ".", "Unlock", "(", ")", "\n", "_", ",", "found", ":=", "h", ".", "expReg", "[", "key", "]", "\n", "if", "!", "found", "||", "h", ".", "expReg", "[", "key", "]", ".", "hash", "!=", "hash", "{", "return", "false", "\n", "}", "\n", "// Update the TTL", "h", ".", "expReg", "[", "key", "]", ".", "ttl", "=", "h", ".", "runId", "\n", "return", "true", "\n", "}" ]
// checkCache returns false if the cached instance is not current. Updates the TTL in the cache
[ "checkCache", "returns", "false", "if", "the", "cached", "instance", "is", "not", "current", ".", "Updates", "the", "TTL", "in", "the", "cache" ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/client.go#L65-L75
train
kubernetes-retired/heapster
metrics/sinks/hawkular/client.go
expireCache
func (h *hawkularSink) expireCache(runId uint64) { h.regLock.Lock() defer h.regLock.Unlock() for k, v := range h.expReg { if (v.ttl + h.cacheAge) <= runId { delete(h.expReg, k) } } }
go
func (h *hawkularSink) expireCache(runId uint64) { h.regLock.Lock() defer h.regLock.Unlock() for k, v := range h.expReg { if (v.ttl + h.cacheAge) <= runId { delete(h.expReg, k) } } }
[ "func", "(", "h", "*", "hawkularSink", ")", "expireCache", "(", "runId", "uint64", ")", "{", "h", ".", "regLock", ".", "Lock", "(", ")", "\n", "defer", "h", ".", "regLock", ".", "Unlock", "(", ")", "\n\n", "for", "k", ",", "v", ":=", "range", "h", ".", "expReg", "{", "if", "(", "v", ".", "ttl", "+", "h", ".", "cacheAge", ")", "<=", "runId", "{", "delete", "(", "h", ".", "expReg", ",", "k", ")", "\n", "}", "\n", "}", "\n", "}" ]
// expireCache will process the map and check for any item that has been expired and release it
[ "expireCache", "will", "process", "the", "map", "and", "check", "for", "any", "item", "that", "has", "been", "expired", "and", "release", "it" ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/client.go#L78-L87
train
kubernetes-retired/heapster
metrics/sinks/hawkular/client.go
updateDefinitions
func (h *hawkularSink) updateDefinitions(mds []*metrics.MetricDefinition) error { for _, p := range mds { if model, f := h.models[p.Tags[descriptorTag]]; f && !h.recent(p, model) { if err := h.client.UpdateTags(p.Type, p.ID, p.Tags, h.modifiers...); err != nil { return err } } h.cache(p) } return nil }
go
func (h *hawkularSink) updateDefinitions(mds []*metrics.MetricDefinition) error { for _, p := range mds { if model, f := h.models[p.Tags[descriptorTag]]; f && !h.recent(p, model) { if err := h.client.UpdateTags(p.Type, p.ID, p.Tags, h.modifiers...); err != nil { return err } } h.cache(p) } return nil }
[ "func", "(", "h", "*", "hawkularSink", ")", "updateDefinitions", "(", "mds", "[", "]", "*", "metrics", ".", "MetricDefinition", ")", "error", "{", "for", "_", ",", "p", ":=", "range", "mds", "{", "if", "model", ",", "f", ":=", "h", ".", "models", "[", "p", ".", "Tags", "[", "descriptorTag", "]", "]", ";", "f", "&&", "!", "h", ".", "recent", "(", "p", ",", "model", ")", "{", "if", "err", ":=", "h", ".", "client", ".", "UpdateTags", "(", "p", ".", "Type", ",", "p", ".", "ID", ",", "p", ".", "Tags", ",", "h", ".", "modifiers", "...", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "h", ".", "cache", "(", "p", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Fetches definitions from the server and checks that they're matching the descriptors
[ "Fetches", "definitions", "from", "the", "server", "and", "checks", "that", "they", "re", "matching", "the", "descriptors" ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/client.go#L90-L101
train
kubernetes-retired/heapster
metrics/sinks/hawkular/client.go
recent
func (h *hawkularSink) recent(live *metrics.MetricDefinition, model *metrics.MetricDefinition) bool { recent := true for k := range model.Tags { if v, found := live.Tags[k]; !found { // There's a label that wasn't in our stored definition live.Tags[k] = v recent = false } } return recent }
go
func (h *hawkularSink) recent(live *metrics.MetricDefinition, model *metrics.MetricDefinition) bool { recent := true for k := range model.Tags { if v, found := live.Tags[k]; !found { // There's a label that wasn't in our stored definition live.Tags[k] = v recent = false } } return recent }
[ "func", "(", "h", "*", "hawkularSink", ")", "recent", "(", "live", "*", "metrics", ".", "MetricDefinition", ",", "model", "*", "metrics", ".", "MetricDefinition", ")", "bool", "{", "recent", ":=", "true", "\n", "for", "k", ":=", "range", "model", ".", "Tags", "{", "if", "v", ",", "found", ":=", "live", ".", "Tags", "[", "k", "]", ";", "!", "found", "{", "// There's a label that wasn't in our stored definition", "live", ".", "Tags", "[", "k", "]", "=", "v", "\n", "recent", "=", "false", "\n", "}", "\n", "}", "\n\n", "return", "recent", "\n", "}" ]
// Checks that stored definition is up to date with the model
[ "Checks", "that", "stored", "definition", "is", "up", "to", "date", "with", "the", "model" ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/client.go#L125-L136
train
kubernetes-retired/heapster
metrics/sinks/hawkular/client.go
descriptorToDefinition
func (h *hawkularSink) descriptorToDefinition(md *core.MetricDescriptor) metrics.MetricDefinition { tags := make(map[string]string) // Postfix description tags with _description for _, l := range md.Labels { if len(l.Description) > 0 { tags[l.Key+descriptionTag] = l.Description } } if len(md.Units.String()) > 0 { tags[unitsTag] = md.Units.String() } tags[descriptorTag] = md.Name hmd := metrics.MetricDefinition{ ID: md.Name, Tags: tags, Type: heapsterTypeToHawkularType(md.Type), } return hmd }
go
func (h *hawkularSink) descriptorToDefinition(md *core.MetricDescriptor) metrics.MetricDefinition { tags := make(map[string]string) // Postfix description tags with _description for _, l := range md.Labels { if len(l.Description) > 0 { tags[l.Key+descriptionTag] = l.Description } } if len(md.Units.String()) > 0 { tags[unitsTag] = md.Units.String() } tags[descriptorTag] = md.Name hmd := metrics.MetricDefinition{ ID: md.Name, Tags: tags, Type: heapsterTypeToHawkularType(md.Type), } return hmd }
[ "func", "(", "h", "*", "hawkularSink", ")", "descriptorToDefinition", "(", "md", "*", "core", ".", "MetricDescriptor", ")", "metrics", ".", "MetricDefinition", "{", "tags", ":=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "// Postfix description tags with _description", "for", "_", ",", "l", ":=", "range", "md", ".", "Labels", "{", "if", "len", "(", "l", ".", "Description", ")", ">", "0", "{", "tags", "[", "l", ".", "Key", "+", "descriptionTag", "]", "=", "l", ".", "Description", "\n", "}", "\n", "}", "\n\n", "if", "len", "(", "md", ".", "Units", ".", "String", "(", ")", ")", ">", "0", "{", "tags", "[", "unitsTag", "]", "=", "md", ".", "Units", ".", "String", "(", ")", "\n", "}", "\n\n", "tags", "[", "descriptorTag", "]", "=", "md", ".", "Name", "\n\n", "hmd", ":=", "metrics", ".", "MetricDefinition", "{", "ID", ":", "md", ".", "Name", ",", "Tags", ":", "tags", ",", "Type", ":", "heapsterTypeToHawkularType", "(", "md", ".", "Type", ")", ",", "}", "\n\n", "return", "hmd", "\n", "}" ]
// Transform the MetricDescriptor to a format used by Hawkular-Metrics
[ "Transform", "the", "MetricDescriptor", "to", "a", "format", "used", "by", "Hawkular", "-", "Metrics" ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/client.go#L139-L161
train
kubernetes-retired/heapster
metrics/sinks/hawkular/client.go
pointToLabeledMetricHeader
func (h *hawkularSink) pointToLabeledMetricHeader(ms *core.MetricSet, metric core.LabeledMetric, timestamp time.Time) (*metrics.MetricHeader, error) { name := h.idName(ms, metric.Name) if resourceID, found := metric.Labels[core.LabelResourceID.Key]; found { name = h.idName(ms, metric.Name+separator+resourceID) } var value float64 if metric.ValueType == core.ValueInt64 { value = float64(metric.IntValue) } else { value = float64(metric.FloatValue) } m := metrics.Datapoint{ Value: value, Timestamp: timestamp, } mh := &metrics.MetricHeader{ ID: name, Data: []metrics.Datapoint{m}, Type: heapsterTypeToHawkularType(metric.MetricType), } return mh, nil }
go
func (h *hawkularSink) pointToLabeledMetricHeader(ms *core.MetricSet, metric core.LabeledMetric, timestamp time.Time) (*metrics.MetricHeader, error) { name := h.idName(ms, metric.Name) if resourceID, found := metric.Labels[core.LabelResourceID.Key]; found { name = h.idName(ms, metric.Name+separator+resourceID) } var value float64 if metric.ValueType == core.ValueInt64 { value = float64(metric.IntValue) } else { value = float64(metric.FloatValue) } m := metrics.Datapoint{ Value: value, Timestamp: timestamp, } mh := &metrics.MetricHeader{ ID: name, Data: []metrics.Datapoint{m}, Type: heapsterTypeToHawkularType(metric.MetricType), } return mh, nil }
[ "func", "(", "h", "*", "hawkularSink", ")", "pointToLabeledMetricHeader", "(", "ms", "*", "core", ".", "MetricSet", ",", "metric", "core", ".", "LabeledMetric", ",", "timestamp", "time", ".", "Time", ")", "(", "*", "metrics", ".", "MetricHeader", ",", "error", ")", "{", "name", ":=", "h", ".", "idName", "(", "ms", ",", "metric", ".", "Name", ")", "\n", "if", "resourceID", ",", "found", ":=", "metric", ".", "Labels", "[", "core", ".", "LabelResourceID", ".", "Key", "]", ";", "found", "{", "name", "=", "h", ".", "idName", "(", "ms", ",", "metric", ".", "Name", "+", "separator", "+", "resourceID", ")", "\n", "}", "\n\n", "var", "value", "float64", "\n", "if", "metric", ".", "ValueType", "==", "core", ".", "ValueInt64", "{", "value", "=", "float64", "(", "metric", ".", "IntValue", ")", "\n", "}", "else", "{", "value", "=", "float64", "(", "metric", ".", "FloatValue", ")", "\n", "}", "\n\n", "m", ":=", "metrics", ".", "Datapoint", "{", "Value", ":", "value", ",", "Timestamp", ":", "timestamp", ",", "}", "\n\n", "mh", ":=", "&", "metrics", ".", "MetricHeader", "{", "ID", ":", "name", ",", "Data", ":", "[", "]", "metrics", ".", "Datapoint", "{", "m", "}", ",", "Type", ":", "heapsterTypeToHawkularType", "(", "metric", ".", "MetricType", ")", ",", "}", "\n\n", "return", "mh", ",", "nil", "\n", "}" ]
// Converts Timeseries to metric structure used by the Hawkular
[ "Converts", "Timeseries", "to", "metric", "structure", "used", "by", "the", "Hawkular" ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/client.go#L356-L382
train
kubernetes-retired/heapster
metrics/sinks/hawkular/client.go
parseFilters
func parseFilters(v []string) ([]Filter, error) { fs := make([]Filter, 0, len(v)) for _, s := range v { p := strings.Index(s, "(") if p < 0 { return nil, fmt.Errorf("Incorrect syntax in filter parameters, missing (") } if strings.Index(s, ")") != len(s)-1 { return nil, fmt.Errorf("Incorrect syntax in filter parameters, missing )") } t := Unknown.From(s[:p]) if t == Unknown { return nil, fmt.Errorf("Unknown filter type") } command := s[p+1 : len(s)-1] switch t { case Label: proto := strings.SplitN(command, ":", 2) if len(proto) < 2 { return nil, fmt.Errorf("Missing : from label filter") } r, err := regexp.Compile(proto[1]) if err != nil { return nil, err } fs = append(fs, labelFilter(proto[0], r)) break case Name: r, err := regexp.Compile(command) if err != nil { return nil, err } fs = append(fs, nameFilter(r)) break } } return fs, nil }
go
func parseFilters(v []string) ([]Filter, error) { fs := make([]Filter, 0, len(v)) for _, s := range v { p := strings.Index(s, "(") if p < 0 { return nil, fmt.Errorf("Incorrect syntax in filter parameters, missing (") } if strings.Index(s, ")") != len(s)-1 { return nil, fmt.Errorf("Incorrect syntax in filter parameters, missing )") } t := Unknown.From(s[:p]) if t == Unknown { return nil, fmt.Errorf("Unknown filter type") } command := s[p+1 : len(s)-1] switch t { case Label: proto := strings.SplitN(command, ":", 2) if len(proto) < 2 { return nil, fmt.Errorf("Missing : from label filter") } r, err := regexp.Compile(proto[1]) if err != nil { return nil, err } fs = append(fs, labelFilter(proto[0], r)) break case Name: r, err := regexp.Compile(command) if err != nil { return nil, err } fs = append(fs, nameFilter(r)) break } } return fs, nil }
[ "func", "parseFilters", "(", "v", "[", "]", "string", ")", "(", "[", "]", "Filter", ",", "error", ")", "{", "fs", ":=", "make", "(", "[", "]", "Filter", ",", "0", ",", "len", "(", "v", ")", ")", "\n", "for", "_", ",", "s", ":=", "range", "v", "{", "p", ":=", "strings", ".", "Index", "(", "s", ",", "\"", "\"", ")", "\n", "if", "p", "<", "0", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "strings", ".", "Index", "(", "s", ",", "\"", "\"", ")", "!=", "len", "(", "s", ")", "-", "1", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "t", ":=", "Unknown", ".", "From", "(", "s", "[", ":", "p", "]", ")", "\n", "if", "t", "==", "Unknown", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "command", ":=", "s", "[", "p", "+", "1", ":", "len", "(", "s", ")", "-", "1", "]", "\n\n", "switch", "t", "{", "case", "Label", ":", "proto", ":=", "strings", ".", "SplitN", "(", "command", ",", "\"", "\"", ",", "2", ")", "\n", "if", "len", "(", "proto", ")", "<", "2", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "r", ",", "err", ":=", "regexp", ".", "Compile", "(", "proto", "[", "1", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "fs", "=", "append", "(", "fs", ",", "labelFilter", "(", "proto", "[", "0", "]", ",", "r", ")", ")", "\n", "break", "\n", "case", "Name", ":", "r", ",", "err", ":=", "regexp", ".", "Compile", "(", "command", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "fs", "=", "append", "(", "fs", ",", "nameFilter", "(", "r", ")", ")", "\n", "break", "\n", "}", "\n", "}", "\n", "return", "fs", ",", "nil", "\n", "}" ]
// If Heapster gets filters, remove these..
[ "If", "Heapster", "gets", "filters", "remove", "these", ".." ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/client.go#L385-L426
train
gdamore/tcell
_demos/mouse.go
main
func main() { encoding.Register() s, e := tcell.NewScreen() if e != nil { fmt.Fprintf(os.Stderr, "%v\n", e) os.Exit(1) } if e := s.Init(); e != nil { fmt.Fprintf(os.Stderr, "%v\n", e) os.Exit(1) } defStyle = tcell.StyleDefault. Background(tcell.ColorBlack). Foreground(tcell.ColorWhite) s.SetStyle(defStyle) s.EnableMouse() s.Clear() posfmt := "Mouse: %d, %d " btnfmt := "Buttons: %s" keyfmt := "Keys: %s" white := tcell.StyleDefault. Foreground(tcell.ColorWhite).Background(tcell.ColorRed) mx, my := -1, -1 ox, oy := -1, -1 bx, by := -1, -1 w, h := s.Size() lchar := '*' bstr := "" lks := "" ecnt := 0 for { drawBox(s, 1, 1, 42, 6, white, ' ') emitStr(s, 2, 2, white, "Press ESC twice to exit, C to clear.") emitStr(s, 2, 3, white, fmt.Sprintf(posfmt, mx, my)) emitStr(s, 2, 4, white, fmt.Sprintf(btnfmt, bstr)) emitStr(s, 2, 5, white, fmt.Sprintf(keyfmt, lks)) s.Show() bstr = "" ev := s.PollEvent() st := tcell.StyleDefault.Background(tcell.ColorRed) up := tcell.StyleDefault. Background(tcell.ColorBlue). Foreground(tcell.ColorBlack) w, h = s.Size() // always clear any old selection box if ox >= 0 && oy >= 0 && bx >= 0 { drawSelect(s, ox, oy, bx, by, false) } switch ev := ev.(type) { case *tcell.EventResize: s.Sync() s.SetContent(w-1, h-1, 'R', nil, st) case *tcell.EventKey: s.SetContent(w-2, h-2, ev.Rune(), nil, st) s.SetContent(w-1, h-1, 'K', nil, st) if ev.Key() == tcell.KeyEscape { ecnt++ if ecnt > 1 { s.Fini() os.Exit(0) } } else if ev.Key() == tcell.KeyCtrlL { s.Sync() } else { ecnt = 0 if ev.Rune() == 'C' || ev.Rune() == 'c' { s.Clear() } } lks = ev.Name() case *tcell.EventMouse: x, y := ev.Position() button := ev.Buttons() for i := uint(0); i < 8; i++ { if int(button)&(1<<i) != 0 { bstr += fmt.Sprintf(" Button%d", i+1) } } if button&tcell.WheelUp != 0 { bstr += " WheelUp" } if button&tcell.WheelDown != 0 { bstr += " WheelDown" } if button&tcell.WheelLeft != 0 { bstr += " WheelLeft" } if button&tcell.WheelRight != 0 { bstr += " WheelRight" } // Only buttons, not wheel events button &= tcell.ButtonMask(0xff) ch := '*' if button != tcell.ButtonNone && ox < 0 { ox, oy = x, y } switch ev.Buttons() { case tcell.ButtonNone: if ox >= 0 { bg := tcell.Color((lchar - '0') * 2) drawBox(s, ox, oy, x, y, up.Background(bg), lchar) ox, oy = -1, -1 bx, by = -1, -1 } case tcell.Button1: ch = '1' case tcell.Button2: ch = '2' case tcell.Button3: ch = '3' case tcell.Button4: ch = '4' case tcell.Button5: ch = '5' case tcell.Button6: ch = '6' case tcell.Button7: ch = '7' case tcell.Button8: ch = '8' default: ch = '*' } if button != tcell.ButtonNone { bx, by = x, y } lchar = ch s.SetContent(w-1, h-1, 'M', nil, st) mx, my = x, y default: s.SetContent(w-1, h-1, 'X', nil, st) } if ox >= 0 && bx >= 0 { drawSelect(s, ox, oy, bx, by, true) } } }
go
func main() { encoding.Register() s, e := tcell.NewScreen() if e != nil { fmt.Fprintf(os.Stderr, "%v\n", e) os.Exit(1) } if e := s.Init(); e != nil { fmt.Fprintf(os.Stderr, "%v\n", e) os.Exit(1) } defStyle = tcell.StyleDefault. Background(tcell.ColorBlack). Foreground(tcell.ColorWhite) s.SetStyle(defStyle) s.EnableMouse() s.Clear() posfmt := "Mouse: %d, %d " btnfmt := "Buttons: %s" keyfmt := "Keys: %s" white := tcell.StyleDefault. Foreground(tcell.ColorWhite).Background(tcell.ColorRed) mx, my := -1, -1 ox, oy := -1, -1 bx, by := -1, -1 w, h := s.Size() lchar := '*' bstr := "" lks := "" ecnt := 0 for { drawBox(s, 1, 1, 42, 6, white, ' ') emitStr(s, 2, 2, white, "Press ESC twice to exit, C to clear.") emitStr(s, 2, 3, white, fmt.Sprintf(posfmt, mx, my)) emitStr(s, 2, 4, white, fmt.Sprintf(btnfmt, bstr)) emitStr(s, 2, 5, white, fmt.Sprintf(keyfmt, lks)) s.Show() bstr = "" ev := s.PollEvent() st := tcell.StyleDefault.Background(tcell.ColorRed) up := tcell.StyleDefault. Background(tcell.ColorBlue). Foreground(tcell.ColorBlack) w, h = s.Size() // always clear any old selection box if ox >= 0 && oy >= 0 && bx >= 0 { drawSelect(s, ox, oy, bx, by, false) } switch ev := ev.(type) { case *tcell.EventResize: s.Sync() s.SetContent(w-1, h-1, 'R', nil, st) case *tcell.EventKey: s.SetContent(w-2, h-2, ev.Rune(), nil, st) s.SetContent(w-1, h-1, 'K', nil, st) if ev.Key() == tcell.KeyEscape { ecnt++ if ecnt > 1 { s.Fini() os.Exit(0) } } else if ev.Key() == tcell.KeyCtrlL { s.Sync() } else { ecnt = 0 if ev.Rune() == 'C' || ev.Rune() == 'c' { s.Clear() } } lks = ev.Name() case *tcell.EventMouse: x, y := ev.Position() button := ev.Buttons() for i := uint(0); i < 8; i++ { if int(button)&(1<<i) != 0 { bstr += fmt.Sprintf(" Button%d", i+1) } } if button&tcell.WheelUp != 0 { bstr += " WheelUp" } if button&tcell.WheelDown != 0 { bstr += " WheelDown" } if button&tcell.WheelLeft != 0 { bstr += " WheelLeft" } if button&tcell.WheelRight != 0 { bstr += " WheelRight" } // Only buttons, not wheel events button &= tcell.ButtonMask(0xff) ch := '*' if button != tcell.ButtonNone && ox < 0 { ox, oy = x, y } switch ev.Buttons() { case tcell.ButtonNone: if ox >= 0 { bg := tcell.Color((lchar - '0') * 2) drawBox(s, ox, oy, x, y, up.Background(bg), lchar) ox, oy = -1, -1 bx, by = -1, -1 } case tcell.Button1: ch = '1' case tcell.Button2: ch = '2' case tcell.Button3: ch = '3' case tcell.Button4: ch = '4' case tcell.Button5: ch = '5' case tcell.Button6: ch = '6' case tcell.Button7: ch = '7' case tcell.Button8: ch = '8' default: ch = '*' } if button != tcell.ButtonNone { bx, by = x, y } lchar = ch s.SetContent(w-1, h-1, 'M', nil, st) mx, my = x, y default: s.SetContent(w-1, h-1, 'X', nil, st) } if ox >= 0 && bx >= 0 { drawSelect(s, ox, oy, bx, by, true) } } }
[ "func", "main", "(", ")", "{", "encoding", ".", "Register", "(", ")", "\n\n", "s", ",", "e", ":=", "tcell", ".", "NewScreen", "(", ")", "\n", "if", "e", "!=", "nil", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"", "\\n", "\"", ",", "e", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}", "\n", "if", "e", ":=", "s", ".", "Init", "(", ")", ";", "e", "!=", "nil", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"", "\\n", "\"", ",", "e", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}", "\n", "defStyle", "=", "tcell", ".", "StyleDefault", ".", "Background", "(", "tcell", ".", "ColorBlack", ")", ".", "Foreground", "(", "tcell", ".", "ColorWhite", ")", "\n", "s", ".", "SetStyle", "(", "defStyle", ")", "\n", "s", ".", "EnableMouse", "(", ")", "\n", "s", ".", "Clear", "(", ")", "\n\n", "posfmt", ":=", "\"", "\"", "\n", "btnfmt", ":=", "\"", "\"", "\n", "keyfmt", ":=", "\"", "\"", "\n", "white", ":=", "tcell", ".", "StyleDefault", ".", "Foreground", "(", "tcell", ".", "ColorWhite", ")", ".", "Background", "(", "tcell", ".", "ColorRed", ")", "\n\n", "mx", ",", "my", ":=", "-", "1", ",", "-", "1", "\n", "ox", ",", "oy", ":=", "-", "1", ",", "-", "1", "\n", "bx", ",", "by", ":=", "-", "1", ",", "-", "1", "\n", "w", ",", "h", ":=", "s", ".", "Size", "(", ")", "\n", "lchar", ":=", "'*'", "\n", "bstr", ":=", "\"", "\"", "\n", "lks", ":=", "\"", "\"", "\n", "ecnt", ":=", "0", "\n\n", "for", "{", "drawBox", "(", "s", ",", "1", ",", "1", ",", "42", ",", "6", ",", "white", ",", "' '", ")", "\n", "emitStr", "(", "s", ",", "2", ",", "2", ",", "white", ",", "\"", "\"", ")", "\n", "emitStr", "(", "s", ",", "2", ",", "3", ",", "white", ",", "fmt", ".", "Sprintf", "(", "posfmt", ",", "mx", ",", "my", ")", ")", "\n", "emitStr", "(", "s", ",", "2", ",", "4", ",", "white", ",", "fmt", ".", "Sprintf", "(", "btnfmt", ",", "bstr", ")", ")", "\n", "emitStr", "(", "s", ",", "2", ",", "5", ",", "white", ",", "fmt", ".", "Sprintf", "(", "keyfmt", ",", "lks", ")", ")", "\n\n", "s", ".", "Show", "(", ")", "\n", "bstr", "=", "\"", "\"", "\n", "ev", ":=", "s", ".", "PollEvent", "(", ")", "\n", "st", ":=", "tcell", ".", "StyleDefault", ".", "Background", "(", "tcell", ".", "ColorRed", ")", "\n", "up", ":=", "tcell", ".", "StyleDefault", ".", "Background", "(", "tcell", ".", "ColorBlue", ")", ".", "Foreground", "(", "tcell", ".", "ColorBlack", ")", "\n", "w", ",", "h", "=", "s", ".", "Size", "(", ")", "\n\n", "// always clear any old selection box", "if", "ox", ">=", "0", "&&", "oy", ">=", "0", "&&", "bx", ">=", "0", "{", "drawSelect", "(", "s", ",", "ox", ",", "oy", ",", "bx", ",", "by", ",", "false", ")", "\n", "}", "\n\n", "switch", "ev", ":=", "ev", ".", "(", "type", ")", "{", "case", "*", "tcell", ".", "EventResize", ":", "s", ".", "Sync", "(", ")", "\n", "s", ".", "SetContent", "(", "w", "-", "1", ",", "h", "-", "1", ",", "'R'", ",", "nil", ",", "st", ")", "\n", "case", "*", "tcell", ".", "EventKey", ":", "s", ".", "SetContent", "(", "w", "-", "2", ",", "h", "-", "2", ",", "ev", ".", "Rune", "(", ")", ",", "nil", ",", "st", ")", "\n", "s", ".", "SetContent", "(", "w", "-", "1", ",", "h", "-", "1", ",", "'K'", ",", "nil", ",", "st", ")", "\n", "if", "ev", ".", "Key", "(", ")", "==", "tcell", ".", "KeyEscape", "{", "ecnt", "++", "\n", "if", "ecnt", ">", "1", "{", "s", ".", "Fini", "(", ")", "\n", "os", ".", "Exit", "(", "0", ")", "\n", "}", "\n", "}", "else", "if", "ev", ".", "Key", "(", ")", "==", "tcell", ".", "KeyCtrlL", "{", "s", ".", "Sync", "(", ")", "\n", "}", "else", "{", "ecnt", "=", "0", "\n", "if", "ev", ".", "Rune", "(", ")", "==", "'C'", "||", "ev", ".", "Rune", "(", ")", "==", "'c'", "{", "s", ".", "Clear", "(", ")", "\n", "}", "\n", "}", "\n", "lks", "=", "ev", ".", "Name", "(", ")", "\n", "case", "*", "tcell", ".", "EventMouse", ":", "x", ",", "y", ":=", "ev", ".", "Position", "(", ")", "\n", "button", ":=", "ev", ".", "Buttons", "(", ")", "\n", "for", "i", ":=", "uint", "(", "0", ")", ";", "i", "<", "8", ";", "i", "++", "{", "if", "int", "(", "button", ")", "&", "(", "1", "<<", "i", ")", "!=", "0", "{", "bstr", "+=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "i", "+", "1", ")", "\n", "}", "\n", "}", "\n", "if", "button", "&", "tcell", ".", "WheelUp", "!=", "0", "{", "bstr", "+=", "\"", "\"", "\n", "}", "\n", "if", "button", "&", "tcell", ".", "WheelDown", "!=", "0", "{", "bstr", "+=", "\"", "\"", "\n", "}", "\n", "if", "button", "&", "tcell", ".", "WheelLeft", "!=", "0", "{", "bstr", "+=", "\"", "\"", "\n", "}", "\n", "if", "button", "&", "tcell", ".", "WheelRight", "!=", "0", "{", "bstr", "+=", "\"", "\"", "\n", "}", "\n", "// Only buttons, not wheel events", "button", "&=", "tcell", ".", "ButtonMask", "(", "0xff", ")", "\n", "ch", ":=", "'*'", "\n\n", "if", "button", "!=", "tcell", ".", "ButtonNone", "&&", "ox", "<", "0", "{", "ox", ",", "oy", "=", "x", ",", "y", "\n", "}", "\n", "switch", "ev", ".", "Buttons", "(", ")", "{", "case", "tcell", ".", "ButtonNone", ":", "if", "ox", ">=", "0", "{", "bg", ":=", "tcell", ".", "Color", "(", "(", "lchar", "-", "'0'", ")", "*", "2", ")", "\n", "drawBox", "(", "s", ",", "ox", ",", "oy", ",", "x", ",", "y", ",", "up", ".", "Background", "(", "bg", ")", ",", "lchar", ")", "\n", "ox", ",", "oy", "=", "-", "1", ",", "-", "1", "\n", "bx", ",", "by", "=", "-", "1", ",", "-", "1", "\n", "}", "\n", "case", "tcell", ".", "Button1", ":", "ch", "=", "'1'", "\n", "case", "tcell", ".", "Button2", ":", "ch", "=", "'2'", "\n", "case", "tcell", ".", "Button3", ":", "ch", "=", "'3'", "\n", "case", "tcell", ".", "Button4", ":", "ch", "=", "'4'", "\n", "case", "tcell", ".", "Button5", ":", "ch", "=", "'5'", "\n", "case", "tcell", ".", "Button6", ":", "ch", "=", "'6'", "\n", "case", "tcell", ".", "Button7", ":", "ch", "=", "'7'", "\n", "case", "tcell", ".", "Button8", ":", "ch", "=", "'8'", "\n", "default", ":", "ch", "=", "'*'", "\n\n", "}", "\n", "if", "button", "!=", "tcell", ".", "ButtonNone", "{", "bx", ",", "by", "=", "x", ",", "y", "\n", "}", "\n", "lchar", "=", "ch", "\n", "s", ".", "SetContent", "(", "w", "-", "1", ",", "h", "-", "1", ",", "'M'", ",", "nil", ",", "st", ")", "\n", "mx", ",", "my", "=", "x", ",", "y", "\n", "default", ":", "s", ".", "SetContent", "(", "w", "-", "1", ",", "h", "-", "1", ",", "'X'", ",", "nil", ",", "st", ")", "\n", "}", "\n\n", "if", "ox", ">=", "0", "&&", "bx", ">=", "0", "{", "drawSelect", "(", "s", ",", "ox", ",", "oy", ",", "bx", ",", "by", ",", "true", ")", "\n", "}", "\n", "}", "\n", "}" ]
// This program just shows simple mouse and keyboard events. Press ESC twice to // exit.
[ "This", "program", "just", "shows", "simple", "mouse", "and", "keyboard", "events", ".", "Press", "ESC", "twice", "to", "exit", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/_demos/mouse.go#L101-L250
train
gdamore/tcell
views/view.go
Fill
func (v *ViewPort) Fill(ch rune, style tcell.Style) { if v.v != nil { for y := 0; y < v.height; y++ { for x := 0; x < v.width; x++ { v.v.SetContent(x+v.physx, y+v.physy, ch, nil, style) } } } }
go
func (v *ViewPort) Fill(ch rune, style tcell.Style) { if v.v != nil { for y := 0; y < v.height; y++ { for x := 0; x < v.width; x++ { v.v.SetContent(x+v.physx, y+v.physy, ch, nil, style) } } } }
[ "func", "(", "v", "*", "ViewPort", ")", "Fill", "(", "ch", "rune", ",", "style", "tcell", ".", "Style", ")", "{", "if", "v", ".", "v", "!=", "nil", "{", "for", "y", ":=", "0", ";", "y", "<", "v", ".", "height", ";", "y", "++", "{", "for", "x", ":=", "0", ";", "x", "<", "v", ".", "width", ";", "x", "++", "{", "v", ".", "v", ".", "SetContent", "(", "x", "+", "v", ".", "physx", ",", "y", "+", "v", ".", "physy", ",", "ch", ",", "nil", ",", "style", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// Fill fills the displayed view port with the given character and style.
[ "Fill", "fills", "the", "displayed", "view", "port", "with", "the", "given", "character", "and", "style", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L73-L81
train
gdamore/tcell
views/view.go
Reset
func (v *ViewPort) Reset() { v.limx = 0 v.limy = 0 v.viewx = 0 v.viewy = 0 }
go
func (v *ViewPort) Reset() { v.limx = 0 v.limy = 0 v.viewx = 0 v.viewy = 0 }
[ "func", "(", "v", "*", "ViewPort", ")", "Reset", "(", ")", "{", "v", ".", "limx", "=", "0", "\n", "v", ".", "limy", "=", "0", "\n", "v", ".", "viewx", "=", "0", "\n", "v", ".", "viewy", "=", "0", "\n", "}" ]
// Reset resets the record of content, and also resets the offset back // to the origin. It doesn't alter the dimensions of the view port, nor // the physical location relative to its parent.
[ "Reset", "resets", "the", "record", "of", "content", "and", "also", "resets", "the", "offset", "back", "to", "the", "origin", ".", "It", "doesn", "t", "alter", "the", "dimensions", "of", "the", "view", "port", "nor", "the", "physical", "location", "relative", "to", "its", "parent", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L91-L96
train
gdamore/tcell
views/view.go
MakeVisible
func (v *ViewPort) MakeVisible(x, y int) { if x < v.limx && x >= v.viewx+v.width { v.viewx = x - (v.width - 1) } if x >= 0 && x < v.viewx { v.viewx = x } if y < v.limy && y >= v.viewy+v.height { v.viewy = y - (v.height - 1) } if y >= 0 && y < v.viewy { v.viewy = y } v.ValidateView() }
go
func (v *ViewPort) MakeVisible(x, y int) { if x < v.limx && x >= v.viewx+v.width { v.viewx = x - (v.width - 1) } if x >= 0 && x < v.viewx { v.viewx = x } if y < v.limy && y >= v.viewy+v.height { v.viewy = y - (v.height - 1) } if y >= 0 && y < v.viewy { v.viewy = y } v.ValidateView() }
[ "func", "(", "v", "*", "ViewPort", ")", "MakeVisible", "(", "x", ",", "y", "int", ")", "{", "if", "x", "<", "v", ".", "limx", "&&", "x", ">=", "v", ".", "viewx", "+", "v", ".", "width", "{", "v", ".", "viewx", "=", "x", "-", "(", "v", ".", "width", "-", "1", ")", "\n", "}", "\n", "if", "x", ">=", "0", "&&", "x", "<", "v", ".", "viewx", "{", "v", ".", "viewx", "=", "x", "\n", "}", "\n", "if", "y", "<", "v", ".", "limy", "&&", "y", ">=", "v", ".", "viewy", "+", "v", ".", "height", "{", "v", ".", "viewy", "=", "y", "-", "(", "v", ".", "height", "-", "1", ")", "\n", "}", "\n", "if", "y", ">=", "0", "&&", "y", "<", "v", ".", "viewy", "{", "v", ".", "viewy", "=", "y", "\n", "}", "\n", "v", ".", "ValidateView", "(", ")", "\n", "}" ]
// MakeVisible moves the ViewPort the minimum necessary to make the given // point visible. This should be called before any content is changed with // SetContent, since otherwise it may be possible to move the location onto // a region whose contents have been discarded.
[ "MakeVisible", "moves", "the", "ViewPort", "the", "minimum", "necessary", "to", "make", "the", "given", "point", "visible", ".", "This", "should", "be", "called", "before", "any", "content", "is", "changed", "with", "SetContent", "since", "otherwise", "it", "may", "be", "possible", "to", "move", "the", "location", "onto", "a", "region", "whose", "contents", "have", "been", "discarded", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L130-L144
train
gdamore/tcell
views/view.go
ValidateViewY
func (v *ViewPort) ValidateViewY() { if v.viewy >= v.limy-v.height { v.viewy = (v.limy - v.height) } if v.viewy < 0 { v.viewy = 0 } }
go
func (v *ViewPort) ValidateViewY() { if v.viewy >= v.limy-v.height { v.viewy = (v.limy - v.height) } if v.viewy < 0 { v.viewy = 0 } }
[ "func", "(", "v", "*", "ViewPort", ")", "ValidateViewY", "(", ")", "{", "if", "v", ".", "viewy", ">=", "v", ".", "limy", "-", "v", ".", "height", "{", "v", ".", "viewy", "=", "(", "v", ".", "limy", "-", "v", ".", "height", ")", "\n", "}", "\n", "if", "v", ".", "viewy", "<", "0", "{", "v", ".", "viewy", "=", "0", "\n", "}", "\n", "}" ]
// ValidateViewY ensures that the Y offset of the view port is limited so that // it cannot scroll away from the content.
[ "ValidateViewY", "ensures", "that", "the", "Y", "offset", "of", "the", "view", "port", "is", "limited", "so", "that", "it", "cannot", "scroll", "away", "from", "the", "content", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L148-L155
train
gdamore/tcell
views/view.go
ValidateViewX
func (v *ViewPort) ValidateViewX() { if v.viewx >= v.limx-v.width { v.viewx = (v.limx - v.width) } if v.viewx < 0 { v.viewx = 0 } }
go
func (v *ViewPort) ValidateViewX() { if v.viewx >= v.limx-v.width { v.viewx = (v.limx - v.width) } if v.viewx < 0 { v.viewx = 0 } }
[ "func", "(", "v", "*", "ViewPort", ")", "ValidateViewX", "(", ")", "{", "if", "v", ".", "viewx", ">=", "v", ".", "limx", "-", "v", ".", "width", "{", "v", ".", "viewx", "=", "(", "v", ".", "limx", "-", "v", ".", "width", ")", "\n", "}", "\n", "if", "v", ".", "viewx", "<", "0", "{", "v", ".", "viewx", "=", "0", "\n", "}", "\n", "}" ]
// ValidateViewX ensures that the X offset of the view port is limited so that // it cannot scroll away from the content.
[ "ValidateViewX", "ensures", "that", "the", "X", "offset", "of", "the", "view", "port", "is", "limited", "so", "that", "it", "cannot", "scroll", "away", "from", "the", "content", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L159-L166
train
gdamore/tcell
views/view.go
Center
func (v *ViewPort) Center(x, y int) { if x < 0 || y < 0 || x >= v.limx || y >= v.limy || v.v == nil { return } v.viewx = x - (v.width / 2) v.viewy = y - (v.height / 2) v.ValidateView() }
go
func (v *ViewPort) Center(x, y int) { if x < 0 || y < 0 || x >= v.limx || y >= v.limy || v.v == nil { return } v.viewx = x - (v.width / 2) v.viewy = y - (v.height / 2) v.ValidateView() }
[ "func", "(", "v", "*", "ViewPort", ")", "Center", "(", "x", ",", "y", "int", ")", "{", "if", "x", "<", "0", "||", "y", "<", "0", "||", "x", ">=", "v", ".", "limx", "||", "y", ">=", "v", ".", "limy", "||", "v", ".", "v", "==", "nil", "{", "return", "\n", "}", "\n", "v", ".", "viewx", "=", "x", "-", "(", "v", ".", "width", "/", "2", ")", "\n", "v", ".", "viewy", "=", "y", "-", "(", "v", ".", "height", "/", "2", ")", "\n", "v", ".", "ValidateView", "(", ")", "\n", "}" ]
// Center centers the point, if possible, in the View.
[ "Center", "centers", "the", "point", "if", "possible", "in", "the", "View", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L176-L183
train
gdamore/tcell
views/view.go
ScrollUp
func (v *ViewPort) ScrollUp(rows int) { v.viewy -= rows v.ValidateViewY() }
go
func (v *ViewPort) ScrollUp(rows int) { v.viewy -= rows v.ValidateViewY() }
[ "func", "(", "v", "*", "ViewPort", ")", "ScrollUp", "(", "rows", "int", ")", "{", "v", ".", "viewy", "-=", "rows", "\n", "v", ".", "ValidateViewY", "(", ")", "\n", "}" ]
// ScrollUp moves the view up, showing lower numbered rows of content.
[ "ScrollUp", "moves", "the", "view", "up", "showing", "lower", "numbered", "rows", "of", "content", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L186-L189
train
gdamore/tcell
views/view.go
ScrollDown
func (v *ViewPort) ScrollDown(rows int) { v.viewy += rows v.ValidateViewY() }
go
func (v *ViewPort) ScrollDown(rows int) { v.viewy += rows v.ValidateViewY() }
[ "func", "(", "v", "*", "ViewPort", ")", "ScrollDown", "(", "rows", "int", ")", "{", "v", ".", "viewy", "+=", "rows", "\n", "v", ".", "ValidateViewY", "(", ")", "\n", "}" ]
// ScrollDown moves the view down, showingh higher numbered rows of content.
[ "ScrollDown", "moves", "the", "view", "down", "showingh", "higher", "numbered", "rows", "of", "content", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L192-L195
train
gdamore/tcell
views/view.go
ScrollLeft
func (v *ViewPort) ScrollLeft(cols int) { v.viewx -= cols v.ValidateViewX() }
go
func (v *ViewPort) ScrollLeft(cols int) { v.viewx -= cols v.ValidateViewX() }
[ "func", "(", "v", "*", "ViewPort", ")", "ScrollLeft", "(", "cols", "int", ")", "{", "v", ".", "viewx", "-=", "cols", "\n", "v", ".", "ValidateViewX", "(", ")", "\n", "}" ]
// ScrollLeft moves the view to the left.
[ "ScrollLeft", "moves", "the", "view", "to", "the", "left", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L198-L201
train
gdamore/tcell
views/view.go
ScrollRight
func (v *ViewPort) ScrollRight(cols int) { v.viewx += cols v.ValidateViewX() }
go
func (v *ViewPort) ScrollRight(cols int) { v.viewx += cols v.ValidateViewX() }
[ "func", "(", "v", "*", "ViewPort", ")", "ScrollRight", "(", "cols", "int", ")", "{", "v", ".", "viewx", "+=", "cols", "\n", "v", ".", "ValidateViewX", "(", ")", "\n", "}" ]
// ScrollRight moves the view to the left.
[ "ScrollRight", "moves", "the", "view", "to", "the", "left", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L204-L207
train
gdamore/tcell
views/view.go
SetSize
func (v *ViewPort) SetSize(width, height int) { v.height = height v.width = width v.ValidateView() }
go
func (v *ViewPort) SetSize(width, height int) { v.height = height v.width = width v.ValidateView() }
[ "func", "(", "v", "*", "ViewPort", ")", "SetSize", "(", "width", ",", "height", "int", ")", "{", "v", ".", "height", "=", "height", "\n", "v", ".", "width", "=", "width", "\n", "v", ".", "ValidateView", "(", ")", "\n", "}" ]
// SetSize is used to set the visible size of the view. Enclosing views or // layout managers can use this to inform the View of its correct visible size.
[ "SetSize", "is", "used", "to", "set", "the", "visible", "size", "of", "the", "view", ".", "Enclosing", "views", "or", "layout", "managers", "can", "use", "this", "to", "inform", "the", "View", "of", "its", "correct", "visible", "size", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L211-L215
train
gdamore/tcell
views/view.go
GetVisible
func (v *ViewPort) GetVisible() (int, int, int, int) { return v.viewx, v.viewy, v.viewx + v.width - 1, v.viewy + v.height - 1 }
go
func (v *ViewPort) GetVisible() (int, int, int, int) { return v.viewx, v.viewy, v.viewx + v.width - 1, v.viewy + v.height - 1 }
[ "func", "(", "v", "*", "ViewPort", ")", "GetVisible", "(", ")", "(", "int", ",", "int", ",", "int", ",", "int", ")", "{", "return", "v", ".", "viewx", ",", "v", ".", "viewy", ",", "v", ".", "viewx", "+", "v", ".", "width", "-", "1", ",", "v", ".", "viewy", "+", "v", ".", "height", "-", "1", "\n", "}" ]
// GetVisible returns the upper left and lower right coordinates of the visible // content. That is, it will return x1, y1, x2, y2 where the upper left cell // is position x1, y1, and the lower right is x2, y2. These coordinates are // in the space of the content, that is the content area uses coordinate 0,0 // as its first cell position.
[ "GetVisible", "returns", "the", "upper", "left", "and", "lower", "right", "coordinates", "of", "the", "visible", "content", ".", "That", "is", "it", "will", "return", "x1", "y1", "x2", "y2", "where", "the", "upper", "left", "cell", "is", "position", "x1", "y1", "and", "the", "lower", "right", "is", "x2", "y2", ".", "These", "coordinates", "are", "in", "the", "space", "of", "the", "content", "that", "is", "the", "content", "area", "uses", "coordinate", "0", "0", "as", "its", "first", "cell", "position", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L222-L224
train
gdamore/tcell
views/view.go
GetPhysical
func (v *ViewPort) GetPhysical() (int, int, int, int) { return v.physx, v.physy, v.physx + v.width - 1, v.physy + v.height - 1 }
go
func (v *ViewPort) GetPhysical() (int, int, int, int) { return v.physx, v.physy, v.physx + v.width - 1, v.physy + v.height - 1 }
[ "func", "(", "v", "*", "ViewPort", ")", "GetPhysical", "(", ")", "(", "int", ",", "int", ",", "int", ",", "int", ")", "{", "return", "v", ".", "physx", ",", "v", ".", "physy", ",", "v", ".", "physx", "+", "v", ".", "width", "-", "1", ",", "v", ".", "physy", "+", "v", ".", "height", "-", "1", "\n", "}" ]
// GetPhysical returns the upper left and lower right coordinates of the visible // content in the coordinate space of the parent. This is may be the physical // coordinates of the screen, if the screen is the view's parent.
[ "GetPhysical", "returns", "the", "upper", "left", "and", "lower", "right", "coordinates", "of", "the", "visible", "content", "in", "the", "coordinate", "space", "of", "the", "parent", ".", "This", "is", "may", "be", "the", "physical", "coordinates", "of", "the", "screen", "if", "the", "screen", "is", "the", "view", "s", "parent", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L229-L231
train
gdamore/tcell
views/view.go
Resize
func (v *ViewPort) Resize(x, y, width, height int) { if v.v == nil { return } px, py := v.v.Size() if x >= 0 && x < px { v.physx = x } if y >= 0 && y < py { v.physy = y } if width < 0 { width = px - x } if height < 0 { height = py - y } if width <= x+px { v.width = width } if height <= y+py { v.height = height } }
go
func (v *ViewPort) Resize(x, y, width, height int) { if v.v == nil { return } px, py := v.v.Size() if x >= 0 && x < px { v.physx = x } if y >= 0 && y < py { v.physy = y } if width < 0 { width = px - x } if height < 0 { height = py - y } if width <= x+px { v.width = width } if height <= y+py { v.height = height } }
[ "func", "(", "v", "*", "ViewPort", ")", "Resize", "(", "x", ",", "y", ",", "width", ",", "height", "int", ")", "{", "if", "v", ".", "v", "==", "nil", "{", "return", "\n", "}", "\n", "px", ",", "py", ":=", "v", ".", "v", ".", "Size", "(", ")", "\n", "if", "x", ">=", "0", "&&", "x", "<", "px", "{", "v", ".", "physx", "=", "x", "\n", "}", "\n", "if", "y", ">=", "0", "&&", "y", "<", "py", "{", "v", ".", "physy", "=", "y", "\n", "}", "\n", "if", "width", "<", "0", "{", "width", "=", "px", "-", "x", "\n", "}", "\n", "if", "height", "<", "0", "{", "height", "=", "py", "-", "y", "\n", "}", "\n", "if", "width", "<=", "x", "+", "px", "{", "v", ".", "width", "=", "width", "\n", "}", "\n", "if", "height", "<=", "y", "+", "py", "{", "v", ".", "height", "=", "height", "\n", "}", "\n", "}" ]
// Resize is called by the enclosing view to change the size of the ViewPort, // usually in response to a window resize event. The x, y refer are the // ViewPort's location relative to the parent View. A negative value for either // width or height will cause the ViewPort to expand to fill to the end of parent // View in the relevant dimension.
[ "Resize", "is", "called", "by", "the", "enclosing", "view", "to", "change", "the", "size", "of", "the", "ViewPort", "usually", "in", "response", "to", "a", "window", "resize", "event", ".", "The", "x", "y", "refer", "are", "the", "ViewPort", "s", "location", "relative", "to", "the", "parent", "View", ".", "A", "negative", "value", "for", "either", "width", "or", "height", "will", "cause", "the", "ViewPort", "to", "expand", "to", "fill", "to", "the", "end", "of", "parent", "View", "in", "the", "relevant", "dimension", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L257-L280
train
gdamore/tcell
views/textbar.go
SetCenter
func (t *TextBar) SetCenter(s string, style tcell.Style) { t.initialize() if style == tcell.StyleDefault { style = t.style } t.center.SetText(s) t.center.SetStyle(style) }
go
func (t *TextBar) SetCenter(s string, style tcell.Style) { t.initialize() if style == tcell.StyleDefault { style = t.style } t.center.SetText(s) t.center.SetStyle(style) }
[ "func", "(", "t", "*", "TextBar", ")", "SetCenter", "(", "s", "string", ",", "style", "tcell", ".", "Style", ")", "{", "t", ".", "initialize", "(", ")", "\n", "if", "style", "==", "tcell", ".", "StyleDefault", "{", "style", "=", "t", ".", "style", "\n", "}", "\n", "t", ".", "center", ".", "SetText", "(", "s", ")", "\n", "t", ".", "center", ".", "SetStyle", "(", "style", ")", "\n", "}" ]
// SetCenter sets the center text for the textbar. The text is // always center aligned.
[ "SetCenter", "sets", "the", "center", "text", "for", "the", "textbar", ".", "The", "text", "is", "always", "center", "aligned", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textbar.go#L44-L51
train
gdamore/tcell
views/textbar.go
SetStyle
func (t *TextBar) SetStyle(style tcell.Style) { t.initialize() t.style = style }
go
func (t *TextBar) SetStyle(style tcell.Style) { t.initialize() t.style = style }
[ "func", "(", "t", "*", "TextBar", ")", "SetStyle", "(", "style", "tcell", ".", "Style", ")", "{", "t", ".", "initialize", "(", ")", "\n", "t", ".", "style", "=", "style", "\n", "}" ]
// SetStyle is used to set a default style to use for the textbar, including // areas where no text is present. Note that this will not change the text // already displayed, so call this before changing or setting text.
[ "SetStyle", "is", "used", "to", "set", "a", "default", "style", "to", "use", "for", "the", "textbar", "including", "areas", "where", "no", "text", "is", "present", ".", "Note", "that", "this", "will", "not", "change", "the", "text", "already", "displayed", "so", "call", "this", "before", "changing", "or", "setting", "text", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textbar.go#L76-L79
train
gdamore/tcell
views/textbar.go
SetView
func (t *TextBar) SetView(view View) { t.initialize() t.view = view t.lview.SetView(view) t.rview.SetView(view) t.cview.SetView(view) t.changed = true }
go
func (t *TextBar) SetView(view View) { t.initialize() t.view = view t.lview.SetView(view) t.rview.SetView(view) t.cview.SetView(view) t.changed = true }
[ "func", "(", "t", "*", "TextBar", ")", "SetView", "(", "view", "View", ")", "{", "t", ".", "initialize", "(", ")", "\n", "t", ".", "view", "=", "view", "\n", "t", ".", "lview", ".", "SetView", "(", "view", ")", "\n", "t", ".", "rview", ".", "SetView", "(", "view", ")", "\n", "t", ".", "cview", ".", "SetView", "(", "view", ")", "\n", "t", ".", "changed", "=", "true", "\n", "}" ]
// SetView sets the View drawing context for this TextBar.
[ "SetView", "sets", "the", "View", "drawing", "context", "for", "this", "TextBar", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textbar.go#L110-L117
train
gdamore/tcell
views/textbar.go
Draw
func (t *TextBar) Draw() { t.initialize() if t.changed { t.layout() } w, h := t.view.Size() for y := 0; y < h; y++ { for x := 0; x < w; x++ { t.view.SetContent(x, y, ' ', nil, t.style) } } // Draw in reverse order -- if we clip, we will clip at the // right side. t.right.Draw() t.center.Draw() t.left.Draw() }
go
func (t *TextBar) Draw() { t.initialize() if t.changed { t.layout() } w, h := t.view.Size() for y := 0; y < h; y++ { for x := 0; x < w; x++ { t.view.SetContent(x, y, ' ', nil, t.style) } } // Draw in reverse order -- if we clip, we will clip at the // right side. t.right.Draw() t.center.Draw() t.left.Draw() }
[ "func", "(", "t", "*", "TextBar", ")", "Draw", "(", ")", "{", "t", ".", "initialize", "(", ")", "\n", "if", "t", ".", "changed", "{", "t", ".", "layout", "(", ")", "\n", "}", "\n", "w", ",", "h", ":=", "t", ".", "view", ".", "Size", "(", ")", "\n", "for", "y", ":=", "0", ";", "y", "<", "h", ";", "y", "++", "{", "for", "x", ":=", "0", ";", "x", "<", "w", ";", "x", "++", "{", "t", ".", "view", ".", "SetContent", "(", "x", ",", "y", ",", "' '", ",", "nil", ",", "t", ".", "style", ")", "\n", "}", "\n", "}", "\n\n", "// Draw in reverse order -- if we clip, we will clip at the", "// right side.", "t", ".", "right", ".", "Draw", "(", ")", "\n", "t", ".", "center", ".", "Draw", "(", ")", "\n", "t", ".", "left", ".", "Draw", "(", ")", "\n", "}" ]
// Draw draws the TextBar into its View context.
[ "Draw", "draws", "the", "TextBar", "into", "its", "View", "context", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textbar.go#L120-L138
train
gdamore/tcell
views/textbar.go
Resize
func (t *TextBar) Resize() { t.initialize() t.layout() t.left.Resize() t.center.Resize() t.right.Resize() t.PostEventWidgetResize(t) }
go
func (t *TextBar) Resize() { t.initialize() t.layout() t.left.Resize() t.center.Resize() t.right.Resize() t.PostEventWidgetResize(t) }
[ "func", "(", "t", "*", "TextBar", ")", "Resize", "(", ")", "{", "t", ".", "initialize", "(", ")", "\n", "t", ".", "layout", "(", ")", "\n\n", "t", ".", "left", ".", "Resize", "(", ")", "\n", "t", ".", "center", ".", "Resize", "(", ")", "\n", "t", ".", "right", ".", "Resize", "(", ")", "\n\n", "t", ".", "PostEventWidgetResize", "(", "t", ")", "\n", "}" ]
// Resize is called when the TextBar's View changes size, and // updates the layout.
[ "Resize", "is", "called", "when", "the", "TextBar", "s", "View", "changes", "size", "and", "updates", "the", "layout", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textbar.go#L142-L151
train
gdamore/tcell
views/textbar.go
Size
func (t *TextBar) Size() (int, int) { w, h := 0, 0 ww, wh := t.left.Size() w += ww if wh > h { h = wh } ww, wh = t.center.Size() w += ww if wh > h { h = wh } ww, wh = t.right.Size() w += ww if wh > h { h = wh } return w, h }
go
func (t *TextBar) Size() (int, int) { w, h := 0, 0 ww, wh := t.left.Size() w += ww if wh > h { h = wh } ww, wh = t.center.Size() w += ww if wh > h { h = wh } ww, wh = t.right.Size() w += ww if wh > h { h = wh } return w, h }
[ "func", "(", "t", "*", "TextBar", ")", "Size", "(", ")", "(", "int", ",", "int", ")", "{", "w", ",", "h", ":=", "0", ",", "0", "\n\n", "ww", ",", "wh", ":=", "t", ".", "left", ".", "Size", "(", ")", "\n", "w", "+=", "ww", "\n", "if", "wh", ">", "h", "{", "h", "=", "wh", "\n", "}", "\n", "ww", ",", "wh", "=", "t", ".", "center", ".", "Size", "(", ")", "\n", "w", "+=", "ww", "\n", "if", "wh", ">", "h", "{", "h", "=", "wh", "\n", "}", "\n", "ww", ",", "wh", "=", "t", ".", "right", ".", "Size", "(", ")", "\n", "w", "+=", "ww", "\n", "if", "wh", ">", "h", "{", "h", "=", "wh", "\n", "}", "\n", "return", "w", ",", "h", "\n", "}" ]
// Size implements the Size method for Widget, returning the width // and height in character cells.
[ "Size", "implements", "the", "Size", "method", "for", "Widget", "returning", "the", "width", "and", "height", "in", "character", "cells", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textbar.go#L155-L174
train
gdamore/tcell
views/textbar.go
HandleEvent
func (t *TextBar) HandleEvent(ev tcell.Event) bool { switch ev.(type) { case *EventWidgetContent: t.changed = true return true } return false }
go
func (t *TextBar) HandleEvent(ev tcell.Event) bool { switch ev.(type) { case *EventWidgetContent: t.changed = true return true } return false }
[ "func", "(", "t", "*", "TextBar", ")", "HandleEvent", "(", "ev", "tcell", ".", "Event", ")", "bool", "{", "switch", "ev", ".", "(", "type", ")", "{", "case", "*", "EventWidgetContent", ":", "t", ".", "changed", "=", "true", "\n", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// HandleEvent handles incoming events. The only events handled are // those for the Text objects; when those change, the TextBar adjusts // the layout to accommodate.
[ "HandleEvent", "handles", "incoming", "events", ".", "The", "only", "events", "handled", "are", "those", "for", "the", "Text", "objects", ";", "when", "those", "change", "the", "TextBar", "adjusts", "the", "layout", "to", "accommodate", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textbar.go#L179-L186
train
gdamore/tcell
color.go
Hex
func (c Color) Hex() int32 { if c&ColorIsRGB != 0 { return (int32(c) & 0xffffff) } if v, ok := ColorValues[c]; ok { return v } return -1 }
go
func (c Color) Hex() int32 { if c&ColorIsRGB != 0 { return (int32(c) & 0xffffff) } if v, ok := ColorValues[c]; ok { return v } return -1 }
[ "func", "(", "c", "Color", ")", "Hex", "(", ")", "int32", "{", "if", "c", "&", "ColorIsRGB", "!=", "0", "{", "return", "(", "int32", "(", "c", ")", "&", "0xffffff", ")", "\n", "}", "\n", "if", "v", ",", "ok", ":=", "ColorValues", "[", "c", "]", ";", "ok", "{", "return", "v", "\n", "}", "\n", "return", "-", "1", "\n", "}" ]
// Hex returns the color's hexadecimal RGB 24-bit value with each component // consisting of a single byte, ala R << 16 | G << 8 | B. If the color // is unknown or unset, -1 is returned.
[ "Hex", "returns", "the", "color", "s", "hexadecimal", "RGB", "24", "-", "bit", "value", "with", "each", "component", "consisting", "of", "a", "single", "byte", "ala", "R", "<<", "16", "|", "G", "<<", "8", "|", "B", ".", "If", "the", "color", "is", "unknown", "or", "unset", "-", "1", "is", "returned", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/color.go#L975-L983
train
gdamore/tcell
color.go
NewRGBColor
func NewRGBColor(r, g, b int32) Color { return NewHexColor(((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff)) }
go
func NewRGBColor(r, g, b int32) Color { return NewHexColor(((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff)) }
[ "func", "NewRGBColor", "(", "r", ",", "g", ",", "b", "int32", ")", "Color", "{", "return", "NewHexColor", "(", "(", "(", "r", "&", "0xff", ")", "<<", "16", ")", "|", "(", "(", "g", "&", "0xff", ")", "<<", "8", ")", "|", "(", "b", "&", "0xff", ")", ")", "\n", "}" ]
// NewRGBColor returns a new color with the given red, green, and blue values. // Each value must be represented in the range 0-255.
[ "NewRGBColor", "returns", "a", "new", "color", "with", "the", "given", "red", "green", "and", "blue", "values", ".", "Each", "value", "must", "be", "represented", "in", "the", "range", "0", "-", "255", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/color.go#L998-L1000
train
gdamore/tcell
cell.go
Invalidate
func (cb *CellBuffer) Invalidate() { for i := range cb.cells { cb.cells[i].lastMain = rune(0) } }
go
func (cb *CellBuffer) Invalidate() { for i := range cb.cells { cb.cells[i].lastMain = rune(0) } }
[ "func", "(", "cb", "*", "CellBuffer", ")", "Invalidate", "(", ")", "{", "for", "i", ":=", "range", "cb", ".", "cells", "{", "cb", ".", "cells", "[", "i", "]", ".", "lastMain", "=", "rune", "(", "0", ")", "\n", "}", "\n", "}" ]
// Invalidate marks all characters within the buffer as dirty.
[ "Invalidate", "marks", "all", "characters", "within", "the", "buffer", "as", "dirty", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/cell.go#L87-L91
train
gdamore/tcell
cell.go
Dirty
func (cb *CellBuffer) Dirty(x, y int) bool { if x >= 0 && y >= 0 && x < cb.w && y < cb.h { c := &cb.cells[(y*cb.w)+x] if c.lastMain == rune(0) { return true } if c.lastMain != c.currMain { return true } if c.lastStyle != c.currStyle { return true } if len(c.lastComb) != len(c.currComb) { return true } for i := range c.lastComb { if c.lastComb[i] != c.currComb[i] { return true } } } return false }
go
func (cb *CellBuffer) Dirty(x, y int) bool { if x >= 0 && y >= 0 && x < cb.w && y < cb.h { c := &cb.cells[(y*cb.w)+x] if c.lastMain == rune(0) { return true } if c.lastMain != c.currMain { return true } if c.lastStyle != c.currStyle { return true } if len(c.lastComb) != len(c.currComb) { return true } for i := range c.lastComb { if c.lastComb[i] != c.currComb[i] { return true } } } return false }
[ "func", "(", "cb", "*", "CellBuffer", ")", "Dirty", "(", "x", ",", "y", "int", ")", "bool", "{", "if", "x", ">=", "0", "&&", "y", ">=", "0", "&&", "x", "<", "cb", ".", "w", "&&", "y", "<", "cb", ".", "h", "{", "c", ":=", "&", "cb", ".", "cells", "[", "(", "y", "*", "cb", ".", "w", ")", "+", "x", "]", "\n", "if", "c", ".", "lastMain", "==", "rune", "(", "0", ")", "{", "return", "true", "\n", "}", "\n", "if", "c", ".", "lastMain", "!=", "c", ".", "currMain", "{", "return", "true", "\n", "}", "\n", "if", "c", ".", "lastStyle", "!=", "c", ".", "currStyle", "{", "return", "true", "\n", "}", "\n", "if", "len", "(", "c", ".", "lastComb", ")", "!=", "len", "(", "c", ".", "currComb", ")", "{", "return", "true", "\n", "}", "\n", "for", "i", ":=", "range", "c", ".", "lastComb", "{", "if", "c", ".", "lastComb", "[", "i", "]", "!=", "c", ".", "currComb", "[", "i", "]", "{", "return", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// Dirty checks if a character at the given location needs an // to be refreshed on the physical display. This returns true // if the cell content is different since the last time it was // marked clean.
[ "Dirty", "checks", "if", "a", "character", "at", "the", "given", "location", "needs", "an", "to", "be", "refreshed", "on", "the", "physical", "display", ".", "This", "returns", "true", "if", "the", "cell", "content", "is", "different", "since", "the", "last", "time", "it", "was", "marked", "clean", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/cell.go#L97-L119
train
gdamore/tcell
cell.go
Resize
func (cb *CellBuffer) Resize(w, h int) { if cb.h == h && cb.w == w { return } newc := make([]cell, w*h) for y := 0; y < h && y < cb.h; y++ { for x := 0; x < w && x < cb.w; x++ { oc := &cb.cells[(y*cb.w)+x] nc := &newc[(y*w)+x] nc.currMain = oc.currMain nc.currComb = oc.currComb nc.currStyle = oc.currStyle nc.width = oc.width nc.lastMain = rune(0) } } cb.cells = newc cb.h = h cb.w = w }
go
func (cb *CellBuffer) Resize(w, h int) { if cb.h == h && cb.w == w { return } newc := make([]cell, w*h) for y := 0; y < h && y < cb.h; y++ { for x := 0; x < w && x < cb.w; x++ { oc := &cb.cells[(y*cb.w)+x] nc := &newc[(y*w)+x] nc.currMain = oc.currMain nc.currComb = oc.currComb nc.currStyle = oc.currStyle nc.width = oc.width nc.lastMain = rune(0) } } cb.cells = newc cb.h = h cb.w = w }
[ "func", "(", "cb", "*", "CellBuffer", ")", "Resize", "(", "w", ",", "h", "int", ")", "{", "if", "cb", ".", "h", "==", "h", "&&", "cb", ".", "w", "==", "w", "{", "return", "\n", "}", "\n\n", "newc", ":=", "make", "(", "[", "]", "cell", ",", "w", "*", "h", ")", "\n", "for", "y", ":=", "0", ";", "y", "<", "h", "&&", "y", "<", "cb", ".", "h", ";", "y", "++", "{", "for", "x", ":=", "0", ";", "x", "<", "w", "&&", "x", "<", "cb", ".", "w", ";", "x", "++", "{", "oc", ":=", "&", "cb", ".", "cells", "[", "(", "y", "*", "cb", ".", "w", ")", "+", "x", "]", "\n", "nc", ":=", "&", "newc", "[", "(", "y", "*", "w", ")", "+", "x", "]", "\n", "nc", ".", "currMain", "=", "oc", ".", "currMain", "\n", "nc", ".", "currComb", "=", "oc", ".", "currComb", "\n", "nc", ".", "currStyle", "=", "oc", ".", "currStyle", "\n", "nc", ".", "width", "=", "oc", ".", "width", "\n", "nc", ".", "lastMain", "=", "rune", "(", "0", ")", "\n", "}", "\n", "}", "\n", "cb", ".", "cells", "=", "newc", "\n", "cb", ".", "h", "=", "h", "\n", "cb", ".", "w", "=", "w", "\n", "}" ]
// Resize is used to resize the cells array, with different dimensions, // while preserving the original contents. The cells will be invalidated // so that they can be redrawn.
[ "Resize", "is", "used", "to", "resize", "the", "cells", "array", "with", "different", "dimensions", "while", "preserving", "the", "original", "contents", ".", "The", "cells", "will", "be", "invalidated", "so", "that", "they", "can", "be", "redrawn", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/cell.go#L143-L164
train
gdamore/tcell
cell.go
Fill
func (cb *CellBuffer) Fill(r rune, style Style) { for i := range cb.cells { c := &cb.cells[i] c.currMain = r c.currComb = nil c.currStyle = style c.width = 1 } }
go
func (cb *CellBuffer) Fill(r rune, style Style) { for i := range cb.cells { c := &cb.cells[i] c.currMain = r c.currComb = nil c.currStyle = style c.width = 1 } }
[ "func", "(", "cb", "*", "CellBuffer", ")", "Fill", "(", "r", "rune", ",", "style", "Style", ")", "{", "for", "i", ":=", "range", "cb", ".", "cells", "{", "c", ":=", "&", "cb", ".", "cells", "[", "i", "]", "\n", "c", ".", "currMain", "=", "r", "\n", "c", ".", "currComb", "=", "nil", "\n", "c", ".", "currStyle", "=", "style", "\n", "c", ".", "width", "=", "1", "\n", "}", "\n", "}" ]
// Fill fills the entire cell buffer array with the specified character // and style. Normally choose ' ' to clear the screen. This API doesn't // support combining characters, or characters with a width larger than one.
[ "Fill", "fills", "the", "entire", "cell", "buffer", "array", "with", "the", "specified", "character", "and", "style", ".", "Normally", "choose", "to", "clear", "the", "screen", ".", "This", "API", "doesn", "t", "support", "combining", "characters", "or", "characters", "with", "a", "width", "larger", "than", "one", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/cell.go#L169-L177
train
gdamore/tcell
views/widget.go
Watch
func (ww *WidgetWatchers) Watch(handler tcell.EventHandler) { if ww.watchers == nil { ww.watchers = make(map[tcell.EventHandler]struct{}) } ww.watchers[handler] = struct{}{} }
go
func (ww *WidgetWatchers) Watch(handler tcell.EventHandler) { if ww.watchers == nil { ww.watchers = make(map[tcell.EventHandler]struct{}) } ww.watchers[handler] = struct{}{} }
[ "func", "(", "ww", "*", "WidgetWatchers", ")", "Watch", "(", "handler", "tcell", ".", "EventHandler", ")", "{", "if", "ww", ".", "watchers", "==", "nil", "{", "ww", ".", "watchers", "=", "make", "(", "map", "[", "tcell", ".", "EventHandler", "]", "struct", "{", "}", ")", "\n", "}", "\n", "ww", ".", "watchers", "[", "handler", "]", "=", "struct", "{", "}", "{", "}", "\n", "}" ]
// Watch monitors this WidgetWatcher, causing the handler to be fired // with EventWidget as they are occur on the watched Widget.
[ "Watch", "monitors", "this", "WidgetWatcher", "causing", "the", "handler", "to", "be", "fired", "with", "EventWidget", "as", "they", "are", "occur", "on", "the", "watched", "Widget", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/widget.go#L93-L98
train
gdamore/tcell
views/widget.go
Unwatch
func (ww *WidgetWatchers) Unwatch(handler tcell.EventHandler) { if ww.watchers != nil { delete(ww.watchers, handler) } }
go
func (ww *WidgetWatchers) Unwatch(handler tcell.EventHandler) { if ww.watchers != nil { delete(ww.watchers, handler) } }
[ "func", "(", "ww", "*", "WidgetWatchers", ")", "Unwatch", "(", "handler", "tcell", ".", "EventHandler", ")", "{", "if", "ww", ".", "watchers", "!=", "nil", "{", "delete", "(", "ww", ".", "watchers", ",", "handler", ")", "\n", "}", "\n", "}" ]
// Unwatch stops monitoring this WidgetWatcher. The handler will no longer // be fired for Widget events.
[ "Unwatch", "stops", "monitoring", "this", "WidgetWatcher", ".", "The", "handler", "will", "no", "longer", "be", "fired", "for", "Widget", "events", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/widget.go#L102-L106
train
gdamore/tcell
views/widget.go
PostEvent
func (ww *WidgetWatchers) PostEvent(wev EventWidget) { for watcher := range ww.watchers { // Deliver events to all listeners, ignoring return value. watcher.HandleEvent(wev) } }
go
func (ww *WidgetWatchers) PostEvent(wev EventWidget) { for watcher := range ww.watchers { // Deliver events to all listeners, ignoring return value. watcher.HandleEvent(wev) } }
[ "func", "(", "ww", "*", "WidgetWatchers", ")", "PostEvent", "(", "wev", "EventWidget", ")", "{", "for", "watcher", ":=", "range", "ww", ".", "watchers", "{", "// Deliver events to all listeners, ignoring return value.", "watcher", ".", "HandleEvent", "(", "wev", ")", "\n", "}", "\n", "}" ]
// PostEvent delivers the EventWidget to all registered watchers. It is // to be called by the Widget implementation.
[ "PostEvent", "delivers", "the", "EventWidget", "to", "all", "registered", "watchers", ".", "It", "is", "to", "be", "called", "by", "the", "Widget", "implementation", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/widget.go#L110-L115
train
gdamore/tcell
views/widget.go
PostEventWidgetContent
func (ww *WidgetWatchers) PostEventWidgetContent(w Widget) { ev := &EventWidgetContent{} ev.SetWidget(w) ev.SetEventNow() ww.PostEvent(ev) }
go
func (ww *WidgetWatchers) PostEventWidgetContent(w Widget) { ev := &EventWidgetContent{} ev.SetWidget(w) ev.SetEventNow() ww.PostEvent(ev) }
[ "func", "(", "ww", "*", "WidgetWatchers", ")", "PostEventWidgetContent", "(", "w", "Widget", ")", "{", "ev", ":=", "&", "EventWidgetContent", "{", "}", "\n", "ev", ".", "SetWidget", "(", "w", ")", "\n", "ev", ".", "SetEventNow", "(", ")", "\n", "ww", ".", "PostEvent", "(", "ev", ")", "\n", "}" ]
// PostEventWidgetContent is called by the Widget when its content is // changed, delivering EventWidgetContent to all watchers.
[ "PostEventWidgetContent", "is", "called", "by", "the", "Widget", "when", "its", "content", "is", "changed", "delivering", "EventWidgetContent", "to", "all", "watchers", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/widget.go#L119-L124
train
gdamore/tcell
views/widget.go
PostEventWidgetResize
func (ww *WidgetWatchers) PostEventWidgetResize(w Widget) { ev := &EventWidgetResize{} ev.SetWidget(w) ev.SetEventNow() ww.PostEvent(ev) }
go
func (ww *WidgetWatchers) PostEventWidgetResize(w Widget) { ev := &EventWidgetResize{} ev.SetWidget(w) ev.SetEventNow() ww.PostEvent(ev) }
[ "func", "(", "ww", "*", "WidgetWatchers", ")", "PostEventWidgetResize", "(", "w", "Widget", ")", "{", "ev", ":=", "&", "EventWidgetResize", "{", "}", "\n", "ev", ".", "SetWidget", "(", "w", ")", "\n", "ev", ".", "SetEventNow", "(", ")", "\n", "ww", ".", "PostEvent", "(", "ev", ")", "\n", "}" ]
// PostEventWidgetResize is called by the Widget when the underlying View // has resized, delivering EventWidgetResize to all watchers.
[ "PostEventWidgetResize", "is", "called", "by", "the", "Widget", "when", "the", "underlying", "View", "has", "resized", "delivering", "EventWidgetResize", "to", "all", "watchers", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/widget.go#L128-L133
train
gdamore/tcell
views/widget.go
PostEventWidgetMove
func (ww *WidgetWatchers) PostEventWidgetMove(w Widget) { ev := &EventWidgetMove{} ev.SetWidget(w) ev.SetEventNow() ww.PostEvent(ev) }
go
func (ww *WidgetWatchers) PostEventWidgetMove(w Widget) { ev := &EventWidgetMove{} ev.SetWidget(w) ev.SetEventNow() ww.PostEvent(ev) }
[ "func", "(", "ww", "*", "WidgetWatchers", ")", "PostEventWidgetMove", "(", "w", "Widget", ")", "{", "ev", ":=", "&", "EventWidgetMove", "{", "}", "\n", "ev", ".", "SetWidget", "(", "w", ")", "\n", "ev", ".", "SetEventNow", "(", ")", "\n", "ww", ".", "PostEvent", "(", "ev", ")", "\n", "}" ]
// PostEventWidgetMove is called by the Widget when it is moved to a new // location, delivering EventWidgetMove to all watchers.
[ "PostEventWidgetMove", "is", "called", "by", "the", "Widget", "when", "it", "is", "moved", "to", "a", "new", "location", "delivering", "EventWidgetMove", "to", "all", "watchers", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/widget.go#L137-L142
train
gdamore/tcell
views/textarea.go
SetLines
func (ta *TextArea) SetLines(lines []string) { ta.Init() m := ta.model m.width = 0 m.height = len(lines) m.lines = append([]string{}, lines...) for _, l := range lines { if len(l) > m.width { m.width = len(l) } } ta.CellView.SetModel(m) }
go
func (ta *TextArea) SetLines(lines []string) { ta.Init() m := ta.model m.width = 0 m.height = len(lines) m.lines = append([]string{}, lines...) for _, l := range lines { if len(l) > m.width { m.width = len(l) } } ta.CellView.SetModel(m) }
[ "func", "(", "ta", "*", "TextArea", ")", "SetLines", "(", "lines", "[", "]", "string", ")", "{", "ta", ".", "Init", "(", ")", "\n", "m", ":=", "ta", ".", "model", "\n", "m", ".", "width", "=", "0", "\n", "m", ".", "height", "=", "len", "(", "lines", ")", "\n", "m", ".", "lines", "=", "append", "(", "[", "]", "string", "{", "}", ",", "lines", "...", ")", "\n", "for", "_", ",", "l", ":=", "range", "lines", "{", "if", "len", "(", "l", ")", ">", "m", ".", "width", "{", "m", ".", "width", "=", "len", "(", "l", ")", "\n", "}", "\n", "}", "\n", "ta", ".", "CellView", ".", "SetModel", "(", "m", ")", "\n", "}" ]
// SetLines sets the content text to display.
[ "SetLines", "sets", "the", "content", "text", "to", "display", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textarea.go#L91-L103
train
gdamore/tcell
views/textarea.go
EnableCursor
func (ta *TextArea) EnableCursor(on bool) { ta.Init() ta.model.cursor = on }
go
func (ta *TextArea) EnableCursor(on bool) { ta.Init() ta.model.cursor = on }
[ "func", "(", "ta", "*", "TextArea", ")", "EnableCursor", "(", "on", "bool", ")", "{", "ta", ".", "Init", "(", ")", "\n", "ta", ".", "model", ".", "cursor", "=", "on", "\n", "}" ]
// EnableCursor enables a soft cursor in the TextArea.
[ "EnableCursor", "enables", "a", "soft", "cursor", "in", "the", "TextArea", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textarea.go#L111-L114
train
gdamore/tcell
views/textarea.go
HideCursor
func (ta *TextArea) HideCursor(on bool) { ta.Init() ta.model.hide = on }
go
func (ta *TextArea) HideCursor(on bool) { ta.Init() ta.model.hide = on }
[ "func", "(", "ta", "*", "TextArea", ")", "HideCursor", "(", "on", "bool", ")", "{", "ta", ".", "Init", "(", ")", "\n", "ta", ".", "model", ".", "hide", "=", "on", "\n", "}" ]
// HideCursor hides or shows the cursor in the TextArea. // If on is true, the cursor is hidden. Note that a cursor is only // shown if it is enabled.
[ "HideCursor", "hides", "or", "shows", "the", "cursor", "in", "the", "TextArea", ".", "If", "on", "is", "true", "the", "cursor", "is", "hidden", ".", "Note", "that", "a", "cursor", "is", "only", "shown", "if", "it", "is", "enabled", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textarea.go#L119-L122
train
gdamore/tcell
views/textarea.go
SetContent
func (ta *TextArea) SetContent(text string) { ta.Init() lines := strings.Split(strings.Trim(text, "\n"), "\n") ta.SetLines(lines) }
go
func (ta *TextArea) SetContent(text string) { ta.Init() lines := strings.Split(strings.Trim(text, "\n"), "\n") ta.SetLines(lines) }
[ "func", "(", "ta", "*", "TextArea", ")", "SetContent", "(", "text", "string", ")", "{", "ta", ".", "Init", "(", ")", "\n", "lines", ":=", "strings", ".", "Split", "(", "strings", ".", "Trim", "(", "text", ",", "\"", "\\n", "\"", ")", ",", "\"", "\\n", "\"", ")", "\n", "ta", ".", "SetLines", "(", "lines", ")", "\n", "}" ]
// SetContent is used to set the textual content, passed as a // single string. Lines within the string are delimited by newlines.
[ "SetContent", "is", "used", "to", "set", "the", "textual", "content", "passed", "as", "a", "single", "string", ".", "Lines", "within", "the", "string", "are", "delimited", "by", "newlines", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textarea.go#L126-L130
train
gdamore/tcell
views/textarea.go
Init
func (ta *TextArea) Init() { ta.once.Do(func() { lm := &linesModel{lines: []string{}, width: 0} ta.model = lm ta.CellView.Init() ta.CellView.SetModel(lm) }) }
go
func (ta *TextArea) Init() { ta.once.Do(func() { lm := &linesModel{lines: []string{}, width: 0} ta.model = lm ta.CellView.Init() ta.CellView.SetModel(lm) }) }
[ "func", "(", "ta", "*", "TextArea", ")", "Init", "(", ")", "{", "ta", ".", "once", ".", "Do", "(", "func", "(", ")", "{", "lm", ":=", "&", "linesModel", "{", "lines", ":", "[", "]", "string", "{", "}", ",", "width", ":", "0", "}", "\n", "ta", ".", "model", "=", "lm", "\n", "ta", ".", "CellView", ".", "Init", "(", ")", "\n", "ta", ".", "CellView", ".", "SetModel", "(", "lm", ")", "\n", "}", ")", "\n", "}" ]
// Init initializes the TextArea.
[ "Init", "initializes", "the", "TextArea", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textarea.go#L133-L140
train
gdamore/tcell
views/text.go
calcY
func (t *Text) calcY(height int) int { if t.align&VAlignCenter != 0 { return (height - len(t.lengths)) / 2 } if t.align&VAlignBottom != 0 { return height - len(t.lengths) } return 0 }
go
func (t *Text) calcY(height int) int { if t.align&VAlignCenter != 0 { return (height - len(t.lengths)) / 2 } if t.align&VAlignBottom != 0 { return height - len(t.lengths) } return 0 }
[ "func", "(", "t", "*", "Text", ")", "calcY", "(", "height", "int", ")", "int", "{", "if", "t", ".", "align", "&", "VAlignCenter", "!=", "0", "{", "return", "(", "height", "-", "len", "(", "t", ".", "lengths", ")", ")", "/", "2", "\n", "}", "\n", "if", "t", ".", "align", "&", "VAlignBottom", "!=", "0", "{", "return", "height", "-", "len", "(", "t", ".", "lengths", ")", "\n", "}", "\n", "return", "0", "\n", "}" ]
// calcY figures the initial Y offset. Alignment is top by default.
[ "calcY", "figures", "the", "initial", "Y", "offset", ".", "Alignment", "is", "top", "by", "default", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/text.go#L51-L59
train
gdamore/tcell
views/text.go
calcX
func (t *Text) calcX(width, line int) int { if t.align&HAlignCenter != 0 { return (width - t.lengths[line]) / 2 } if t.align&HAlignRight != 0 { return width - t.lengths[line] } return 0 }
go
func (t *Text) calcX(width, line int) int { if t.align&HAlignCenter != 0 { return (width - t.lengths[line]) / 2 } if t.align&HAlignRight != 0 { return width - t.lengths[line] } return 0 }
[ "func", "(", "t", "*", "Text", ")", "calcX", "(", "width", ",", "line", "int", ")", "int", "{", "if", "t", ".", "align", "&", "HAlignCenter", "!=", "0", "{", "return", "(", "width", "-", "t", ".", "lengths", "[", "line", "]", ")", "/", "2", "\n", "}", "\n", "if", "t", ".", "align", "&", "HAlignRight", "!=", "0", "{", "return", "width", "-", "t", ".", "lengths", "[", "line", "]", "\n", "}", "\n", "return", "0", "\n", "}" ]
// calcX figures the initial X offset for the given line. // Alignment is left by default.
[ "calcX", "figures", "the", "initial", "X", "offset", "for", "the", "given", "line", ".", "Alignment", "is", "left", "by", "default", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/text.go#L63-L71
train
gdamore/tcell
views/text.go
Draw
func (t *Text) Draw() { v := t.view if v == nil { return } width, height := v.Size() if width == 0 || height == 0 { return } t.clear() // Note that we might wind up with a negative X if the width // is larger than the length. That's OK, and correct even. // The view will clip it properly in that case. // We align to the left & top by default. y := t.calcY(height) r := rune(0) w := 0 x := 0 var styl tcell.Style var comb []rune line := 0 newline := true for i, l := range t.text { if newline { x = t.calcX(width, line) newline = false } if l == '\n' { if w != 0 { v.SetContent(x, y, r, comb, styl) } newline = true w = 0 comb = nil line++ y++ continue } if t.widths[i] == 0 { comb = append(comb, l) continue } if w != 0 { v.SetContent(x, y, r, comb, styl) x += w } r = l w = t.widths[i] styl = t.styles[i] comb = nil } if w != 0 { v.SetContent(x, y, r, comb, styl) } }
go
func (t *Text) Draw() { v := t.view if v == nil { return } width, height := v.Size() if width == 0 || height == 0 { return } t.clear() // Note that we might wind up with a negative X if the width // is larger than the length. That's OK, and correct even. // The view will clip it properly in that case. // We align to the left & top by default. y := t.calcY(height) r := rune(0) w := 0 x := 0 var styl tcell.Style var comb []rune line := 0 newline := true for i, l := range t.text { if newline { x = t.calcX(width, line) newline = false } if l == '\n' { if w != 0 { v.SetContent(x, y, r, comb, styl) } newline = true w = 0 comb = nil line++ y++ continue } if t.widths[i] == 0 { comb = append(comb, l) continue } if w != 0 { v.SetContent(x, y, r, comb, styl) x += w } r = l w = t.widths[i] styl = t.styles[i] comb = nil } if w != 0 { v.SetContent(x, y, r, comb, styl) } }
[ "func", "(", "t", "*", "Text", ")", "Draw", "(", ")", "{", "v", ":=", "t", ".", "view", "\n", "if", "v", "==", "nil", "{", "return", "\n", "}", "\n\n", "width", ",", "height", ":=", "v", ".", "Size", "(", ")", "\n", "if", "width", "==", "0", "||", "height", "==", "0", "{", "return", "\n", "}", "\n\n", "t", ".", "clear", "(", ")", "\n\n", "// Note that we might wind up with a negative X if the width", "// is larger than the length. That's OK, and correct even.", "// The view will clip it properly in that case.", "// We align to the left & top by default.", "y", ":=", "t", ".", "calcY", "(", "height", ")", "\n", "r", ":=", "rune", "(", "0", ")", "\n", "w", ":=", "0", "\n", "x", ":=", "0", "\n", "var", "styl", "tcell", ".", "Style", "\n", "var", "comb", "[", "]", "rune", "\n", "line", ":=", "0", "\n", "newline", ":=", "true", "\n", "for", "i", ",", "l", ":=", "range", "t", ".", "text", "{", "if", "newline", "{", "x", "=", "t", ".", "calcX", "(", "width", ",", "line", ")", "\n", "newline", "=", "false", "\n", "}", "\n", "if", "l", "==", "'\\n'", "{", "if", "w", "!=", "0", "{", "v", ".", "SetContent", "(", "x", ",", "y", ",", "r", ",", "comb", ",", "styl", ")", "\n", "}", "\n", "newline", "=", "true", "\n", "w", "=", "0", "\n", "comb", "=", "nil", "\n", "line", "++", "\n", "y", "++", "\n", "continue", "\n", "}", "\n", "if", "t", ".", "widths", "[", "i", "]", "==", "0", "{", "comb", "=", "append", "(", "comb", ",", "l", ")", "\n", "continue", "\n", "}", "\n", "if", "w", "!=", "0", "{", "v", ".", "SetContent", "(", "x", ",", "y", ",", "r", ",", "comb", ",", "styl", ")", "\n", "x", "+=", "w", "\n", "}", "\n", "r", "=", "l", "\n", "w", "=", "t", ".", "widths", "[", "i", "]", "\n", "styl", "=", "t", ".", "styles", "[", "i", "]", "\n", "comb", "=", "nil", "\n", "}", "\n", "if", "w", "!=", "0", "{", "v", ".", "SetContent", "(", "x", ",", "y", ",", "r", ",", "comb", ",", "styl", ")", "\n", "}", "\n", "}" ]
// Draw draws the Text.
[ "Draw", "draws", "the", "Text", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/text.go#L74-L133
train
gdamore/tcell
views/text.go
Size
func (t *Text) Size() (int, int) { if len(t.text) != 0 { return t.width, t.height } return 0, 0 }
go
func (t *Text) Size() (int, int) { if len(t.text) != 0 { return t.width, t.height } return 0, 0 }
[ "func", "(", "t", "*", "Text", ")", "Size", "(", ")", "(", "int", ",", "int", ")", "{", "if", "len", "(", "t", ".", "text", ")", "!=", "0", "{", "return", "t", ".", "width", ",", "t", ".", "height", "\n", "}", "\n", "return", "0", ",", "0", "\n", "}" ]
// Size returns the width and height in character cells of the Text.
[ "Size", "returns", "the", "width", "and", "height", "in", "character", "cells", "of", "the", "Text", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/text.go#L136-L141
train
gdamore/tcell
views/text.go
SetAlignment
func (t *Text) SetAlignment(align Alignment) { if align != t.align { t.align = align t.PostEventWidgetContent(t) } }
go
func (t *Text) SetAlignment(align Alignment) { if align != t.align { t.align = align t.PostEventWidgetContent(t) } }
[ "func", "(", "t", "*", "Text", ")", "SetAlignment", "(", "align", "Alignment", ")", "{", "if", "align", "!=", "t", ".", "align", "{", "t", ".", "align", "=", "align", "\n", "t", ".", "PostEventWidgetContent", "(", "t", ")", "\n", "}", "\n", "}" ]
// SetAlignment sets the alignment. Negative values // indicate right justification, positive values are left, // and zero indicates center aligned.
[ "SetAlignment", "sets", "the", "alignment", ".", "Negative", "values", "indicate", "right", "justification", "positive", "values", "are", "left", "and", "zero", "indicates", "center", "aligned", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/text.go#L146-L151
train
gdamore/tcell
views/text.go
SetText
func (t *Text) SetText(s string) { t.width = 0 t.text = []rune(s) if len(t.widths) < len(t.text) { t.widths = make([]int, len(t.text)) } else { t.widths = t.widths[0:len(t.text)] } if len(t.styles) < len(t.text) { t.styles = make([]tcell.Style, len(t.text)) } else { t.styles = t.styles[0:len(t.text)] } t.lengths = []int{} length := 0 for i, r := range t.text { t.widths[i] = runewidth.RuneWidth(r) t.styles[i] = t.style if r == '\n' { t.lengths = append(t.lengths, length) if length > t.width { t.width = length length = 0 } } else if t.widths[i] == 0 && length == 0 { // If first character on line is combining, inject // a leading space. (Shame on the caller!) t.widths = append(t.widths, 0) copy(t.widths[i+1:], t.widths[i:]) t.widths[i] = 1 t.text = append(t.text, ' ') copy(t.text[i+1:], t.text[i:]) t.text[i] = ' ' t.styles = append(t.styles, t.style) copy(t.styles[i+1:], t.styles[i:]) t.styles[i] = t.style length++ } else { length += t.widths[i] } } if length > 0 { t.lengths = append(t.lengths, length) if length > t.width { t.width = length } } t.height = len(t.lengths) t.PostEventWidgetContent(t) }
go
func (t *Text) SetText(s string) { t.width = 0 t.text = []rune(s) if len(t.widths) < len(t.text) { t.widths = make([]int, len(t.text)) } else { t.widths = t.widths[0:len(t.text)] } if len(t.styles) < len(t.text) { t.styles = make([]tcell.Style, len(t.text)) } else { t.styles = t.styles[0:len(t.text)] } t.lengths = []int{} length := 0 for i, r := range t.text { t.widths[i] = runewidth.RuneWidth(r) t.styles[i] = t.style if r == '\n' { t.lengths = append(t.lengths, length) if length > t.width { t.width = length length = 0 } } else if t.widths[i] == 0 && length == 0 { // If first character on line is combining, inject // a leading space. (Shame on the caller!) t.widths = append(t.widths, 0) copy(t.widths[i+1:], t.widths[i:]) t.widths[i] = 1 t.text = append(t.text, ' ') copy(t.text[i+1:], t.text[i:]) t.text[i] = ' ' t.styles = append(t.styles, t.style) copy(t.styles[i+1:], t.styles[i:]) t.styles[i] = t.style length++ } else { length += t.widths[i] } } if length > 0 { t.lengths = append(t.lengths, length) if length > t.width { t.width = length } } t.height = len(t.lengths) t.PostEventWidgetContent(t) }
[ "func", "(", "t", "*", "Text", ")", "SetText", "(", "s", "string", ")", "{", "t", ".", "width", "=", "0", "\n", "t", ".", "text", "=", "[", "]", "rune", "(", "s", ")", "\n", "if", "len", "(", "t", ".", "widths", ")", "<", "len", "(", "t", ".", "text", ")", "{", "t", ".", "widths", "=", "make", "(", "[", "]", "int", ",", "len", "(", "t", ".", "text", ")", ")", "\n", "}", "else", "{", "t", ".", "widths", "=", "t", ".", "widths", "[", "0", ":", "len", "(", "t", ".", "text", ")", "]", "\n", "}", "\n", "if", "len", "(", "t", ".", "styles", ")", "<", "len", "(", "t", ".", "text", ")", "{", "t", ".", "styles", "=", "make", "(", "[", "]", "tcell", ".", "Style", ",", "len", "(", "t", ".", "text", ")", ")", "\n", "}", "else", "{", "t", ".", "styles", "=", "t", ".", "styles", "[", "0", ":", "len", "(", "t", ".", "text", ")", "]", "\n", "}", "\n", "t", ".", "lengths", "=", "[", "]", "int", "{", "}", "\n", "length", ":=", "0", "\n", "for", "i", ",", "r", ":=", "range", "t", ".", "text", "{", "t", ".", "widths", "[", "i", "]", "=", "runewidth", ".", "RuneWidth", "(", "r", ")", "\n", "t", ".", "styles", "[", "i", "]", "=", "t", ".", "style", "\n", "if", "r", "==", "'\\n'", "{", "t", ".", "lengths", "=", "append", "(", "t", ".", "lengths", ",", "length", ")", "\n", "if", "length", ">", "t", ".", "width", "{", "t", ".", "width", "=", "length", "\n", "length", "=", "0", "\n", "}", "\n\n", "}", "else", "if", "t", ".", "widths", "[", "i", "]", "==", "0", "&&", "length", "==", "0", "{", "// If first character on line is combining, inject", "// a leading space. (Shame on the caller!)", "t", ".", "widths", "=", "append", "(", "t", ".", "widths", ",", "0", ")", "\n", "copy", "(", "t", ".", "widths", "[", "i", "+", "1", ":", "]", ",", "t", ".", "widths", "[", "i", ":", "]", ")", "\n", "t", ".", "widths", "[", "i", "]", "=", "1", "\n\n", "t", ".", "text", "=", "append", "(", "t", ".", "text", ",", "' '", ")", "\n", "copy", "(", "t", ".", "text", "[", "i", "+", "1", ":", "]", ",", "t", ".", "text", "[", "i", ":", "]", ")", "\n", "t", ".", "text", "[", "i", "]", "=", "' '", "\n\n", "t", ".", "styles", "=", "append", "(", "t", ".", "styles", ",", "t", ".", "style", ")", "\n", "copy", "(", "t", ".", "styles", "[", "i", "+", "1", ":", "]", ",", "t", ".", "styles", "[", "i", ":", "]", ")", "\n", "t", ".", "styles", "[", "i", "]", "=", "t", ".", "style", "\n", "length", "++", "\n", "}", "else", "{", "length", "+=", "t", ".", "widths", "[", "i", "]", "\n", "}", "\n", "}", "\n", "if", "length", ">", "0", "{", "t", ".", "lengths", "=", "append", "(", "t", ".", "lengths", ",", "length", ")", "\n", "if", "length", ">", "t", ".", "width", "{", "t", ".", "width", "=", "length", "\n", "}", "\n", "}", "\n", "t", ".", "height", "=", "len", "(", "t", ".", "lengths", ")", "\n", "t", ".", "PostEventWidgetContent", "(", "t", ")", "\n", "}" ]
// SetText sets the text used for the string. Any previously set // styles on individual rune indices are reset, and the default style // for the widget is set.
[ "SetText", "sets", "the", "text", "used", "for", "the", "string", ".", "Any", "previously", "set", "styles", "on", "individual", "rune", "indices", "are", "reset", "and", "the", "default", "style", "for", "the", "widget", "is", "set", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/text.go#L171-L223
train
gdamore/tcell
views/text.go
SetStyle
func (t *Text) SetStyle(style tcell.Style) { t.style = style for i := 0; i < len(t.text); i++ { if t.widths[i] != 0 { t.styles[i] = t.style } } t.PostEventWidgetContent(t) }
go
func (t *Text) SetStyle(style tcell.Style) { t.style = style for i := 0; i < len(t.text); i++ { if t.widths[i] != 0 { t.styles[i] = t.style } } t.PostEventWidgetContent(t) }
[ "func", "(", "t", "*", "Text", ")", "SetStyle", "(", "style", "tcell", ".", "Style", ")", "{", "t", ".", "style", "=", "style", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "t", ".", "text", ")", ";", "i", "++", "{", "if", "t", ".", "widths", "[", "i", "]", "!=", "0", "{", "t", ".", "styles", "[", "i", "]", "=", "t", ".", "style", "\n", "}", "\n", "}", "\n", "t", ".", "PostEventWidgetContent", "(", "t", ")", "\n", "}" ]
// SetStyle sets the style used. This applies to every cell in the // in the text.
[ "SetStyle", "sets", "the", "style", "used", ".", "This", "applies", "to", "every", "cell", "in", "the", "in", "the", "text", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/text.go#L232-L240
train
gdamore/tcell
views/text.go
StyleAt
func (t *Text) StyleAt(pos int) tcell.Style { if pos < 0 || pos >= len(t.text) || t.widths[pos] < 1 { return tcell.StyleDefault } return t.styles[pos] }
go
func (t *Text) StyleAt(pos int) tcell.Style { if pos < 0 || pos >= len(t.text) || t.widths[pos] < 1 { return tcell.StyleDefault } return t.styles[pos] }
[ "func", "(", "t", "*", "Text", ")", "StyleAt", "(", "pos", "int", ")", "tcell", ".", "Style", "{", "if", "pos", "<", "0", "||", "pos", ">=", "len", "(", "t", ".", "text", ")", "||", "t", ".", "widths", "[", "pos", "]", "<", "1", "{", "return", "tcell", ".", "StyleDefault", "\n", "}", "\n", "return", "t", ".", "styles", "[", "pos", "]", "\n", "}" ]
// StyleAt gets the style at the given rune index. If an invalid // index is given, or the index is a combining character, then // tcell.StyleDefault is returned.
[ "StyleAt", "gets", "the", "style", "at", "the", "given", "rune", "index", ".", "If", "an", "invalid", "index", "is", "given", "or", "the", "index", "is", "a", "combining", "character", "then", "tcell", ".", "StyleDefault", "is", "returned", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/text.go#L264-L269
train
gdamore/tcell
views/sstextbar.go
SetCenter
func (s *SimpleStyledTextBar) SetCenter(m string) { s.initialize() s.center.SetMarkup(m) }
go
func (s *SimpleStyledTextBar) SetCenter(m string) { s.initialize() s.center.SetMarkup(m) }
[ "func", "(", "s", "*", "SimpleStyledTextBar", ")", "SetCenter", "(", "m", "string", ")", "{", "s", ".", "initialize", "(", ")", "\n", "s", ".", "center", ".", "SetMarkup", "(", "m", ")", "\n", "}" ]
// SetCenter sets the center text for the textbar. // It is always centered.
[ "SetCenter", "sets", "the", "center", "text", "for", "the", "textbar", ".", "It", "is", "always", "centered", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/sstextbar.go#L53-L56
train
gdamore/tcell
termbox/compat.go
Init
func Init() error { outMode = OutputNormal if s, e := tcell.NewScreen(); e != nil { return e } else if e = s.Init(); e != nil { return e } else { screen = s return nil } }
go
func Init() error { outMode = OutputNormal if s, e := tcell.NewScreen(); e != nil { return e } else if e = s.Init(); e != nil { return e } else { screen = s return nil } }
[ "func", "Init", "(", ")", "error", "{", "outMode", "=", "OutputNormal", "\n", "if", "s", ",", "e", ":=", "tcell", ".", "NewScreen", "(", ")", ";", "e", "!=", "nil", "{", "return", "e", "\n", "}", "else", "if", "e", "=", "s", ".", "Init", "(", ")", ";", "e", "!=", "nil", "{", "return", "e", "\n", "}", "else", "{", "screen", "=", "s", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// Init initializes the screen for use.
[ "Init", "initializes", "the", "screen", "for", "use", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/termbox/compat.go#L29-L39
train
gdamore/tcell
termbox/compat.go
Clear
func Clear(fg, bg Attribute) { st := mkStyle(fg, bg) w, h := screen.Size() for row := 0; row < h; row++ { for col := 0; col < w; col++ { screen.SetContent(col, row, ' ', nil, st) } } }
go
func Clear(fg, bg Attribute) { st := mkStyle(fg, bg) w, h := screen.Size() for row := 0; row < h; row++ { for col := 0; col < w; col++ { screen.SetContent(col, row, ' ', nil, st) } } }
[ "func", "Clear", "(", "fg", ",", "bg", "Attribute", ")", "{", "st", ":=", "mkStyle", "(", "fg", ",", "bg", ")", "\n", "w", ",", "h", ":=", "screen", ".", "Size", "(", ")", "\n", "for", "row", ":=", "0", ";", "row", "<", "h", ";", "row", "++", "{", "for", "col", ":=", "0", ";", "col", "<", "w", ";", "col", "++", "{", "screen", ".", "SetContent", "(", "col", ",", "row", ",", "' '", ",", "nil", ",", "st", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Clear clears the screen with the given attributes.
[ "Clear", "clears", "the", "screen", "with", "the", "given", "attributes", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/termbox/compat.go#L134-L142
train
gdamore/tcell
termbox/compat.go
SetOutputMode
func SetOutputMode(mode OutputMode) OutputMode { if screen.Colors() < 256 { mode = OutputNormal } switch mode { case OutputCurrent: return outMode case OutputNormal, Output256, Output216, OutputGrayscale: outMode = mode return mode default: return outMode } }
go
func SetOutputMode(mode OutputMode) OutputMode { if screen.Colors() < 256 { mode = OutputNormal } switch mode { case OutputCurrent: return outMode case OutputNormal, Output256, Output216, OutputGrayscale: outMode = mode return mode default: return outMode } }
[ "func", "SetOutputMode", "(", "mode", "OutputMode", ")", "OutputMode", "{", "if", "screen", ".", "Colors", "(", ")", "<", "256", "{", "mode", "=", "OutputNormal", "\n", "}", "\n", "switch", "mode", "{", "case", "OutputCurrent", ":", "return", "outMode", "\n", "case", "OutputNormal", ",", "Output256", ",", "Output216", ",", "OutputGrayscale", ":", "outMode", "=", "mode", "\n", "return", "mode", "\n", "default", ":", "return", "outMode", "\n", "}", "\n", "}" ]
// SetOutputMode is used to set the color palette used.
[ "SetOutputMode", "is", "used", "to", "set", "the", "color", "palette", "used", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/termbox/compat.go#L175-L188
train
gdamore/tcell
termbox/compat.go
ParseEvent
func ParseEvent(data []byte) Event { // Not supported return Event{Type: EventError, Err: errors.New("no raw events")} }
go
func ParseEvent(data []byte) Event { // Not supported return Event{Type: EventError, Err: errors.New("no raw events")} }
[ "func", "ParseEvent", "(", "data", "[", "]", "byte", ")", "Event", "{", "// Not supported", "return", "Event", "{", "Type", ":", "EventError", ",", "Err", ":", "errors", ".", "New", "(", "\"", "\"", ")", "}", "\n", "}" ]
// ParseEvent is not supported.
[ "ParseEvent", "is", "not", "supported", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/termbox/compat.go#L332-L335
train
gdamore/tcell
errors.go
NewEventError
func NewEventError(err error) *EventError { return &EventError{t: time.Now(), err: err} }
go
func NewEventError(err error) *EventError { return &EventError{t: time.Now(), err: err} }
[ "func", "NewEventError", "(", "err", "error", ")", "*", "EventError", "{", "return", "&", "EventError", "{", "t", ":", "time", ".", "Now", "(", ")", ",", "err", ":", "err", "}", "\n", "}" ]
// NewEventError creates an ErrorEvent with the given error payload.
[ "NewEventError", "creates", "an", "ErrorEvent", "with", "the", "given", "error", "payload", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/errors.go#L71-L73
train
gdamore/tcell
style.go
Foreground
func (s Style) Foreground(c Color) Style { if c == ColorDefault { return (s &^ (0x1ffffff00000000 | styleFgSet)) } return (s &^ Style(0x1ffffff00000000)) | ((Style(c) & 0x1ffffff) << 32) | styleFgSet }
go
func (s Style) Foreground(c Color) Style { if c == ColorDefault { return (s &^ (0x1ffffff00000000 | styleFgSet)) } return (s &^ Style(0x1ffffff00000000)) | ((Style(c) & 0x1ffffff) << 32) | styleFgSet }
[ "func", "(", "s", "Style", ")", "Foreground", "(", "c", "Color", ")", "Style", "{", "if", "c", "==", "ColorDefault", "{", "return", "(", "s", "&^", "(", "0x1ffffff00000000", "|", "styleFgSet", ")", ")", "\n", "}", "\n", "return", "(", "s", "&^", "Style", "(", "0x1ffffff00000000", ")", ")", "|", "(", "(", "Style", "(", "c", ")", "&", "0x1ffffff", ")", "<<", "32", ")", "|", "styleFgSet", "\n", "}" ]
// Foreground returns a new style based on s, with the foreground color set // as requested. ColorDefault can be used to select the global default.
[ "Foreground", "returns", "a", "new", "style", "based", "on", "s", "with", "the", "foreground", "color", "set", "as", "requested", ".", "ColorDefault", "can", "be", "used", "to", "select", "the", "global", "default", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/style.go#L50-L56
train
gdamore/tcell
style.go
Background
func (s Style) Background(c Color) Style { if c == ColorDefault { return (s &^ (0x1ffffff | styleBgSet)) } return (s &^ (0x1ffffff)) | (Style(c) & 0x1ffffff) | styleBgSet }
go
func (s Style) Background(c Color) Style { if c == ColorDefault { return (s &^ (0x1ffffff | styleBgSet)) } return (s &^ (0x1ffffff)) | (Style(c) & 0x1ffffff) | styleBgSet }
[ "func", "(", "s", "Style", ")", "Background", "(", "c", "Color", ")", "Style", "{", "if", "c", "==", "ColorDefault", "{", "return", "(", "s", "&^", "(", "0x1ffffff", "|", "styleBgSet", ")", ")", "\n", "}", "\n", "return", "(", "s", "&^", "(", "0x1ffffff", ")", ")", "|", "(", "Style", "(", "c", ")", "&", "0x1ffffff", ")", "|", "styleBgSet", "\n", "}" ]
// Background returns a new style based on s, with the background color set // as requested. ColorDefault can be used to select the global default.
[ "Background", "returns", "a", "new", "style", "based", "on", "s", "with", "the", "background", "color", "set", "as", "requested", ".", "ColorDefault", "can", "be", "used", "to", "select", "the", "global", "default", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/style.go#L60-L65
train
gdamore/tcell
style.go
Decompose
func (s Style) Decompose() (fg Color, bg Color, attr AttrMask) { if s&styleFgSet != 0 { fg = Color(s>>32) & 0x1ffffff } else { fg = ColorDefault } if s&styleBgSet != 0 { bg = Color(s & 0x1ffffff) } else { bg = ColorDefault } attr = AttrMask(s) & attrAll return fg, bg, attr }
go
func (s Style) Decompose() (fg Color, bg Color, attr AttrMask) { if s&styleFgSet != 0 { fg = Color(s>>32) & 0x1ffffff } else { fg = ColorDefault } if s&styleBgSet != 0 { bg = Color(s & 0x1ffffff) } else { bg = ColorDefault } attr = AttrMask(s) & attrAll return fg, bg, attr }
[ "func", "(", "s", "Style", ")", "Decompose", "(", ")", "(", "fg", "Color", ",", "bg", "Color", ",", "attr", "AttrMask", ")", "{", "if", "s", "&", "styleFgSet", "!=", "0", "{", "fg", "=", "Color", "(", "s", ">>", "32", ")", "&", "0x1ffffff", "\n", "}", "else", "{", "fg", "=", "ColorDefault", "\n", "}", "\n", "if", "s", "&", "styleBgSet", "!=", "0", "{", "bg", "=", "Color", "(", "s", "&", "0x1ffffff", ")", "\n", "}", "else", "{", "bg", "=", "ColorDefault", "\n", "}", "\n", "attr", "=", "AttrMask", "(", "s", ")", "&", "attrAll", "\n\n", "return", "fg", ",", "bg", ",", "attr", "\n", "}" ]
// Decompose breaks a style up, returning the foreground, background, // and other attributes.
[ "Decompose", "breaks", "a", "style", "up", "returning", "the", "foreground", "background", "and", "other", "attributes", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/style.go#L69-L83
train
gdamore/tcell
style.go
Bold
func (s Style) Bold(on bool) Style { return s.setAttrs(Style(AttrBold), on) }
go
func (s Style) Bold(on bool) Style { return s.setAttrs(Style(AttrBold), on) }
[ "func", "(", "s", "Style", ")", "Bold", "(", "on", "bool", ")", "Style", "{", "return", "s", ".", "setAttrs", "(", "Style", "(", "AttrBold", ")", ",", "on", ")", "\n", "}" ]
// Bold returns a new style based on s, with the bold attribute set // as requested.
[ "Bold", "returns", "a", "new", "style", "based", "on", "s", "with", "the", "bold", "attribute", "set", "as", "requested", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/style.go#L99-L101
train
gdamore/tcell
style.go
Blink
func (s Style) Blink(on bool) Style { return s.setAttrs(Style(AttrBlink), on) }
go
func (s Style) Blink(on bool) Style { return s.setAttrs(Style(AttrBlink), on) }
[ "func", "(", "s", "Style", ")", "Blink", "(", "on", "bool", ")", "Style", "{", "return", "s", ".", "setAttrs", "(", "Style", "(", "AttrBlink", ")", ",", "on", ")", "\n", "}" ]
// Blink returns a new style based on s, with the blink attribute set // as requested.
[ "Blink", "returns", "a", "new", "style", "based", "on", "s", "with", "the", "blink", "attribute", "set", "as", "requested", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/style.go#L105-L107
train
gdamore/tcell
style.go
Dim
func (s Style) Dim(on bool) Style { return s.setAttrs(Style(AttrDim), on) }
go
func (s Style) Dim(on bool) Style { return s.setAttrs(Style(AttrDim), on) }
[ "func", "(", "s", "Style", ")", "Dim", "(", "on", "bool", ")", "Style", "{", "return", "s", ".", "setAttrs", "(", "Style", "(", "AttrDim", ")", ",", "on", ")", "\n", "}" ]
// Dim returns a new style based on s, with the dim attribute set // as requested.
[ "Dim", "returns", "a", "new", "style", "based", "on", "s", "with", "the", "dim", "attribute", "set", "as", "requested", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/style.go#L111-L113
train
gdamore/tcell
style.go
Underline
func (s Style) Underline(on bool) Style { return s.setAttrs(Style(AttrUnderline), on) }
go
func (s Style) Underline(on bool) Style { return s.setAttrs(Style(AttrUnderline), on) }
[ "func", "(", "s", "Style", ")", "Underline", "(", "on", "bool", ")", "Style", "{", "return", "s", ".", "setAttrs", "(", "Style", "(", "AttrUnderline", ")", ",", "on", ")", "\n", "}" ]
// Underline returns a new style based on s, with the underline attribute set // as requested.
[ "Underline", "returns", "a", "new", "style", "based", "on", "s", "with", "the", "underline", "attribute", "set", "as", "requested", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/style.go#L124-L126
train
gdamore/tcell
key.go
Name
func (ev *EventKey) Name() string { s := "" m := []string{} if ev.mod&ModShift != 0 { m = append(m, "Shift") } if ev.mod&ModAlt != 0 { m = append(m, "Alt") } if ev.mod&ModMeta != 0 { m = append(m, "Meta") } if ev.mod&ModCtrl != 0 { m = append(m, "Ctrl") } ok := false if s, ok = KeyNames[ev.key]; !ok { if ev.key == KeyRune { s = "Rune[" + string(ev.ch) + "]" } else { s = fmt.Sprintf("Key[%d,%d]", ev.key, int(ev.ch)) } } if len(m) != 0 { if ev.mod&ModCtrl != 0 && strings.HasPrefix(s, "Ctrl-") { s = s[5:] } return fmt.Sprintf("%s+%s", strings.Join(m, "+"), s) } return s }
go
func (ev *EventKey) Name() string { s := "" m := []string{} if ev.mod&ModShift != 0 { m = append(m, "Shift") } if ev.mod&ModAlt != 0 { m = append(m, "Alt") } if ev.mod&ModMeta != 0 { m = append(m, "Meta") } if ev.mod&ModCtrl != 0 { m = append(m, "Ctrl") } ok := false if s, ok = KeyNames[ev.key]; !ok { if ev.key == KeyRune { s = "Rune[" + string(ev.ch) + "]" } else { s = fmt.Sprintf("Key[%d,%d]", ev.key, int(ev.ch)) } } if len(m) != 0 { if ev.mod&ModCtrl != 0 && strings.HasPrefix(s, "Ctrl-") { s = s[5:] } return fmt.Sprintf("%s+%s", strings.Join(m, "+"), s) } return s }
[ "func", "(", "ev", "*", "EventKey", ")", "Name", "(", ")", "string", "{", "s", ":=", "\"", "\"", "\n", "m", ":=", "[", "]", "string", "{", "}", "\n", "if", "ev", ".", "mod", "&", "ModShift", "!=", "0", "{", "m", "=", "append", "(", "m", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "ev", ".", "mod", "&", "ModAlt", "!=", "0", "{", "m", "=", "append", "(", "m", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "ev", ".", "mod", "&", "ModMeta", "!=", "0", "{", "m", "=", "append", "(", "m", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "ev", ".", "mod", "&", "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", ".", "ch", ")", "+", "\"", "\"", "\n", "}", "else", "{", "s", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ev", ".", "key", ",", "int", "(", "ev", ".", "ch", ")", ")", "\n", "}", "\n", "}", "\n", "if", "len", "(", "m", ")", "!=", "0", "{", "if", "ev", ".", "mod", "&", "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 printable value or the key stroke. This can be used // when printing the event, for example.
[ "Name", "returns", "a", "printable", "value", "or", "the", "key", "stroke", ".", "This", "can", "be", "used", "when", "printing", "the", "event", "for", "example", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/key.go#L206-L237
train
gdamore/tcell
colorfit.go
FindColor
func FindColor(c Color, palette []Color) Color { match := ColorDefault dist := float64(0) r, g, b := c.RGB() c1 := colorful.Color{ R: float64(r) / 255.0, G: float64(g) / 255.0, B: float64(b) / 255.0, } for _, d := range palette { r, g, b = d.RGB() c2 := colorful.Color{ R: float64(r) / 255.0, G: float64(g) / 255.0, B: float64(b) / 255.0, } // CIE94 is more accurate, but really really expensive. nd := c1.DistanceCIE76(c2) if math.IsNaN(nd) { nd = math.Inf(1) } if match == ColorDefault || nd < dist { match = d dist = nd } } return match }
go
func FindColor(c Color, palette []Color) Color { match := ColorDefault dist := float64(0) r, g, b := c.RGB() c1 := colorful.Color{ R: float64(r) / 255.0, G: float64(g) / 255.0, B: float64(b) / 255.0, } for _, d := range palette { r, g, b = d.RGB() c2 := colorful.Color{ R: float64(r) / 255.0, G: float64(g) / 255.0, B: float64(b) / 255.0, } // CIE94 is more accurate, but really really expensive. nd := c1.DistanceCIE76(c2) if math.IsNaN(nd) { nd = math.Inf(1) } if match == ColorDefault || nd < dist { match = d dist = nd } } return match }
[ "func", "FindColor", "(", "c", "Color", ",", "palette", "[", "]", "Color", ")", "Color", "{", "match", ":=", "ColorDefault", "\n", "dist", ":=", "float64", "(", "0", ")", "\n", "r", ",", "g", ",", "b", ":=", "c", ".", "RGB", "(", ")", "\n", "c1", ":=", "colorful", ".", "Color", "{", "R", ":", "float64", "(", "r", ")", "/", "255.0", ",", "G", ":", "float64", "(", "g", ")", "/", "255.0", ",", "B", ":", "float64", "(", "b", ")", "/", "255.0", ",", "}", "\n", "for", "_", ",", "d", ":=", "range", "palette", "{", "r", ",", "g", ",", "b", "=", "d", ".", "RGB", "(", ")", "\n", "c2", ":=", "colorful", ".", "Color", "{", "R", ":", "float64", "(", "r", ")", "/", "255.0", ",", "G", ":", "float64", "(", "g", ")", "/", "255.0", ",", "B", ":", "float64", "(", "b", ")", "/", "255.0", ",", "}", "\n", "// CIE94 is more accurate, but really really expensive.", "nd", ":=", "c1", ".", "DistanceCIE76", "(", "c2", ")", "\n", "if", "math", ".", "IsNaN", "(", "nd", ")", "{", "nd", "=", "math", ".", "Inf", "(", "1", ")", "\n", "}", "\n", "if", "match", "==", "ColorDefault", "||", "nd", "<", "dist", "{", "match", "=", "d", "\n", "dist", "=", "nd", "\n", "}", "\n", "}", "\n", "return", "match", "\n", "}" ]
// FindColor attempts to find a given color, or the best match possible for it, // from the palette given. This is an expensive operation, so results should // be cached by the caller.
[ "FindColor", "attempts", "to", "find", "a", "given", "color", "or", "the", "best", "match", "possible", "for", "it", "from", "the", "palette", "given", ".", "This", "is", "an", "expensive", "operation", "so", "results", "should", "be", "cached", "by", "the", "caller", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/colorfit.go#L25-L52
train
gdamore/tcell
tscreen.go
buildAcsMap
func (t *tScreen) buildAcsMap() { acsstr := t.ti.AltChars t.acs = make(map[rune]string) for len(acsstr) > 2 { srcv := acsstr[0] dstv := string(acsstr[1]) if r, ok := vtACSNames[srcv]; ok { t.acs[r] = t.ti.EnterAcs + dstv + t.ti.ExitAcs } acsstr = acsstr[2:] } }
go
func (t *tScreen) buildAcsMap() { acsstr := t.ti.AltChars t.acs = make(map[rune]string) for len(acsstr) > 2 { srcv := acsstr[0] dstv := string(acsstr[1]) if r, ok := vtACSNames[srcv]; ok { t.acs[r] = t.ti.EnterAcs + dstv + t.ti.ExitAcs } acsstr = acsstr[2:] } }
[ "func", "(", "t", "*", "tScreen", ")", "buildAcsMap", "(", ")", "{", "acsstr", ":=", "t", ".", "ti", ".", "AltChars", "\n", "t", ".", "acs", "=", "make", "(", "map", "[", "rune", "]", "string", ")", "\n", "for", "len", "(", "acsstr", ")", ">", "2", "{", "srcv", ":=", "acsstr", "[", "0", "]", "\n", "dstv", ":=", "string", "(", "acsstr", "[", "1", "]", ")", "\n", "if", "r", ",", "ok", ":=", "vtACSNames", "[", "srcv", "]", ";", "ok", "{", "t", ".", "acs", "[", "r", "]", "=", "t", ".", "ti", ".", "EnterAcs", "+", "dstv", "+", "t", ".", "ti", ".", "ExitAcs", "\n", "}", "\n", "acsstr", "=", "acsstr", "[", "2", ":", "]", "\n", "}", "\n", "}" ]
// buildAcsMap builds a map of characters that we translate from Unicode to // alternate character encodings. To do this, we use the standard VT100 ACS // maps. This is only done if the terminal lacks support for Unicode; we // always prefer to emit Unicode glyphs when we are able.
[ "buildAcsMap", "builds", "a", "map", "of", "characters", "that", "we", "translate", "from", "Unicode", "to", "alternate", "character", "encodings", ".", "To", "do", "this", "we", "use", "the", "standard", "VT100", "ACS", "maps", ".", "This", "is", "only", "done", "if", "the", "terminal", "lacks", "support", "for", "Unicode", ";", "we", "always", "prefer", "to", "emit", "Unicode", "glyphs", "when", "we", "are", "able", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/tscreen.go#L846-L857
train
gdamore/tcell
tscreen.go
parseXtermMouse
func (t *tScreen) parseXtermMouse(buf *bytes.Buffer) (bool, bool) { b := buf.Bytes() state := 0 btn := 0 x := 0 y := 0 for i := range b { switch state { case 0: switch b[i] { case '\x1b': state = 1 case '\x9b': state = 2 default: return false, false } case 1: if b[i] != '[' { return false, false } state = 2 case 2: if b[i] != 'M' { return false, false } state++ case 3: btn = int(b[i]) state++ case 4: x = int(b[i]) - 32 - 1 state++ case 5: y = int(b[i]) - 32 - 1 for i >= 0 { buf.ReadByte() i-- } t.postMouseEvent(x, y, btn) return true, true } } return true, false }
go
func (t *tScreen) parseXtermMouse(buf *bytes.Buffer) (bool, bool) { b := buf.Bytes() state := 0 btn := 0 x := 0 y := 0 for i := range b { switch state { case 0: switch b[i] { case '\x1b': state = 1 case '\x9b': state = 2 default: return false, false } case 1: if b[i] != '[' { return false, false } state = 2 case 2: if b[i] != 'M' { return false, false } state++ case 3: btn = int(b[i]) state++ case 4: x = int(b[i]) - 32 - 1 state++ case 5: y = int(b[i]) - 32 - 1 for i >= 0 { buf.ReadByte() i-- } t.postMouseEvent(x, y, btn) return true, true } } return true, false }
[ "func", "(", "t", "*", "tScreen", ")", "parseXtermMouse", "(", "buf", "*", "bytes", ".", "Buffer", ")", "(", "bool", ",", "bool", ")", "{", "b", ":=", "buf", ".", "Bytes", "(", ")", "\n\n", "state", ":=", "0", "\n", "btn", ":=", "0", "\n", "x", ":=", "0", "\n", "y", ":=", "0", "\n\n", "for", "i", ":=", "range", "b", "{", "switch", "state", "{", "case", "0", ":", "switch", "b", "[", "i", "]", "{", "case", "'\\x1b'", ":", "state", "=", "1", "\n", "case", "'\\x9b'", ":", "state", "=", "2", "\n", "default", ":", "return", "false", ",", "false", "\n", "}", "\n", "case", "1", ":", "if", "b", "[", "i", "]", "!=", "'['", "{", "return", "false", ",", "false", "\n", "}", "\n", "state", "=", "2", "\n", "case", "2", ":", "if", "b", "[", "i", "]", "!=", "'M'", "{", "return", "false", ",", "false", "\n", "}", "\n", "state", "++", "\n", "case", "3", ":", "btn", "=", "int", "(", "b", "[", "i", "]", ")", "\n", "state", "++", "\n", "case", "4", ":", "x", "=", "int", "(", "b", "[", "i", "]", ")", "-", "32", "-", "1", "\n", "state", "++", "\n", "case", "5", ":", "y", "=", "int", "(", "b", "[", "i", "]", ")", "-", "32", "-", "1", "\n", "for", "i", ">=", "0", "{", "buf", ".", "ReadByte", "(", ")", "\n", "i", "--", "\n", "}", "\n", "t", ".", "postMouseEvent", "(", "x", ",", "y", ",", "btn", ")", "\n", "return", "true", ",", "true", "\n", "}", "\n", "}", "\n", "return", "true", ",", "false", "\n", "}" ]
// parseXtermMouse is like parseSgrMouse, but it parses a legacy // X11 mouse record.
[ "parseXtermMouse", "is", "like", "parseSgrMouse", "but", "it", "parses", "a", "legacy", "X11", "mouse", "record", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/tscreen.go#L1073-L1120
train
gdamore/tcell
views/boxlayout.go
Resize
func (b *BoxLayout) Resize() { b.layout() // Now also let the children know we resized. for i := range b.cells { b.cells[i].widget.Resize() } b.PostEventWidgetResize(b) }
go
func (b *BoxLayout) Resize() { b.layout() // Now also let the children know we resized. for i := range b.cells { b.cells[i].widget.Resize() } b.PostEventWidgetResize(b) }
[ "func", "(", "b", "*", "BoxLayout", ")", "Resize", "(", ")", "{", "b", ".", "layout", "(", ")", "\n\n", "// Now also let the children know we resized.", "for", "i", ":=", "range", "b", ".", "cells", "{", "b", ".", "cells", "[", "i", "]", ".", "widget", ".", "Resize", "(", ")", "\n", "}", "\n", "b", ".", "PostEventWidgetResize", "(", "b", ")", "\n", "}" ]
// Resize adjusts the layout when the underlying View changes size.
[ "Resize", "adjusts", "the", "layout", "when", "the", "underlying", "View", "changes", "size", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/boxlayout.go#L188-L196
train
gdamore/tcell
views/boxlayout.go
Draw
func (b *BoxLayout) Draw() { if b.view == nil { return } if b.changed { b.layout() } b.view.Fill(' ', b.style) for i := range b.cells { b.cells[i].widget.Draw() } }
go
func (b *BoxLayout) Draw() { if b.view == nil { return } if b.changed { b.layout() } b.view.Fill(' ', b.style) for i := range b.cells { b.cells[i].widget.Draw() } }
[ "func", "(", "b", "*", "BoxLayout", ")", "Draw", "(", ")", "{", "if", "b", ".", "view", "==", "nil", "{", "return", "\n", "}", "\n", "if", "b", ".", "changed", "{", "b", ".", "layout", "(", ")", "\n", "}", "\n", "b", ".", "view", ".", "Fill", "(", "' '", ",", "b", ".", "style", ")", "\n", "for", "i", ":=", "range", "b", ".", "cells", "{", "b", ".", "cells", "[", "i", "]", ".", "widget", ".", "Draw", "(", ")", "\n", "}", "\n", "}" ]
// Draw is called to update the displayed content.
[ "Draw", "is", "called", "to", "update", "the", "displayed", "content", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/boxlayout.go#L199-L211
train
gdamore/tcell
views/boxlayout.go
SetView
func (b *BoxLayout) SetView(view View) { b.changed = true b.view = view for _, c := range b.cells { c.view.SetView(view) } }
go
func (b *BoxLayout) SetView(view View) { b.changed = true b.view = view for _, c := range b.cells { c.view.SetView(view) } }
[ "func", "(", "b", "*", "BoxLayout", ")", "SetView", "(", "view", "View", ")", "{", "b", ".", "changed", "=", "true", "\n", "b", ".", "view", "=", "view", "\n", "for", "_", ",", "c", ":=", "range", "b", ".", "cells", "{", "c", ".", "view", ".", "SetView", "(", "view", ")", "\n", "}", "\n", "}" ]
// SetView sets the View object used for the text bar.
[ "SetView", "sets", "the", "View", "object", "used", "for", "the", "text", "bar", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/boxlayout.go#L219-L225
train
gdamore/tcell
views/boxlayout.go
HandleEvent
func (b *BoxLayout) HandleEvent(ev tcell.Event) bool { switch ev.(type) { case *EventWidgetContent: // This can only have come from one of our children. b.changed = true b.PostEventWidgetContent(b) return true } for _, c := range b.cells { if c.widget.HandleEvent(ev) { return true } } return false }
go
func (b *BoxLayout) HandleEvent(ev tcell.Event) bool { switch ev.(type) { case *EventWidgetContent: // This can only have come from one of our children. b.changed = true b.PostEventWidgetContent(b) return true } for _, c := range b.cells { if c.widget.HandleEvent(ev) { return true } } return false }
[ "func", "(", "b", "*", "BoxLayout", ")", "HandleEvent", "(", "ev", "tcell", ".", "Event", ")", "bool", "{", "switch", "ev", ".", "(", "type", ")", "{", "case", "*", "EventWidgetContent", ":", "// This can only have come from one of our children.", "b", ".", "changed", "=", "true", "\n", "b", ".", "PostEventWidgetContent", "(", "b", ")", "\n", "return", "true", "\n", "}", "\n", "for", "_", ",", "c", ":=", "range", "b", ".", "cells", "{", "if", "c", ".", "widget", ".", "HandleEvent", "(", "ev", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// HandleEvent implements a tcell.EventHandler. The only events // we care about are Widget change events from our children. We // watch for those so that if the child changes, we can arrange // to update our layout.
[ "HandleEvent", "implements", "a", "tcell", ".", "EventHandler", ".", "The", "only", "events", "we", "care", "about", "are", "Widget", "change", "events", "from", "our", "children", ".", "We", "watch", "for", "those", "so", "that", "if", "the", "child", "changes", "we", "can", "arrange", "to", "update", "our", "layout", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/boxlayout.go#L231-L245
train
gdamore/tcell
views/boxlayout.go
AddWidget
func (b *BoxLayout) AddWidget(widget Widget, fill float64) { c := &boxLayoutCell{ widget: widget, fill: fill, view: NewViewPort(b.view, 0, 0, 0, 0), } widget.SetView(c.view) b.cells = append(b.cells, c) b.changed = true widget.Watch(b) b.layout() b.PostEventWidgetContent(b) }
go
func (b *BoxLayout) AddWidget(widget Widget, fill float64) { c := &boxLayoutCell{ widget: widget, fill: fill, view: NewViewPort(b.view, 0, 0, 0, 0), } widget.SetView(c.view) b.cells = append(b.cells, c) b.changed = true widget.Watch(b) b.layout() b.PostEventWidgetContent(b) }
[ "func", "(", "b", "*", "BoxLayout", ")", "AddWidget", "(", "widget", "Widget", ",", "fill", "float64", ")", "{", "c", ":=", "&", "boxLayoutCell", "{", "widget", ":", "widget", ",", "fill", ":", "fill", ",", "view", ":", "NewViewPort", "(", "b", ".", "view", ",", "0", ",", "0", ",", "0", ",", "0", ")", ",", "}", "\n", "widget", ".", "SetView", "(", "c", ".", "view", ")", "\n", "b", ".", "cells", "=", "append", "(", "b", ".", "cells", ",", "c", ")", "\n", "b", ".", "changed", "=", "true", "\n", "widget", ".", "Watch", "(", "b", ")", "\n", "b", ".", "layout", "(", ")", "\n", "b", ".", "PostEventWidgetContent", "(", "b", ")", "\n", "}" ]
// AddWidget adds a widget to the end of the BoxLayout.
[ "AddWidget", "adds", "a", "widget", "to", "the", "end", "of", "the", "BoxLayout", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/boxlayout.go#L248-L260
train
gdamore/tcell
views/boxlayout.go
InsertWidget
func (b *BoxLayout) InsertWidget(index int, widget Widget, fill float64) { c := &boxLayoutCell{ widget: widget, fill: fill, view: NewViewPort(b.view, 0, 0, 0, 0), } c.widget.SetView(c.view) if index < 0 { index = 0 } if index > len(b.cells) { index = len(b.cells) } b.cells = append(b.cells, c) copy(b.cells[index+1:], b.cells[index:]) b.cells[index] = c widget.Watch(b) b.layout() b.PostEventWidgetContent(b) }
go
func (b *BoxLayout) InsertWidget(index int, widget Widget, fill float64) { c := &boxLayoutCell{ widget: widget, fill: fill, view: NewViewPort(b.view, 0, 0, 0, 0), } c.widget.SetView(c.view) if index < 0 { index = 0 } if index > len(b.cells) { index = len(b.cells) } b.cells = append(b.cells, c) copy(b.cells[index+1:], b.cells[index:]) b.cells[index] = c widget.Watch(b) b.layout() b.PostEventWidgetContent(b) }
[ "func", "(", "b", "*", "BoxLayout", ")", "InsertWidget", "(", "index", "int", ",", "widget", "Widget", ",", "fill", "float64", ")", "{", "c", ":=", "&", "boxLayoutCell", "{", "widget", ":", "widget", ",", "fill", ":", "fill", ",", "view", ":", "NewViewPort", "(", "b", ".", "view", ",", "0", ",", "0", ",", "0", ",", "0", ")", ",", "}", "\n", "c", ".", "widget", ".", "SetView", "(", "c", ".", "view", ")", "\n", "if", "index", "<", "0", "{", "index", "=", "0", "\n", "}", "\n", "if", "index", ">", "len", "(", "b", ".", "cells", ")", "{", "index", "=", "len", "(", "b", ".", "cells", ")", "\n", "}", "\n", "b", ".", "cells", "=", "append", "(", "b", ".", "cells", ",", "c", ")", "\n", "copy", "(", "b", ".", "cells", "[", "index", "+", "1", ":", "]", ",", "b", ".", "cells", "[", "index", ":", "]", ")", "\n", "b", ".", "cells", "[", "index", "]", "=", "c", "\n", "widget", ".", "Watch", "(", "b", ")", "\n", "b", ".", "layout", "(", ")", "\n", "b", ".", "PostEventWidgetContent", "(", "b", ")", "\n", "}" ]
// InsertWidget inserts a widget at the given offset. Offset 0 is the // front. If the index is longer than the number of widgets, then it // just gets appended to the end.
[ "InsertWidget", "inserts", "a", "widget", "at", "the", "given", "offset", ".", "Offset", "0", "is", "the", "front", ".", "If", "the", "index", "is", "longer", "than", "the", "number", "of", "widgets", "then", "it", "just", "gets", "appended", "to", "the", "end", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/boxlayout.go#L265-L284
train
gdamore/tcell
views/boxlayout.go
RemoveWidget
func (b *BoxLayout) RemoveWidget(widget Widget) { changed := false for i := 0; i < len(b.cells); i++ { if b.cells[i].widget == widget { b.cells = append(b.cells[:i], b.cells[i+1:]...) changed = true } } if !changed { return } b.changed = true widget.Unwatch(b) b.layout() b.PostEventWidgetContent(b) }
go
func (b *BoxLayout) RemoveWidget(widget Widget) { changed := false for i := 0; i < len(b.cells); i++ { if b.cells[i].widget == widget { b.cells = append(b.cells[:i], b.cells[i+1:]...) changed = true } } if !changed { return } b.changed = true widget.Unwatch(b) b.layout() b.PostEventWidgetContent(b) }
[ "func", "(", "b", "*", "BoxLayout", ")", "RemoveWidget", "(", "widget", "Widget", ")", "{", "changed", ":=", "false", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "b", ".", "cells", ")", ";", "i", "++", "{", "if", "b", ".", "cells", "[", "i", "]", ".", "widget", "==", "widget", "{", "b", ".", "cells", "=", "append", "(", "b", ".", "cells", "[", ":", "i", "]", ",", "b", ".", "cells", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "changed", "=", "true", "\n", "}", "\n", "}", "\n", "if", "!", "changed", "{", "return", "\n", "}", "\n", "b", ".", "changed", "=", "true", "\n", "widget", ".", "Unwatch", "(", "b", ")", "\n", "b", ".", "layout", "(", ")", "\n", "b", ".", "PostEventWidgetContent", "(", "b", ")", "\n", "}" ]
// RemoveWidget removes a Widget from the layout.
[ "RemoveWidget", "removes", "a", "Widget", "from", "the", "layout", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/boxlayout.go#L287-L302
train
gdamore/tcell
views/boxlayout.go
Widgets
func (b *BoxLayout) Widgets() []Widget { w := make([]Widget, 0, len(b.cells)) for _, c := range b.cells { w = append(w, c.widget) } return w }
go
func (b *BoxLayout) Widgets() []Widget { w := make([]Widget, 0, len(b.cells)) for _, c := range b.cells { w = append(w, c.widget) } return w }
[ "func", "(", "b", "*", "BoxLayout", ")", "Widgets", "(", ")", "[", "]", "Widget", "{", "w", ":=", "make", "(", "[", "]", "Widget", ",", "0", ",", "len", "(", "b", ".", "cells", ")", ")", "\n", "for", "_", ",", "c", ":=", "range", "b", ".", "cells", "{", "w", "=", "append", "(", "w", ",", "c", ".", "widget", ")", "\n", "}", "\n", "return", "w", "\n", "}" ]
// Widgets returns the list of Widgets for this BoxLayout.
[ "Widgets", "returns", "the", "list", "of", "Widgets", "for", "this", "BoxLayout", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/boxlayout.go#L305-L311
train
gdamore/tcell
views/boxlayout.go
SetOrientation
func (b *BoxLayout) SetOrientation(orient Orientation) { if b.orient != orient { b.orient = orient b.changed = true b.PostEventWidgetContent(b) } }
go
func (b *BoxLayout) SetOrientation(orient Orientation) { if b.orient != orient { b.orient = orient b.changed = true b.PostEventWidgetContent(b) } }
[ "func", "(", "b", "*", "BoxLayout", ")", "SetOrientation", "(", "orient", "Orientation", ")", "{", "if", "b", ".", "orient", "!=", "orient", "{", "b", ".", "orient", "=", "orient", "\n", "b", ".", "changed", "=", "true", "\n", "b", ".", "PostEventWidgetContent", "(", "b", ")", "\n", "}", "\n", "}" ]
// SetOrientation sets the orientation as either Horizontal or Vertical.
[ "SetOrientation", "sets", "the", "orientation", "as", "either", "Horizontal", "or", "Vertical", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/boxlayout.go#L314-L320
train
gdamore/tcell
views/boxlayout.go
SetStyle
func (b *BoxLayout) SetStyle(style tcell.Style) { b.style = style b.PostEventWidgetContent(b) }
go
func (b *BoxLayout) SetStyle(style tcell.Style) { b.style = style b.PostEventWidgetContent(b) }
[ "func", "(", "b", "*", "BoxLayout", ")", "SetStyle", "(", "style", "tcell", ".", "Style", ")", "{", "b", ".", "style", "=", "style", "\n", "b", ".", "PostEventWidgetContent", "(", "b", ")", "\n", "}" ]
// SetStyle sets the style used.
[ "SetStyle", "sets", "the", "style", "used", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/boxlayout.go#L323-L326
train
gdamore/tcell
console_win.go
mod2mask
func mod2mask(cks uint32) ModMask { mm := ModNone // Left or right control if (cks & (0x0008 | 0x0004)) != 0 { mm |= ModCtrl } // Left or right alt if (cks & (0x0002 | 0x0001)) != 0 { mm |= ModAlt } // Any shift if (cks & 0x0010) != 0 { mm |= ModShift } return mm }
go
func mod2mask(cks uint32) ModMask { mm := ModNone // Left or right control if (cks & (0x0008 | 0x0004)) != 0 { mm |= ModCtrl } // Left or right alt if (cks & (0x0002 | 0x0001)) != 0 { mm |= ModAlt } // Any shift if (cks & 0x0010) != 0 { mm |= ModShift } return mm }
[ "func", "mod2mask", "(", "cks", "uint32", ")", "ModMask", "{", "mm", ":=", "ModNone", "\n", "// Left or right control", "if", "(", "cks", "&", "(", "0x0008", "|", "0x0004", ")", ")", "!=", "0", "{", "mm", "|=", "ModCtrl", "\n", "}", "\n", "// Left or right alt", "if", "(", "cks", "&", "(", "0x0002", "|", "0x0001", ")", ")", "!=", "0", "{", "mm", "|=", "ModAlt", "\n", "}", "\n", "// Any shift", "if", "(", "cks", "&", "0x0010", ")", "!=", "0", "{", "mm", "|=", "ModShift", "\n", "}", "\n", "return", "mm", "\n", "}" ]
// Convert windows dwControlKeyState to modifier mask
[ "Convert", "windows", "dwControlKeyState", "to", "modifier", "mask" ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/console_win.go#L459-L474
train
gdamore/tcell
console_win.go
mapColor2RGB
func mapColor2RGB(c Color) uint16 { winLock.Lock() if v, ok := winColors[c]; ok { c = v } else { v = FindColor(c, winPalette) winColors[c] = v c = v } winLock.Unlock() if vc, ok := vgaColors[c]; ok { return vc } return 0 }
go
func mapColor2RGB(c Color) uint16 { winLock.Lock() if v, ok := winColors[c]; ok { c = v } else { v = FindColor(c, winPalette) winColors[c] = v c = v } winLock.Unlock() if vc, ok := vgaColors[c]; ok { return vc } return 0 }
[ "func", "mapColor2RGB", "(", "c", "Color", ")", "uint16", "{", "winLock", ".", "Lock", "(", ")", "\n", "if", "v", ",", "ok", ":=", "winColors", "[", "c", "]", ";", "ok", "{", "c", "=", "v", "\n", "}", "else", "{", "v", "=", "FindColor", "(", "c", ",", "winPalette", ")", "\n", "winColors", "[", "c", "]", "=", "v", "\n", "c", "=", "v", "\n", "}", "\n", "winLock", ".", "Unlock", "(", ")", "\n\n", "if", "vc", ",", "ok", ":=", "vgaColors", "[", "c", "]", ";", "ok", "{", "return", "vc", "\n", "}", "\n", "return", "0", "\n", "}" ]
// Windows uses RGB signals
[ "Windows", "uses", "RGB", "signals" ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/console_win.go#L652-L667
train
gdamore/tcell
console_win.go
mapStyle
func (s *cScreen) mapStyle(style Style) uint16 { f, b, a := style.Decompose() fa := s.oscreen.attrs & 0xf ba := (s.oscreen.attrs) >> 4 & 0xf if f != ColorDefault { fa = mapColor2RGB(f) } if b != ColorDefault { ba = mapColor2RGB(b) } var attr uint16 // We simulate reverse by doing the color swap ourselves. // Apparently windows cannot really do this except in DBCS // views. if a&AttrReverse != 0 { attr = ba attr |= (fa << 4) } else { attr = fa attr |= (ba << 4) } if a&AttrBold != 0 { attr |= 0x8 } if a&AttrDim != 0 { attr &^= 0x8 } if a&AttrUnderline != 0 { // Best effort -- doesn't seem to work though. attr |= 0x8000 } // Blink is unsupported return attr }
go
func (s *cScreen) mapStyle(style Style) uint16 { f, b, a := style.Decompose() fa := s.oscreen.attrs & 0xf ba := (s.oscreen.attrs) >> 4 & 0xf if f != ColorDefault { fa = mapColor2RGB(f) } if b != ColorDefault { ba = mapColor2RGB(b) } var attr uint16 // We simulate reverse by doing the color swap ourselves. // Apparently windows cannot really do this except in DBCS // views. if a&AttrReverse != 0 { attr = ba attr |= (fa << 4) } else { attr = fa attr |= (ba << 4) } if a&AttrBold != 0 { attr |= 0x8 } if a&AttrDim != 0 { attr &^= 0x8 } if a&AttrUnderline != 0 { // Best effort -- doesn't seem to work though. attr |= 0x8000 } // Blink is unsupported return attr }
[ "func", "(", "s", "*", "cScreen", ")", "mapStyle", "(", "style", "Style", ")", "uint16", "{", "f", ",", "b", ",", "a", ":=", "style", ".", "Decompose", "(", ")", "\n", "fa", ":=", "s", ".", "oscreen", ".", "attrs", "&", "0xf", "\n", "ba", ":=", "(", "s", ".", "oscreen", ".", "attrs", ")", ">>", "4", "&", "0xf", "\n", "if", "f", "!=", "ColorDefault", "{", "fa", "=", "mapColor2RGB", "(", "f", ")", "\n", "}", "\n", "if", "b", "!=", "ColorDefault", "{", "ba", "=", "mapColor2RGB", "(", "b", ")", "\n", "}", "\n", "var", "attr", "uint16", "\n", "// We simulate reverse by doing the color swap ourselves.", "// Apparently windows cannot really do this except in DBCS", "// views.", "if", "a", "&", "AttrReverse", "!=", "0", "{", "attr", "=", "ba", "\n", "attr", "|=", "(", "fa", "<<", "4", ")", "\n", "}", "else", "{", "attr", "=", "fa", "\n", "attr", "|=", "(", "ba", "<<", "4", ")", "\n", "}", "\n", "if", "a", "&", "AttrBold", "!=", "0", "{", "attr", "|=", "0x8", "\n", "}", "\n", "if", "a", "&", "AttrDim", "!=", "0", "{", "attr", "&^=", "0x8", "\n", "}", "\n", "if", "a", "&", "AttrUnderline", "!=", "0", "{", "// Best effort -- doesn't seem to work though.", "attr", "|=", "0x8000", "\n", "}", "\n", "// Blink is unsupported", "return", "attr", "\n", "}" ]
// Map a tcell style to Windows attributes
[ "Map", "a", "tcell", "style", "to", "Windows", "attributes" ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/console_win.go#L670-L703
train
gdamore/tcell
views/sstext.go
LookupStyle
func (t *SimpleStyledText) LookupStyle(r rune) tcell.Style { return t.styles[r] }
go
func (t *SimpleStyledText) LookupStyle(r rune) tcell.Style { return t.styles[r] }
[ "func", "(", "t", "*", "SimpleStyledText", ")", "LookupStyle", "(", "r", "rune", ")", "tcell", ".", "Style", "{", "return", "t", ".", "styles", "[", "r", "]", "\n", "}" ]
// LookupStyle returns the style registered for the given rune. // Returns tcell.StyleDefault if no style was previously registered // for the rune.
[ "LookupStyle", "returns", "the", "style", "registered", "for", "the", "given", "rune", ".", "Returns", "tcell", ".", "StyleDefault", "if", "no", "style", "was", "previously", "registered", "for", "the", "rune", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/sstext.go#L107-L109
train
gdamore/tcell
views/sstext.go
NewSimpleStyledText
func NewSimpleStyledText() *SimpleStyledText { ss := &SimpleStyledText{} // Create map and establish default styles. ss.styles = make(map[rune]tcell.Style) ss.styles['N'] = tcell.StyleDefault ss.styles['S'] = tcell.StyleDefault.Reverse(true) ss.styles['U'] = tcell.StyleDefault.Underline(true) ss.styles['B'] = tcell.StyleDefault.Bold(true) return ss }
go
func NewSimpleStyledText() *SimpleStyledText { ss := &SimpleStyledText{} // Create map and establish default styles. ss.styles = make(map[rune]tcell.Style) ss.styles['N'] = tcell.StyleDefault ss.styles['S'] = tcell.StyleDefault.Reverse(true) ss.styles['U'] = tcell.StyleDefault.Underline(true) ss.styles['B'] = tcell.StyleDefault.Bold(true) return ss }
[ "func", "NewSimpleStyledText", "(", ")", "*", "SimpleStyledText", "{", "ss", ":=", "&", "SimpleStyledText", "{", "}", "\n", "// Create map and establish default styles.", "ss", ".", "styles", "=", "make", "(", "map", "[", "rune", "]", "tcell", ".", "Style", ")", "\n", "ss", ".", "styles", "[", "'N'", "]", "=", "tcell", ".", "StyleDefault", "\n", "ss", ".", "styles", "[", "'S'", "]", "=", "tcell", ".", "StyleDefault", ".", "Reverse", "(", "true", ")", "\n", "ss", ".", "styles", "[", "'U'", "]", "=", "tcell", ".", "StyleDefault", ".", "Underline", "(", "true", ")", "\n", "ss", ".", "styles", "[", "'B'", "]", "=", "tcell", ".", "StyleDefault", ".", "Bold", "(", "true", ")", "\n", "return", "ss", "\n", "}" ]
// NewSimpleStyledText creates an empty Text.
[ "NewSimpleStyledText", "creates", "an", "empty", "Text", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/sstext.go#L117-L126
train
gdamore/tcell
views/panel.go
Draw
func (p *Panel) Draw() { p.BoxLayout.SetOrientation(Vertical) p.BoxLayout.Draw() }
go
func (p *Panel) Draw() { p.BoxLayout.SetOrientation(Vertical) p.BoxLayout.Draw() }
[ "func", "(", "p", "*", "Panel", ")", "Draw", "(", ")", "{", "p", ".", "BoxLayout", ".", "SetOrientation", "(", "Vertical", ")", "\n", "p", ".", "BoxLayout", ".", "Draw", "(", ")", "\n", "}" ]
// Draw draws the Panel.
[ "Draw", "draws", "the", "Panel", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/panel.go#L44-L47
train
gdamore/tcell
views/panel.go
SetTitle
func (p *Panel) SetTitle(w Widget) { if p.title != nil { p.RemoveWidget(p.title) } p.InsertWidget(0, w, 0.0) p.title = w }
go
func (p *Panel) SetTitle(w Widget) { if p.title != nil { p.RemoveWidget(p.title) } p.InsertWidget(0, w, 0.0) p.title = w }
[ "func", "(", "p", "*", "Panel", ")", "SetTitle", "(", "w", "Widget", ")", "{", "if", "p", ".", "title", "!=", "nil", "{", "p", ".", "RemoveWidget", "(", "p", ".", "title", ")", "\n", "}", "\n", "p", ".", "InsertWidget", "(", "0", ",", "w", ",", "0.0", ")", "\n", "p", ".", "title", "=", "w", "\n", "}" ]
// SetTitle sets the Widget to display in the title area.
[ "SetTitle", "sets", "the", "Widget", "to", "display", "in", "the", "title", "area", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/panel.go#L50-L56
train
gdamore/tcell
views/panel.go
SetMenu
func (p *Panel) SetMenu(w Widget) { index := 0 if p.title != nil { index++ } if p.menu != nil { p.RemoveWidget(p.menu) } p.InsertWidget(index, w, 0.0) p.menu = w }
go
func (p *Panel) SetMenu(w Widget) { index := 0 if p.title != nil { index++ } if p.menu != nil { p.RemoveWidget(p.menu) } p.InsertWidget(index, w, 0.0) p.menu = w }
[ "func", "(", "p", "*", "Panel", ")", "SetMenu", "(", "w", "Widget", ")", "{", "index", ":=", "0", "\n", "if", "p", ".", "title", "!=", "nil", "{", "index", "++", "\n", "}", "\n", "if", "p", ".", "menu", "!=", "nil", "{", "p", ".", "RemoveWidget", "(", "p", ".", "menu", ")", "\n", "}", "\n", "p", ".", "InsertWidget", "(", "index", ",", "w", ",", "0.0", ")", "\n", "p", ".", "menu", "=", "w", "\n", "}" ]
// SetMenu sets the Widget to display in the menu area, which is // just below the title.
[ "SetMenu", "sets", "the", "Widget", "to", "display", "in", "the", "menu", "area", "which", "is", "just", "below", "the", "title", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/panel.go#L60-L70
train
gdamore/tcell
views/panel.go
SetContent
func (p *Panel) SetContent(w Widget) { index := 0 if p.title != nil { index++ } if p.menu != nil { index++ } if p.content != nil { p.RemoveWidget(p.content) } p.InsertWidget(index, w, 1.0) p.content = w }
go
func (p *Panel) SetContent(w Widget) { index := 0 if p.title != nil { index++ } if p.menu != nil { index++ } if p.content != nil { p.RemoveWidget(p.content) } p.InsertWidget(index, w, 1.0) p.content = w }
[ "func", "(", "p", "*", "Panel", ")", "SetContent", "(", "w", "Widget", ")", "{", "index", ":=", "0", "\n", "if", "p", ".", "title", "!=", "nil", "{", "index", "++", "\n", "}", "\n", "if", "p", ".", "menu", "!=", "nil", "{", "index", "++", "\n", "}", "\n", "if", "p", ".", "content", "!=", "nil", "{", "p", ".", "RemoveWidget", "(", "p", ".", "content", ")", "\n", "}", "\n", "p", ".", "InsertWidget", "(", "index", ",", "w", ",", "1.0", ")", "\n", "p", ".", "content", "=", "w", "\n", "}" ]
// SetContent sets the Widget to display in the content area.
[ "SetContent", "sets", "the", "Widget", "to", "display", "in", "the", "content", "area", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/panel.go#L73-L86
train
gdamore/tcell
views/panel.go
SetStatus
func (p *Panel) SetStatus(w Widget) { index := 0 if p.title != nil { index++ } if p.menu != nil { index++ } if p.content != nil { index++ } if p.status != nil { p.RemoveWidget(p.status) } p.InsertWidget(index, w, 0.0) p.status = w }
go
func (p *Panel) SetStatus(w Widget) { index := 0 if p.title != nil { index++ } if p.menu != nil { index++ } if p.content != nil { index++ } if p.status != nil { p.RemoveWidget(p.status) } p.InsertWidget(index, w, 0.0) p.status = w }
[ "func", "(", "p", "*", "Panel", ")", "SetStatus", "(", "w", "Widget", ")", "{", "index", ":=", "0", "\n", "if", "p", ".", "title", "!=", "nil", "{", "index", "++", "\n", "}", "\n", "if", "p", ".", "menu", "!=", "nil", "{", "index", "++", "\n", "}", "\n", "if", "p", ".", "content", "!=", "nil", "{", "index", "++", "\n", "}", "\n", "if", "p", ".", "status", "!=", "nil", "{", "p", ".", "RemoveWidget", "(", "p", ".", "status", ")", "\n", "}", "\n", "p", ".", "InsertWidget", "(", "index", ",", "w", ",", "0.0", ")", "\n", "p", ".", "status", "=", "w", "\n", "}" ]
// SetStatus sets the Widget to display in the status area, which is at // the bottom of the panel.
[ "SetStatus", "sets", "the", "Widget", "to", "display", "in", "the", "status", "area", "which", "is", "at", "the", "bottom", "of", "the", "panel", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/panel.go#L90-L106
train
gdamore/tcell
views/cellarea.go
Draw
func (a *CellView) Draw() { port := a.port model := a.model port.Fill(' ', a.style) if a.view == nil { return } if model == nil { return } vw, vh := a.view.Size() for y := 0; y < vh; y++ { for x := 0; x < vw; x++ { a.view.SetContent(x, y, ' ', nil, a.style) } } ex, ey := model.GetBounds() vx, vy := port.Size() if ex < vx { ex = vx } if ey < vy { ey = vy } cx, cy, en, sh := a.model.GetCursor() for y := 0; y < ey; y++ { for x := 0; x < ex; x++ { ch, style, comb, wid := model.GetCell(x, y) if ch == 0 { ch = ' ' style = a.style } if en && x == cx && y == cy && sh { style = style.Reverse(true) } port.SetContent(x, y, ch, comb, style) x += wid - 1 } } }
go
func (a *CellView) Draw() { port := a.port model := a.model port.Fill(' ', a.style) if a.view == nil { return } if model == nil { return } vw, vh := a.view.Size() for y := 0; y < vh; y++ { for x := 0; x < vw; x++ { a.view.SetContent(x, y, ' ', nil, a.style) } } ex, ey := model.GetBounds() vx, vy := port.Size() if ex < vx { ex = vx } if ey < vy { ey = vy } cx, cy, en, sh := a.model.GetCursor() for y := 0; y < ey; y++ { for x := 0; x < ex; x++ { ch, style, comb, wid := model.GetCell(x, y) if ch == 0 { ch = ' ' style = a.style } if en && x == cx && y == cy && sh { style = style.Reverse(true) } port.SetContent(x, y, ch, comb, style) x += wid - 1 } } }
[ "func", "(", "a", "*", "CellView", ")", "Draw", "(", ")", "{", "port", ":=", "a", ".", "port", "\n", "model", ":=", "a", ".", "model", "\n", "port", ".", "Fill", "(", "' '", ",", "a", ".", "style", ")", "\n\n", "if", "a", ".", "view", "==", "nil", "{", "return", "\n", "}", "\n", "if", "model", "==", "nil", "{", "return", "\n", "}", "\n", "vw", ",", "vh", ":=", "a", ".", "view", ".", "Size", "(", ")", "\n", "for", "y", ":=", "0", ";", "y", "<", "vh", ";", "y", "++", "{", "for", "x", ":=", "0", ";", "x", "<", "vw", ";", "x", "++", "{", "a", ".", "view", ".", "SetContent", "(", "x", ",", "y", ",", "' '", ",", "nil", ",", "a", ".", "style", ")", "\n", "}", "\n", "}", "\n\n", "ex", ",", "ey", ":=", "model", ".", "GetBounds", "(", ")", "\n", "vx", ",", "vy", ":=", "port", ".", "Size", "(", ")", "\n", "if", "ex", "<", "vx", "{", "ex", "=", "vx", "\n", "}", "\n", "if", "ey", "<", "vy", "{", "ey", "=", "vy", "\n", "}", "\n\n", "cx", ",", "cy", ",", "en", ",", "sh", ":=", "a", ".", "model", ".", "GetCursor", "(", ")", "\n", "for", "y", ":=", "0", ";", "y", "<", "ey", ";", "y", "++", "{", "for", "x", ":=", "0", ";", "x", "<", "ex", ";", "x", "++", "{", "ch", ",", "style", ",", "comb", ",", "wid", ":=", "model", ".", "GetCell", "(", "x", ",", "y", ")", "\n", "if", "ch", "==", "0", "{", "ch", "=", "' '", "\n", "style", "=", "a", ".", "style", "\n", "}", "\n", "if", "en", "&&", "x", "==", "cx", "&&", "y", "==", "cy", "&&", "sh", "{", "style", "=", "style", ".", "Reverse", "(", "true", ")", "\n", "}", "\n", "port", ".", "SetContent", "(", "x", ",", "y", ",", "ch", ",", "comb", ",", "style", ")", "\n", "x", "+=", "wid", "-", "1", "\n", "}", "\n", "}", "\n", "}" ]
// Draw draws the content.
[ "Draw", "draws", "the", "content", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L51-L94
train
gdamore/tcell
views/cellarea.go
MakeCursorVisible
func (a *CellView) MakeCursorVisible() { if a.model == nil { return } x, y, enabled, _ := a.model.GetCursor() if enabled { a.MakeVisible(x, y) } }
go
func (a *CellView) MakeCursorVisible() { if a.model == nil { return } x, y, enabled, _ := a.model.GetCursor() if enabled { a.MakeVisible(x, y) } }
[ "func", "(", "a", "*", "CellView", ")", "MakeCursorVisible", "(", ")", "{", "if", "a", ".", "model", "==", "nil", "{", "return", "\n", "}", "\n", "x", ",", "y", ",", "enabled", ",", "_", ":=", "a", ".", "model", ".", "GetCursor", "(", ")", "\n", "if", "enabled", "{", "a", ".", "MakeVisible", "(", "x", ",", "y", ")", "\n", "}", "\n", "}" ]
// MakeCursorVisible ensures that the cursor is visible, panning the ViewPort // as necessary, if the cursor is enabled.
[ "MakeCursorVisible", "ensures", "that", "the", "cursor", "is", "visible", "panning", "the", "ViewPort", "as", "necessary", "if", "the", "cursor", "is", "enabled", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L176-L184
train
gdamore/tcell
views/cellarea.go
HandleEvent
func (a *CellView) HandleEvent(e tcell.Event) bool { if a.model == nil { return false } switch e := e.(type) { case *tcell.EventKey: switch e.Key() { case tcell.KeyUp, tcell.KeyCtrlP: a.keyUp() return true case tcell.KeyDown, tcell.KeyCtrlN: a.keyDown() return true case tcell.KeyRight, tcell.KeyCtrlF: a.keyRight() return true case tcell.KeyLeft, tcell.KeyCtrlB: a.keyLeft() return true case tcell.KeyPgDn: a.keyPgDn() return true case tcell.KeyPgUp: a.keyPgUp() return true case tcell.KeyEnd: a.keyEnd() return true case tcell.KeyHome: a.keyHome() return true } } return false }
go
func (a *CellView) HandleEvent(e tcell.Event) bool { if a.model == nil { return false } switch e := e.(type) { case *tcell.EventKey: switch e.Key() { case tcell.KeyUp, tcell.KeyCtrlP: a.keyUp() return true case tcell.KeyDown, tcell.KeyCtrlN: a.keyDown() return true case tcell.KeyRight, tcell.KeyCtrlF: a.keyRight() return true case tcell.KeyLeft, tcell.KeyCtrlB: a.keyLeft() return true case tcell.KeyPgDn: a.keyPgDn() return true case tcell.KeyPgUp: a.keyPgUp() return true case tcell.KeyEnd: a.keyEnd() return true case tcell.KeyHome: a.keyHome() return true } } return false }
[ "func", "(", "a", "*", "CellView", ")", "HandleEvent", "(", "e", "tcell", ".", "Event", ")", "bool", "{", "if", "a", ".", "model", "==", "nil", "{", "return", "false", "\n", "}", "\n", "switch", "e", ":=", "e", ".", "(", "type", ")", "{", "case", "*", "tcell", ".", "EventKey", ":", "switch", "e", ".", "Key", "(", ")", "{", "case", "tcell", ".", "KeyUp", ",", "tcell", ".", "KeyCtrlP", ":", "a", ".", "keyUp", "(", ")", "\n", "return", "true", "\n", "case", "tcell", ".", "KeyDown", ",", "tcell", ".", "KeyCtrlN", ":", "a", ".", "keyDown", "(", ")", "\n", "return", "true", "\n", "case", "tcell", ".", "KeyRight", ",", "tcell", ".", "KeyCtrlF", ":", "a", ".", "keyRight", "(", ")", "\n", "return", "true", "\n", "case", "tcell", ".", "KeyLeft", ",", "tcell", ".", "KeyCtrlB", ":", "a", ".", "keyLeft", "(", ")", "\n", "return", "true", "\n", "case", "tcell", ".", "KeyPgDn", ":", "a", ".", "keyPgDn", "(", ")", "\n", "return", "true", "\n", "case", "tcell", ".", "KeyPgUp", ":", "a", ".", "keyPgUp", "(", ")", "\n", "return", "true", "\n", "case", "tcell", ".", "KeyEnd", ":", "a", ".", "keyEnd", "(", ")", "\n", "return", "true", "\n", "case", "tcell", ".", "KeyHome", ":", "a", ".", "keyHome", "(", ")", "\n", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// HandleEvent handles events. In particular, it handles certain key events // to move the cursor or pan the view.
[ "HandleEvent", "handles", "events", ".", "In", "particular", "it", "handles", "certain", "key", "events", "to", "move", "the", "cursor", "or", "pan", "the", "view", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L188-L222
train
gdamore/tcell
views/cellarea.go
Size
func (a *CellView) Size() (int, int) { // We always return a minimum of two rows, and two columns. w, h := a.model.GetBounds() // Clip to a 2x2 minimum square; we can scroll within that. if w > 2 { w = 2 } if h > 2 { h = 2 } return w, h }
go
func (a *CellView) Size() (int, int) { // We always return a minimum of two rows, and two columns. w, h := a.model.GetBounds() // Clip to a 2x2 minimum square; we can scroll within that. if w > 2 { w = 2 } if h > 2 { h = 2 } return w, h }
[ "func", "(", "a", "*", "CellView", ")", "Size", "(", ")", "(", "int", ",", "int", ")", "{", "// We always return a minimum of two rows, and two columns.", "w", ",", "h", ":=", "a", ".", "model", ".", "GetBounds", "(", ")", "\n", "// Clip to a 2x2 minimum square; we can scroll within that.", "if", "w", ">", "2", "{", "w", "=", "2", "\n", "}", "\n", "if", "h", ">", "2", "{", "h", "=", "2", "\n", "}", "\n", "return", "w", ",", "h", "\n", "}" ]
// Size returns the content size, based on the model.
[ "Size", "returns", "the", "content", "size", "based", "on", "the", "model", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L225-L236
train
gdamore/tcell
views/cellarea.go
SetModel
func (a *CellView) SetModel(model CellModel) { w, h := model.GetBounds() model.SetCursor(0, 0) a.model = model a.port.SetContentSize(w, h, true) a.port.ValidateView() a.PostEventWidgetContent(a) }
go
func (a *CellView) SetModel(model CellModel) { w, h := model.GetBounds() model.SetCursor(0, 0) a.model = model a.port.SetContentSize(w, h, true) a.port.ValidateView() a.PostEventWidgetContent(a) }
[ "func", "(", "a", "*", "CellView", ")", "SetModel", "(", "model", "CellModel", ")", "{", "w", ",", "h", ":=", "model", ".", "GetBounds", "(", ")", "\n", "model", ".", "SetCursor", "(", "0", ",", "0", ")", "\n", "a", ".", "model", "=", "model", "\n", "a", ".", "port", ".", "SetContentSize", "(", "w", ",", "h", ",", "true", ")", "\n", "a", ".", "port", ".", "ValidateView", "(", ")", "\n", "a", ".", "PostEventWidgetContent", "(", "a", ")", "\n", "}" ]
// SetModel sets the model for this CellView.
[ "SetModel", "sets", "the", "model", "for", "this", "CellView", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L239-L246
train
gdamore/tcell
views/cellarea.go
SetView
func (a *CellView) SetView(view View) { port := a.port port.SetView(view) a.view = view if view == nil { return } width, height := view.Size() a.port.Resize(0, 0, width, height) if a.model != nil { w, h := a.model.GetBounds() a.port.SetContentSize(w, h, true) } a.Resize() }
go
func (a *CellView) SetView(view View) { port := a.port port.SetView(view) a.view = view if view == nil { return } width, height := view.Size() a.port.Resize(0, 0, width, height) if a.model != nil { w, h := a.model.GetBounds() a.port.SetContentSize(w, h, true) } a.Resize() }
[ "func", "(", "a", "*", "CellView", ")", "SetView", "(", "view", "View", ")", "{", "port", ":=", "a", ".", "port", "\n", "port", ".", "SetView", "(", "view", ")", "\n", "a", ".", "view", "=", "view", "\n", "if", "view", "==", "nil", "{", "return", "\n", "}", "\n", "width", ",", "height", ":=", "view", ".", "Size", "(", ")", "\n", "a", ".", "port", ".", "Resize", "(", "0", ",", "0", ",", "width", ",", "height", ")", "\n", "if", "a", ".", "model", "!=", "nil", "{", "w", ",", "h", ":=", "a", ".", "model", ".", "GetBounds", "(", ")", "\n", "a", ".", "port", ".", "SetContentSize", "(", "w", ",", "h", ",", "true", ")", "\n", "}", "\n", "a", ".", "Resize", "(", ")", "\n", "}" ]
// SetView sets the View context.
[ "SetView", "sets", "the", "View", "context", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L249-L263
train
gdamore/tcell
views/cellarea.go
Resize
func (a *CellView) Resize() { // We might want to reflow text width, height := a.view.Size() a.port.Resize(0, 0, width, height) a.port.ValidateView() a.MakeCursorVisible() }
go
func (a *CellView) Resize() { // We might want to reflow text width, height := a.view.Size() a.port.Resize(0, 0, width, height) a.port.ValidateView() a.MakeCursorVisible() }
[ "func", "(", "a", "*", "CellView", ")", "Resize", "(", ")", "{", "// We might want to reflow text", "width", ",", "height", ":=", "a", ".", "view", ".", "Size", "(", ")", "\n", "a", ".", "port", ".", "Resize", "(", "0", ",", "0", ",", "width", ",", "height", ")", "\n", "a", ".", "port", ".", "ValidateView", "(", ")", "\n", "a", ".", "MakeCursorVisible", "(", ")", "\n", "}" ]
// Resize is called when the View is resized. It will ensure that the // cursor is visible, if present.
[ "Resize", "is", "called", "when", "the", "View", "is", "resized", ".", "It", "will", "ensure", "that", "the", "cursor", "is", "visible", "if", "present", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L267-L273
train
gdamore/tcell
views/cellarea.go
SetCursor
func (a *CellView) SetCursor(x, y int) { a.cursorX = x a.cursorY = y a.model.SetCursor(x, y) }
go
func (a *CellView) SetCursor(x, y int) { a.cursorX = x a.cursorY = y a.model.SetCursor(x, y) }
[ "func", "(", "a", "*", "CellView", ")", "SetCursor", "(", "x", ",", "y", "int", ")", "{", "a", ".", "cursorX", "=", "x", "\n", "a", ".", "cursorY", "=", "y", "\n", "a", ".", "model", ".", "SetCursor", "(", "x", ",", "y", ")", "\n", "}" ]
// SetCursor sets the the cursor position.
[ "SetCursor", "sets", "the", "the", "cursor", "position", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L276-L280
train
gdamore/tcell
views/cellarea.go
SetCursorX
func (a *CellView) SetCursorX(x int) { a.SetCursor(x, a.cursorY) }
go
func (a *CellView) SetCursorX(x int) { a.SetCursor(x, a.cursorY) }
[ "func", "(", "a", "*", "CellView", ")", "SetCursorX", "(", "x", "int", ")", "{", "a", ".", "SetCursor", "(", "x", ",", "a", ".", "cursorY", ")", "\n", "}" ]
// SetCursorX sets the the cursor column.
[ "SetCursorX", "sets", "the", "the", "cursor", "column", "." ]
dcf1bb30770eb1158b67005e1e472de6d74f055d
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L283-L285
train