repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
kubernetes-retired/heapster
metrics/api/v1/historical_handlers.go
nodeAggregations
func (a *HistoricalApi) nodeAggregations(request *restful.Request, response *restful.Response) { key := core.HistoricalKey{ ObjectType: core.MetricSetTypeNode, NodeName: request.PathParameter("node-name"), } a.processAggregationRequest(key, request, response) }
go
func (a *HistoricalApi) nodeAggregations(request *restful.Request, response *restful.Response) { key := core.HistoricalKey{ ObjectType: core.MetricSetTypeNode, NodeName: request.PathParameter("node-name"), } a.processAggregationRequest(key, request, response) }
[ "func", "(", "a", "*", "HistoricalApi", ")", "nodeAggregations", "(", "request", "*", "restful", ".", "Request", ",", "response", "*", "restful", ".", "Response", ")", "{", "key", ":=", "core", ".", "HistoricalKey", "{", "ObjectType", ":", "core", ".", "MetricSetTypeNode", ",", "NodeName", ":", "request", ".", "PathParameter", "(", "\"node-name\"", ")", ",", "}", "\n", "a", ".", "processAggregationRequest", "(", "key", ",", "request", ",", "response", ")", "\n", "}" ]
// nodeAggregations returns a metric timeseries for a metric of the Node entity.
[ "nodeAggregations", "returns", "a", "metric", "timeseries", "for", "a", "metric", "of", "the", "Node", "entity", "." ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L488-L494
train
kubernetes-retired/heapster
metrics/api/v1/historical_handlers.go
namespaceAggregations
func (a *HistoricalApi) namespaceAggregations(request *restful.Request, response *restful.Response) { key := core.HistoricalKey{ ObjectType: core.MetricSetTypeNamespace, NamespaceName: request.PathParameter("namespace-name"), } a.processAggregationRequest(key, request, response) }
go
func (a *HistoricalApi) namespaceAggregations(request *restful.Request, response *restful.Response) { key := core.HistoricalKey{ ObjectType: core.MetricSetTypeNamespace, NamespaceName: request.PathParameter("namespace-name"), } a.processAggregationRequest(key, request, response) }
[ "func", "(", "a", "*", "HistoricalApi", ")", "namespaceAggregations", "(", "request", "*", "restful", ".", "Request", ",", "response", "*", "restful", ".", "Response", ")", "{", "key", ":=", "core", ".", "HistoricalKey", "{", "ObjectType", ":", "core", ".", "MetricSetTypeNamespace", ",", "NamespaceName", ":", "request", ".", "PathParameter", "(", "\"namespace-name\"", ")", ",", "}", "\n", "a", ".", "processAggregationRequest", "(", "key", ",", "request", ",", "response", ")", "\n", "}" ]
// namespaceAggregations returns a metric timeseries for a metric of the Namespace entity.
[ "namespaceAggregations", "returns", "a", "metric", "timeseries", "for", "a", "metric", "of", "the", "Namespace", "entity", "." ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L497-L503
train
kubernetes-retired/heapster
metrics/api/v1/historical_handlers.go
podContainerAggregations
func (a *HistoricalApi) podContainerAggregations(request *restful.Request, response *restful.Response) { var key core.HistoricalKey if request.PathParameter("pod-id") != "" { key = core.HistoricalKey{ ObjectType: core.MetricSetTypePodContainer, PodId: request.PathParameter("pod-id"), ContainerName: request.PathParameter("container-name"), } } else { key = core.HistoricalKey{ ObjectType: core.MetricSetTypePodContainer, NamespaceName: request.PathParameter("namespace-name"), PodName: request.PathParameter("pod-name"), ContainerName: request.PathParameter("container-name"), } } a.processAggregationRequest(key, request, response) }
go
func (a *HistoricalApi) podContainerAggregations(request *restful.Request, response *restful.Response) { var key core.HistoricalKey if request.PathParameter("pod-id") != "" { key = core.HistoricalKey{ ObjectType: core.MetricSetTypePodContainer, PodId: request.PathParameter("pod-id"), ContainerName: request.PathParameter("container-name"), } } else { key = core.HistoricalKey{ ObjectType: core.MetricSetTypePodContainer, NamespaceName: request.PathParameter("namespace-name"), PodName: request.PathParameter("pod-name"), ContainerName: request.PathParameter("container-name"), } } a.processAggregationRequest(key, request, response) }
[ "func", "(", "a", "*", "HistoricalApi", ")", "podContainerAggregations", "(", "request", "*", "restful", ".", "Request", ",", "response", "*", "restful", ".", "Response", ")", "{", "var", "key", "core", ".", "HistoricalKey", "\n", "if", "request", ".", "PathParameter", "(", "\"pod-id\"", ")", "!=", "\"\"", "{", "key", "=", "core", ".", "HistoricalKey", "{", "ObjectType", ":", "core", ".", "MetricSetTypePodContainer", ",", "PodId", ":", "request", ".", "PathParameter", "(", "\"pod-id\"", ")", ",", "ContainerName", ":", "request", ".", "PathParameter", "(", "\"container-name\"", ")", ",", "}", "\n", "}", "else", "{", "key", "=", "core", ".", "HistoricalKey", "{", "ObjectType", ":", "core", ".", "MetricSetTypePodContainer", ",", "NamespaceName", ":", "request", ".", "PathParameter", "(", "\"namespace-name\"", ")", ",", "PodName", ":", "request", ".", "PathParameter", "(", "\"pod-name\"", ")", ",", "ContainerName", ":", "request", ".", "PathParameter", "(", "\"container-name\"", ")", ",", "}", "\n", "}", "\n", "a", ".", "processAggregationRequest", "(", "key", ",", "request", ",", "response", ")", "\n", "}" ]
// podContainerAggregations returns a metric timeseries for a metric of a Pod Container entity.
[ "podContainerAggregations", "returns", "a", "metric", "timeseries", "for", "a", "metric", "of", "a", "Pod", "Container", "entity", "." ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L524-L541
train
kubernetes-retired/heapster
metrics/api/v1/historical_handlers.go
freeContainerAggregations
func (a *HistoricalApi) freeContainerAggregations(request *restful.Request, response *restful.Response) { key := core.HistoricalKey{ ObjectType: core.MetricSetTypeSystemContainer, NodeName: request.PathParameter("node-name"), ContainerName: request.PathParameter("container-name"), } a.processAggregationRequest(key, request, response) }
go
func (a *HistoricalApi) freeContainerAggregations(request *restful.Request, response *restful.Response) { key := core.HistoricalKey{ ObjectType: core.MetricSetTypeSystemContainer, NodeName: request.PathParameter("node-name"), ContainerName: request.PathParameter("container-name"), } a.processAggregationRequest(key, request, response) }
[ "func", "(", "a", "*", "HistoricalApi", ")", "freeContainerAggregations", "(", "request", "*", "restful", ".", "Request", ",", "response", "*", "restful", ".", "Response", ")", "{", "key", ":=", "core", ".", "HistoricalKey", "{", "ObjectType", ":", "core", ".", "MetricSetTypeSystemContainer", ",", "NodeName", ":", "request", ".", "PathParameter", "(", "\"node-name\"", ")", ",", "ContainerName", ":", "request", ".", "PathParameter", "(", "\"container-name\"", ")", ",", "}", "\n", "a", ".", "processAggregationRequest", "(", "key", ",", "request", ",", "response", ")", "\n", "}" ]
// freeContainerAggregations returns a metric timeseries for a metric of the Container entity. // freeContainerAggregations addresses only free containers.
[ "freeContainerAggregations", "returns", "a", "metric", "timeseries", "for", "a", "metric", "of", "the", "Container", "entity", ".", "freeContainerAggregations", "addresses", "only", "free", "containers", "." ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L545-L552
train
kubernetes-retired/heapster
metrics/api/v1/historical_handlers.go
podListAggregations
func (a *HistoricalApi) podListAggregations(request *restful.Request, response *restful.Response) { start, end, err := getStartEndTimeHistorical(request) if err != nil { response.WriteError(http.StatusBadRequest, err) return } bucketSize, err := getBucketSize(request) if err != nil { response.WriteError(http.StatusBadRequest, err) return } aggregations, err := getAggregations(request) if err != nil { response.WriteError(http.StatusBadRequest, err) return } labels, err := getLabels(request) if err != nil { response.WriteError(http.StatusBadRequest, err) return } keys := []core.HistoricalKey{} if request.PathParameter("pod-id-list") != "" { for _, podId := range strings.Split(request.PathParameter("pod-id-list"), ",") { key := core.HistoricalKey{ ObjectType: core.MetricSetTypePod, PodId: podId, } keys = append(keys, key) } } else { for _, podName := range strings.Split(request.PathParameter("pod-list"), ",") { key := core.HistoricalKey{ ObjectType: core.MetricSetTypePod, NamespaceName: request.PathParameter("namespace-name"), PodName: podName, } keys = append(keys, key) } } metricName := request.PathParameter("metric-name") convertedMetricName := convertMetricName(metricName) var metrics map[core.HistoricalKey][]core.TimestampedAggregationValue if labels != nil { metrics, err = a.historicalSource.GetLabeledAggregation(convertedMetricName, labels, aggregations, keys, start, end, bucketSize) } else { metrics, err = a.historicalSource.GetAggregation(convertedMetricName, aggregations, keys, start, end, bucketSize) } if err != nil { response.WriteError(http.StatusInternalServerError, err) return } result := types.MetricAggregationResultList{ Items: make([]types.MetricAggregationResult, 0, len(keys)), } for _, key := range keys { result.Items = append(result.Items, exportTimestampedAggregationValue(metrics[key])) } response.PrettyPrint(false) response.WriteEntity(result) }
go
func (a *HistoricalApi) podListAggregations(request *restful.Request, response *restful.Response) { start, end, err := getStartEndTimeHistorical(request) if err != nil { response.WriteError(http.StatusBadRequest, err) return } bucketSize, err := getBucketSize(request) if err != nil { response.WriteError(http.StatusBadRequest, err) return } aggregations, err := getAggregations(request) if err != nil { response.WriteError(http.StatusBadRequest, err) return } labels, err := getLabels(request) if err != nil { response.WriteError(http.StatusBadRequest, err) return } keys := []core.HistoricalKey{} if request.PathParameter("pod-id-list") != "" { for _, podId := range strings.Split(request.PathParameter("pod-id-list"), ",") { key := core.HistoricalKey{ ObjectType: core.MetricSetTypePod, PodId: podId, } keys = append(keys, key) } } else { for _, podName := range strings.Split(request.PathParameter("pod-list"), ",") { key := core.HistoricalKey{ ObjectType: core.MetricSetTypePod, NamespaceName: request.PathParameter("namespace-name"), PodName: podName, } keys = append(keys, key) } } metricName := request.PathParameter("metric-name") convertedMetricName := convertMetricName(metricName) var metrics map[core.HistoricalKey][]core.TimestampedAggregationValue if labels != nil { metrics, err = a.historicalSource.GetLabeledAggregation(convertedMetricName, labels, aggregations, keys, start, end, bucketSize) } else { metrics, err = a.historicalSource.GetAggregation(convertedMetricName, aggregations, keys, start, end, bucketSize) } if err != nil { response.WriteError(http.StatusInternalServerError, err) return } result := types.MetricAggregationResultList{ Items: make([]types.MetricAggregationResult, 0, len(keys)), } for _, key := range keys { result.Items = append(result.Items, exportTimestampedAggregationValue(metrics[key])) } response.PrettyPrint(false) response.WriteEntity(result) }
[ "func", "(", "a", "*", "HistoricalApi", ")", "podListAggregations", "(", "request", "*", "restful", ".", "Request", ",", "response", "*", "restful", ".", "Response", ")", "{", "start", ",", "end", ",", "err", ":=", "getStartEndTimeHistorical", "(", "request", ")", "\n", "if", "err", "!=", "nil", "{", "response", ".", "WriteError", "(", "http", ".", "StatusBadRequest", ",", "err", ")", "\n", "return", "\n", "}", "\n", "bucketSize", ",", "err", ":=", "getBucketSize", "(", "request", ")", "\n", "if", "err", "!=", "nil", "{", "response", ".", "WriteError", "(", "http", ".", "StatusBadRequest", ",", "err", ")", "\n", "return", "\n", "}", "\n", "aggregations", ",", "err", ":=", "getAggregations", "(", "request", ")", "\n", "if", "err", "!=", "nil", "{", "response", ".", "WriteError", "(", "http", ".", "StatusBadRequest", ",", "err", ")", "\n", "return", "\n", "}", "\n", "labels", ",", "err", ":=", "getLabels", "(", "request", ")", "\n", "if", "err", "!=", "nil", "{", "response", ".", "WriteError", "(", "http", ".", "StatusBadRequest", ",", "err", ")", "\n", "return", "\n", "}", "\n", "keys", ":=", "[", "]", "core", ".", "HistoricalKey", "{", "}", "\n", "if", "request", ".", "PathParameter", "(", "\"pod-id-list\"", ")", "!=", "\"\"", "{", "for", "_", ",", "podId", ":=", "range", "strings", ".", "Split", "(", "request", ".", "PathParameter", "(", "\"pod-id-list\"", ")", ",", "\",\"", ")", "{", "key", ":=", "core", ".", "HistoricalKey", "{", "ObjectType", ":", "core", ".", "MetricSetTypePod", ",", "PodId", ":", "podId", ",", "}", "\n", "keys", "=", "append", "(", "keys", ",", "key", ")", "\n", "}", "\n", "}", "else", "{", "for", "_", ",", "podName", ":=", "range", "strings", ".", "Split", "(", "request", ".", "PathParameter", "(", "\"pod-list\"", ")", ",", "\",\"", ")", "{", "key", ":=", "core", ".", "HistoricalKey", "{", "ObjectType", ":", "core", ".", "MetricSetTypePod", ",", "NamespaceName", ":", "request", ".", "PathParameter", "(", "\"namespace-name\"", ")", ",", "PodName", ":", "podName", ",", "}", "\n", "keys", "=", "append", "(", "keys", ",", "key", ")", "\n", "}", "\n", "}", "\n", "metricName", ":=", "request", ".", "PathParameter", "(", "\"metric-name\"", ")", "\n", "convertedMetricName", ":=", "convertMetricName", "(", "metricName", ")", "\n", "var", "metrics", "map", "[", "core", ".", "HistoricalKey", "]", "[", "]", "core", ".", "TimestampedAggregationValue", "\n", "if", "labels", "!=", "nil", "{", "metrics", ",", "err", "=", "a", ".", "historicalSource", ".", "GetLabeledAggregation", "(", "convertedMetricName", ",", "labels", ",", "aggregations", ",", "keys", ",", "start", ",", "end", ",", "bucketSize", ")", "\n", "}", "else", "{", "metrics", ",", "err", "=", "a", ".", "historicalSource", ".", "GetAggregation", "(", "convertedMetricName", ",", "aggregations", ",", "keys", ",", "start", ",", "end", ",", "bucketSize", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "response", ".", "WriteError", "(", "http", ".", "StatusInternalServerError", ",", "err", ")", "\n", "return", "\n", "}", "\n", "result", ":=", "types", ".", "MetricAggregationResultList", "{", "Items", ":", "make", "(", "[", "]", "types", ".", "MetricAggregationResult", ",", "0", ",", "len", "(", "keys", ")", ")", ",", "}", "\n", "for", "_", ",", "key", ":=", "range", "keys", "{", "result", ".", "Items", "=", "append", "(", "result", ".", "Items", ",", "exportTimestampedAggregationValue", "(", "metrics", "[", "key", "]", ")", ")", "\n", "}", "\n", "response", ".", "PrettyPrint", "(", "false", ")", "\n", "response", ".", "WriteEntity", "(", "result", ")", "\n", "}" ]
// podListAggregations returns a list of metric timeseries for the specified pods.
[ "podListAggregations", "returns", "a", "list", "of", "metric", "timeseries", "for", "the", "specified", "pods", "." ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L555-L616
train
kubernetes-retired/heapster
metrics/api/v1/historical_handlers.go
processMetricRequest
func (a *HistoricalApi) processMetricRequest(key core.HistoricalKey, request *restful.Request, response *restful.Response) { start, end, err := getStartEndTimeHistorical(request) if err != nil { response.WriteError(http.StatusBadRequest, err) return } labels, err := getLabels(request) if err != nil { response.WriteError(http.StatusBadRequest, err) return } metricName := request.PathParameter("metric-name") convertedMetricName := convertMetricName(metricName) var metrics map[core.HistoricalKey][]core.TimestampedMetricValue if labels != nil { metrics, err = a.historicalSource.GetLabeledMetric(convertedMetricName, labels, []core.HistoricalKey{key}, start, end) } else { metrics, err = a.historicalSource.GetMetric(convertedMetricName, []core.HistoricalKey{key}, start, end) } if err != nil { response.WriteError(http.StatusInternalServerError, err) return } converted := exportTimestampedMetricValue(metrics[key]) response.WriteEntity(converted) }
go
func (a *HistoricalApi) processMetricRequest(key core.HistoricalKey, request *restful.Request, response *restful.Response) { start, end, err := getStartEndTimeHistorical(request) if err != nil { response.WriteError(http.StatusBadRequest, err) return } labels, err := getLabels(request) if err != nil { response.WriteError(http.StatusBadRequest, err) return } metricName := request.PathParameter("metric-name") convertedMetricName := convertMetricName(metricName) var metrics map[core.HistoricalKey][]core.TimestampedMetricValue if labels != nil { metrics, err = a.historicalSource.GetLabeledMetric(convertedMetricName, labels, []core.HistoricalKey{key}, start, end) } else { metrics, err = a.historicalSource.GetMetric(convertedMetricName, []core.HistoricalKey{key}, start, end) } if err != nil { response.WriteError(http.StatusInternalServerError, err) return } converted := exportTimestampedMetricValue(metrics[key]) response.WriteEntity(converted) }
[ "func", "(", "a", "*", "HistoricalApi", ")", "processMetricRequest", "(", "key", "core", ".", "HistoricalKey", ",", "request", "*", "restful", ".", "Request", ",", "response", "*", "restful", ".", "Response", ")", "{", "start", ",", "end", ",", "err", ":=", "getStartEndTimeHistorical", "(", "request", ")", "\n", "if", "err", "!=", "nil", "{", "response", ".", "WriteError", "(", "http", ".", "StatusBadRequest", ",", "err", ")", "\n", "return", "\n", "}", "\n", "labels", ",", "err", ":=", "getLabels", "(", "request", ")", "\n", "if", "err", "!=", "nil", "{", "response", ".", "WriteError", "(", "http", ".", "StatusBadRequest", ",", "err", ")", "\n", "return", "\n", "}", "\n", "metricName", ":=", "request", ".", "PathParameter", "(", "\"metric-name\"", ")", "\n", "convertedMetricName", ":=", "convertMetricName", "(", "metricName", ")", "\n", "var", "metrics", "map", "[", "core", ".", "HistoricalKey", "]", "[", "]", "core", ".", "TimestampedMetricValue", "\n", "if", "labels", "!=", "nil", "{", "metrics", ",", "err", "=", "a", ".", "historicalSource", ".", "GetLabeledMetric", "(", "convertedMetricName", ",", "labels", ",", "[", "]", "core", ".", "HistoricalKey", "{", "key", "}", ",", "start", ",", "end", ")", "\n", "}", "else", "{", "metrics", ",", "err", "=", "a", ".", "historicalSource", ".", "GetMetric", "(", "convertedMetricName", ",", "[", "]", "core", ".", "HistoricalKey", "{", "key", "}", ",", "start", ",", "end", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "response", ".", "WriteError", "(", "http", ".", "StatusInternalServerError", ",", "err", ")", "\n", "return", "\n", "}", "\n", "converted", ":=", "exportTimestampedMetricValue", "(", "metrics", "[", "key", "]", ")", "\n", "response", ".", "WriteEntity", "(", "converted", ")", "\n", "}" ]
// processMetricRequest retrieves a metric for the object at the requested key.
[ "processMetricRequest", "retrieves", "a", "metric", "for", "the", "object", "at", "the", "requested", "key", "." ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L619-L646
train
kubernetes-retired/heapster
metrics/api/v1/historical_handlers.go
processMetricNamesRequest
func (a *HistoricalApi) processMetricNamesRequest(key core.HistoricalKey, response *restful.Response) { if resp, err := a.historicalSource.GetMetricNames(key); err != nil { response.WriteError(http.StatusInternalServerError, err) } else { response.WriteEntity(resp) } }
go
func (a *HistoricalApi) processMetricNamesRequest(key core.HistoricalKey, response *restful.Response) { if resp, err := a.historicalSource.GetMetricNames(key); err != nil { response.WriteError(http.StatusInternalServerError, err) } else { response.WriteEntity(resp) } }
[ "func", "(", "a", "*", "HistoricalApi", ")", "processMetricNamesRequest", "(", "key", "core", ".", "HistoricalKey", ",", "response", "*", "restful", ".", "Response", ")", "{", "if", "resp", ",", "err", ":=", "a", ".", "historicalSource", ".", "GetMetricNames", "(", "key", ")", ";", "err", "!=", "nil", "{", "response", ".", "WriteError", "(", "http", ".", "StatusInternalServerError", ",", "err", ")", "\n", "}", "else", "{", "response", ".", "WriteEntity", "(", "resp", ")", "\n", "}", "\n", "}" ]
// processMetricNamesRequest retrieves the available metrics for the object at the specified key.
[ "processMetricNamesRequest", "retrieves", "the", "available", "metrics", "for", "the", "object", "at", "the", "specified", "key", "." ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L649-L655
train
kubernetes-retired/heapster
metrics/api/v1/historical_handlers.go
getBucketSize
func getBucketSize(request *restful.Request) (time.Duration, error) { rawSize := request.QueryParameter("bucket") if rawSize == "" { return 0, nil } if len(rawSize) < 2 { return 0, fmt.Errorf("unable to parse bucket size: %q is too short to be a duration", rawSize) } var multiplier time.Duration var num string switch rawSize[len(rawSize)-1] { case 's': // could be s or ms if len(rawSize) < 3 || rawSize[len(rawSize)-2] != 'm' { multiplier = time.Second num = rawSize[:len(rawSize)-1] } else { multiplier = time.Millisecond num = rawSize[:len(rawSize)-2] } case 'h': multiplier = time.Hour num = rawSize[:len(rawSize)-1] case 'd': multiplier = 24 * time.Hour num = rawSize[:len(rawSize)-1] case 'm': multiplier = time.Minute num = rawSize[:len(rawSize)-1] default: return 0, fmt.Errorf("unable to parse bucket size: %q has no known duration suffix", rawSize) } parsedNum, err := strconv.ParseUint(num, 10, 64) if err != nil { return 0, err } return time.Duration(parsedNum) * multiplier, nil }
go
func getBucketSize(request *restful.Request) (time.Duration, error) { rawSize := request.QueryParameter("bucket") if rawSize == "" { return 0, nil } if len(rawSize) < 2 { return 0, fmt.Errorf("unable to parse bucket size: %q is too short to be a duration", rawSize) } var multiplier time.Duration var num string switch rawSize[len(rawSize)-1] { case 's': // could be s or ms if len(rawSize) < 3 || rawSize[len(rawSize)-2] != 'm' { multiplier = time.Second num = rawSize[:len(rawSize)-1] } else { multiplier = time.Millisecond num = rawSize[:len(rawSize)-2] } case 'h': multiplier = time.Hour num = rawSize[:len(rawSize)-1] case 'd': multiplier = 24 * time.Hour num = rawSize[:len(rawSize)-1] case 'm': multiplier = time.Minute num = rawSize[:len(rawSize)-1] default: return 0, fmt.Errorf("unable to parse bucket size: %q has no known duration suffix", rawSize) } parsedNum, err := strconv.ParseUint(num, 10, 64) if err != nil { return 0, err } return time.Duration(parsedNum) * multiplier, nil }
[ "func", "getBucketSize", "(", "request", "*", "restful", ".", "Request", ")", "(", "time", ".", "Duration", ",", "error", ")", "{", "rawSize", ":=", "request", ".", "QueryParameter", "(", "\"bucket\"", ")", "\n", "if", "rawSize", "==", "\"\"", "{", "return", "0", ",", "nil", "\n", "}", "\n", "if", "len", "(", "rawSize", ")", "<", "2", "{", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"unable to parse bucket size: %q is too short to be a duration\"", ",", "rawSize", ")", "\n", "}", "\n", "var", "multiplier", "time", ".", "Duration", "\n", "var", "num", "string", "\n", "switch", "rawSize", "[", "len", "(", "rawSize", ")", "-", "1", "]", "{", "case", "'s'", ":", "if", "len", "(", "rawSize", ")", "<", "3", "||", "rawSize", "[", "len", "(", "rawSize", ")", "-", "2", "]", "!=", "'m'", "{", "multiplier", "=", "time", ".", "Second", "\n", "num", "=", "rawSize", "[", ":", "len", "(", "rawSize", ")", "-", "1", "]", "\n", "}", "else", "{", "multiplier", "=", "time", ".", "Millisecond", "\n", "num", "=", "rawSize", "[", ":", "len", "(", "rawSize", ")", "-", "2", "]", "\n", "}", "\n", "case", "'h'", ":", "multiplier", "=", "time", ".", "Hour", "\n", "num", "=", "rawSize", "[", ":", "len", "(", "rawSize", ")", "-", "1", "]", "\n", "case", "'d'", ":", "multiplier", "=", "24", "*", "time", ".", "Hour", "\n", "num", "=", "rawSize", "[", ":", "len", "(", "rawSize", ")", "-", "1", "]", "\n", "case", "'m'", ":", "multiplier", "=", "time", ".", "Minute", "\n", "num", "=", "rawSize", "[", ":", "len", "(", "rawSize", ")", "-", "1", "]", "\n", "default", ":", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"unable to parse bucket size: %q has no known duration suffix\"", ",", "rawSize", ")", "\n", "}", "\n", "parsedNum", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "num", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "time", ".", "Duration", "(", "parsedNum", ")", "*", "multiplier", ",", "nil", "\n", "}" ]
// getBucketSize parses the bucket size specifier into a
[ "getBucketSize", "parses", "the", "bucket", "size", "specifier", "into", "a" ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L698-L739
train
kubernetes-retired/heapster
metrics/api/v1/historical_handlers.go
getAggregations
func getAggregations(request *restful.Request) ([]core.AggregationType, error) { aggregationsRaw := strings.Split(request.PathParameter("aggregations"), ",") if len(aggregationsRaw) == 0 { return nil, fmt.Errorf("No aggregations specified") } aggregations := make([]core.AggregationType, len(aggregationsRaw)) for ind, aggNameRaw := range aggregationsRaw { aggName := core.AggregationType(aggNameRaw) if _, ok := core.AllAggregations[aggName]; !ok { return nil, fmt.Errorf("Unknown aggregation %q", aggName) } aggregations[ind] = aggName } return aggregations, nil }
go
func getAggregations(request *restful.Request) ([]core.AggregationType, error) { aggregationsRaw := strings.Split(request.PathParameter("aggregations"), ",") if len(aggregationsRaw) == 0 { return nil, fmt.Errorf("No aggregations specified") } aggregations := make([]core.AggregationType, len(aggregationsRaw)) for ind, aggNameRaw := range aggregationsRaw { aggName := core.AggregationType(aggNameRaw) if _, ok := core.AllAggregations[aggName]; !ok { return nil, fmt.Errorf("Unknown aggregation %q", aggName) } aggregations[ind] = aggName } return aggregations, nil }
[ "func", "getAggregations", "(", "request", "*", "restful", ".", "Request", ")", "(", "[", "]", "core", ".", "AggregationType", ",", "error", ")", "{", "aggregationsRaw", ":=", "strings", ".", "Split", "(", "request", ".", "PathParameter", "(", "\"aggregations\"", ")", ",", "\",\"", ")", "\n", "if", "len", "(", "aggregationsRaw", ")", "==", "0", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"No aggregations specified\"", ")", "\n", "}", "\n", "aggregations", ":=", "make", "(", "[", "]", "core", ".", "AggregationType", ",", "len", "(", "aggregationsRaw", ")", ")", "\n", "for", "ind", ",", "aggNameRaw", ":=", "range", "aggregationsRaw", "{", "aggName", ":=", "core", ".", "AggregationType", "(", "aggNameRaw", ")", "\n", "if", "_", ",", "ok", ":=", "core", ".", "AllAggregations", "[", "aggName", "]", ";", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"Unknown aggregation %q\"", ",", "aggName", ")", "\n", "}", "\n", "aggregations", "[", "ind", "]", "=", "aggName", "\n", "}", "\n", "return", "aggregations", ",", "nil", "\n", "}" ]
// getAggregations extracts and validates the list of requested aggregations
[ "getAggregations", "extracts", "and", "validates", "the", "list", "of", "requested", "aggregations" ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L742-L759
train
kubernetes-retired/heapster
metrics/api/v1/historical_handlers.go
exportMetricValue
func exportMetricValue(value *core.MetricValue) *types.MetricValue { if value == nil { return nil } if value.ValueType == core.ValueInt64 { return &types.MetricValue{ IntValue: &value.IntValue, } } else { floatVal := float64(value.FloatValue) return &types.MetricValue{ FloatValue: &floatVal, } } }
go
func exportMetricValue(value *core.MetricValue) *types.MetricValue { if value == nil { return nil } if value.ValueType == core.ValueInt64 { return &types.MetricValue{ IntValue: &value.IntValue, } } else { floatVal := float64(value.FloatValue) return &types.MetricValue{ FloatValue: &floatVal, } } }
[ "func", "exportMetricValue", "(", "value", "*", "core", ".", "MetricValue", ")", "*", "types", ".", "MetricValue", "{", "if", "value", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "value", ".", "ValueType", "==", "core", ".", "ValueInt64", "{", "return", "&", "types", ".", "MetricValue", "{", "IntValue", ":", "&", "value", ".", "IntValue", ",", "}", "\n", "}", "else", "{", "floatVal", ":=", "float64", "(", "value", ".", "FloatValue", ")", "\n", "return", "&", "types", ".", "MetricValue", "{", "FloatValue", ":", "&", "floatVal", ",", "}", "\n", "}", "\n", "}" ]
// exportMetricValue converts a core.MetricValue into an API MetricValue
[ "exportMetricValue", "converts", "a", "core", ".", "MetricValue", "into", "an", "API", "MetricValue" ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L762-L777
train
kubernetes-retired/heapster
metrics/api/v1/historical_handlers.go
extractMetricValue
func extractMetricValue(aggregations *core.AggregationValue, aggName core.AggregationType) *types.MetricValue { if inputVal, ok := aggregations.Aggregations[aggName]; ok { return exportMetricValue(&inputVal) } else { return nil } }
go
func extractMetricValue(aggregations *core.AggregationValue, aggName core.AggregationType) *types.MetricValue { if inputVal, ok := aggregations.Aggregations[aggName]; ok { return exportMetricValue(&inputVal) } else { return nil } }
[ "func", "extractMetricValue", "(", "aggregations", "*", "core", ".", "AggregationValue", ",", "aggName", "core", ".", "AggregationType", ")", "*", "types", ".", "MetricValue", "{", "if", "inputVal", ",", "ok", ":=", "aggregations", ".", "Aggregations", "[", "aggName", "]", ";", "ok", "{", "return", "exportMetricValue", "(", "&", "inputVal", ")", "\n", "}", "else", "{", "return", "nil", "\n", "}", "\n", "}" ]
// extractMetricValue checks to see if the given metric was present in the results, and if so, // returns it in API form
[ "extractMetricValue", "checks", "to", "see", "if", "the", "given", "metric", "was", "present", "in", "the", "results", "and", "if", "so", "returns", "it", "in", "API", "form" ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L781-L787
train
kubernetes-retired/heapster
metrics/api/v1/historical_handlers.go
exportTimestampedAggregationValue
func exportTimestampedAggregationValue(values []core.TimestampedAggregationValue) types.MetricAggregationResult { result := types.MetricAggregationResult{ Buckets: make([]types.MetricAggregationBucket, 0, len(values)), BucketSize: 0, } for _, value := range values { // just use the largest bucket size, since all bucket sizes should be uniform // (except for the last one, which may be smaller) if result.BucketSize < value.BucketSize { result.BucketSize = value.BucketSize } bucket := types.MetricAggregationBucket{ Timestamp: value.Timestamp, Count: value.Count, Average: extractMetricValue(&value.AggregationValue, core.AggregationTypeAverage), Maximum: extractMetricValue(&value.AggregationValue, core.AggregationTypeMaximum), Minimum: extractMetricValue(&value.AggregationValue, core.AggregationTypeMinimum), Median: extractMetricValue(&value.AggregationValue, core.AggregationTypeMedian), Percentiles: make(map[string]types.MetricValue, 3), } if val, ok := value.Aggregations[core.AggregationTypePercentile50]; ok { bucket.Percentiles["50"] = *exportMetricValue(&val) } if val, ok := value.Aggregations[core.AggregationTypePercentile95]; ok { bucket.Percentiles["95"] = *exportMetricValue(&val) } if val, ok := value.Aggregations[core.AggregationTypePercentile99]; ok { bucket.Percentiles["99"] = *exportMetricValue(&val) } result.Buckets = append(result.Buckets, bucket) } return result }
go
func exportTimestampedAggregationValue(values []core.TimestampedAggregationValue) types.MetricAggregationResult { result := types.MetricAggregationResult{ Buckets: make([]types.MetricAggregationBucket, 0, len(values)), BucketSize: 0, } for _, value := range values { // just use the largest bucket size, since all bucket sizes should be uniform // (except for the last one, which may be smaller) if result.BucketSize < value.BucketSize { result.BucketSize = value.BucketSize } bucket := types.MetricAggregationBucket{ Timestamp: value.Timestamp, Count: value.Count, Average: extractMetricValue(&value.AggregationValue, core.AggregationTypeAverage), Maximum: extractMetricValue(&value.AggregationValue, core.AggregationTypeMaximum), Minimum: extractMetricValue(&value.AggregationValue, core.AggregationTypeMinimum), Median: extractMetricValue(&value.AggregationValue, core.AggregationTypeMedian), Percentiles: make(map[string]types.MetricValue, 3), } if val, ok := value.Aggregations[core.AggregationTypePercentile50]; ok { bucket.Percentiles["50"] = *exportMetricValue(&val) } if val, ok := value.Aggregations[core.AggregationTypePercentile95]; ok { bucket.Percentiles["95"] = *exportMetricValue(&val) } if val, ok := value.Aggregations[core.AggregationTypePercentile99]; ok { bucket.Percentiles["99"] = *exportMetricValue(&val) } result.Buckets = append(result.Buckets, bucket) } return result }
[ "func", "exportTimestampedAggregationValue", "(", "values", "[", "]", "core", ".", "TimestampedAggregationValue", ")", "types", ".", "MetricAggregationResult", "{", "result", ":=", "types", ".", "MetricAggregationResult", "{", "Buckets", ":", "make", "(", "[", "]", "types", ".", "MetricAggregationBucket", ",", "0", ",", "len", "(", "values", ")", ")", ",", "BucketSize", ":", "0", ",", "}", "\n", "for", "_", ",", "value", ":=", "range", "values", "{", "if", "result", ".", "BucketSize", "<", "value", ".", "BucketSize", "{", "result", ".", "BucketSize", "=", "value", ".", "BucketSize", "\n", "}", "\n", "bucket", ":=", "types", ".", "MetricAggregationBucket", "{", "Timestamp", ":", "value", ".", "Timestamp", ",", "Count", ":", "value", ".", "Count", ",", "Average", ":", "extractMetricValue", "(", "&", "value", ".", "AggregationValue", ",", "core", ".", "AggregationTypeAverage", ")", ",", "Maximum", ":", "extractMetricValue", "(", "&", "value", ".", "AggregationValue", ",", "core", ".", "AggregationTypeMaximum", ")", ",", "Minimum", ":", "extractMetricValue", "(", "&", "value", ".", "AggregationValue", ",", "core", ".", "AggregationTypeMinimum", ")", ",", "Median", ":", "extractMetricValue", "(", "&", "value", ".", "AggregationValue", ",", "core", ".", "AggregationTypeMedian", ")", ",", "Percentiles", ":", "make", "(", "map", "[", "string", "]", "types", ".", "MetricValue", ",", "3", ")", ",", "}", "\n", "if", "val", ",", "ok", ":=", "value", ".", "Aggregations", "[", "core", ".", "AggregationTypePercentile50", "]", ";", "ok", "{", "bucket", ".", "Percentiles", "[", "\"50\"", "]", "=", "*", "exportMetricValue", "(", "&", "val", ")", "\n", "}", "\n", "if", "val", ",", "ok", ":=", "value", ".", "Aggregations", "[", "core", ".", "AggregationTypePercentile95", "]", ";", "ok", "{", "bucket", ".", "Percentiles", "[", "\"95\"", "]", "=", "*", "exportMetricValue", "(", "&", "val", ")", "\n", "}", "\n", "if", "val", ",", "ok", ":=", "value", ".", "Aggregations", "[", "core", ".", "AggregationTypePercentile99", "]", ";", "ok", "{", "bucket", ".", "Percentiles", "[", "\"99\"", "]", "=", "*", "exportMetricValue", "(", "&", "val", ")", "\n", "}", "\n", "result", ".", "Buckets", "=", "append", "(", "result", ".", "Buckets", ",", "bucket", ")", "\n", "}", "\n", "return", "result", "\n", "}" ]
// exportTimestampedAggregationValue converts a core.TimestampedAggregationValue into an API MetricAggregationResult
[ "exportTimestampedAggregationValue", "converts", "a", "core", ".", "TimestampedAggregationValue", "into", "an", "API", "MetricAggregationResult" ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L790-L828
train
kubernetes-retired/heapster
metrics/sources/summary/summary.go
decodeSummary
func (this *summaryMetricsSource) decodeSummary(summary *stats.Summary) map[string]*MetricSet { glog.V(9).Infof("Begin summary decode") result := map[string]*MetricSet{} labels := map[string]string{ LabelNodename.Key: this.node.NodeName, LabelHostname.Key: this.node.HostName, LabelHostID.Key: this.node.HostID, } this.decodeNodeStats(result, labels, &summary.Node) for _, pod := range summary.Pods { this.decodePodStats(result, labels, &pod) } glog.V(9).Infof("End summary decode") return result }
go
func (this *summaryMetricsSource) decodeSummary(summary *stats.Summary) map[string]*MetricSet { glog.V(9).Infof("Begin summary decode") result := map[string]*MetricSet{} labels := map[string]string{ LabelNodename.Key: this.node.NodeName, LabelHostname.Key: this.node.HostName, LabelHostID.Key: this.node.HostID, } this.decodeNodeStats(result, labels, &summary.Node) for _, pod := range summary.Pods { this.decodePodStats(result, labels, &pod) } glog.V(9).Infof("End summary decode") return result }
[ "func", "(", "this", "*", "summaryMetricsSource", ")", "decodeSummary", "(", "summary", "*", "stats", ".", "Summary", ")", "map", "[", "string", "]", "*", "MetricSet", "{", "glog", ".", "V", "(", "9", ")", ".", "Infof", "(", "\"Begin summary decode\"", ")", "\n", "result", ":=", "map", "[", "string", "]", "*", "MetricSet", "{", "}", "\n", "labels", ":=", "map", "[", "string", "]", "string", "{", "LabelNodename", ".", "Key", ":", "this", ".", "node", ".", "NodeName", ",", "LabelHostname", ".", "Key", ":", "this", ".", "node", ".", "HostName", ",", "LabelHostID", ".", "Key", ":", "this", ".", "node", ".", "HostID", ",", "}", "\n", "this", ".", "decodeNodeStats", "(", "result", ",", "labels", ",", "&", "summary", ".", "Node", ")", "\n", "for", "_", ",", "pod", ":=", "range", "summary", ".", "Pods", "{", "this", ".", "decodePodStats", "(", "result", ",", "labels", ",", "&", "pod", ")", "\n", "}", "\n", "glog", ".", "V", "(", "9", ")", ".", "Infof", "(", "\"End summary decode\"", ")", "\n", "return", "result", "\n", "}" ]
// decodeSummary translates the kubelet statsSummary API into the flattened heapster MetricSet API.
[ "decodeSummary", "translates", "the", "kubelet", "statsSummary", "API", "into", "the", "flattened", "heapster", "MetricSet", "API", "." ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sources/summary/summary.go#L120-L137
train
kubernetes-retired/heapster
metrics/sources/summary/summary.go
cloneLabels
func (this *summaryMetricsSource) cloneLabels(labels map[string]string) map[string]string { clone := make(map[string]string, len(labels)) for k, v := range labels { clone[k] = v } return clone }
go
func (this *summaryMetricsSource) cloneLabels(labels map[string]string) map[string]string { clone := make(map[string]string, len(labels)) for k, v := range labels { clone[k] = v } return clone }
[ "func", "(", "this", "*", "summaryMetricsSource", ")", "cloneLabels", "(", "labels", "map", "[", "string", "]", "string", ")", "map", "[", "string", "]", "string", "{", "clone", ":=", "make", "(", "map", "[", "string", "]", "string", ",", "len", "(", "labels", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "labels", "{", "clone", "[", "k", "]", "=", "v", "\n", "}", "\n", "return", "clone", "\n", "}" ]
// Convenience method for labels deep copy.
[ "Convenience", "method", "for", "labels", "deep", "copy", "." ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sources/summary/summary.go#L140-L146
train
kubernetes-retired/heapster
metrics/sources/summary/summary.go
addIntMetric
func (this *summaryMetricsSource) addIntMetric(metrics *MetricSet, metric *Metric, value *uint64) { if value == nil { glog.V(9).Infof("skipping metric %s because the value was nil", metric.Name) return } val := MetricValue{ ValueType: ValueInt64, MetricType: metric.Type, IntValue: int64(*value), } metrics.MetricValues[metric.Name] = val }
go
func (this *summaryMetricsSource) addIntMetric(metrics *MetricSet, metric *Metric, value *uint64) { if value == nil { glog.V(9).Infof("skipping metric %s because the value was nil", metric.Name) return } val := MetricValue{ ValueType: ValueInt64, MetricType: metric.Type, IntValue: int64(*value), } metrics.MetricValues[metric.Name] = val }
[ "func", "(", "this", "*", "summaryMetricsSource", ")", "addIntMetric", "(", "metrics", "*", "MetricSet", ",", "metric", "*", "Metric", ",", "value", "*", "uint64", ")", "{", "if", "value", "==", "nil", "{", "glog", ".", "V", "(", "9", ")", ".", "Infof", "(", "\"skipping metric %s because the value was nil\"", ",", "metric", ".", "Name", ")", "\n", "return", "\n", "}", "\n", "val", ":=", "MetricValue", "{", "ValueType", ":", "ValueInt64", ",", "MetricType", ":", "metric", ".", "Type", ",", "IntValue", ":", "int64", "(", "*", "value", ")", ",", "}", "\n", "metrics", ".", "MetricValues", "[", "metric", ".", "Name", "]", "=", "val", "\n", "}" ]
// addIntMetric is a convenience method for adding the metric and value to the metric set.
[ "addIntMetric", "is", "a", "convenience", "method", "for", "adding", "the", "metric", "and", "value", "to", "the", "metric", "set", "." ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sources/summary/summary.go#L370-L381
train
kubernetes-retired/heapster
metrics/sources/summary/summary.go
addLabeledIntMetric
func (this *summaryMetricsSource) addLabeledIntMetric(metrics *MetricSet, metric *Metric, labels map[string]string, value *uint64) { if value == nil { glog.V(9).Infof("skipping labeled metric %s (%v) because the value was nil", metric.Name, labels) return } val := LabeledMetric{ Name: metric.Name, Labels: labels, MetricValue: MetricValue{ ValueType: ValueInt64, MetricType: metric.Type, IntValue: int64(*value), }, } metrics.LabeledMetrics = append(metrics.LabeledMetrics, val) }
go
func (this *summaryMetricsSource) addLabeledIntMetric(metrics *MetricSet, metric *Metric, labels map[string]string, value *uint64) { if value == nil { glog.V(9).Infof("skipping labeled metric %s (%v) because the value was nil", metric.Name, labels) return } val := LabeledMetric{ Name: metric.Name, Labels: labels, MetricValue: MetricValue{ ValueType: ValueInt64, MetricType: metric.Type, IntValue: int64(*value), }, } metrics.LabeledMetrics = append(metrics.LabeledMetrics, val) }
[ "func", "(", "this", "*", "summaryMetricsSource", ")", "addLabeledIntMetric", "(", "metrics", "*", "MetricSet", ",", "metric", "*", "Metric", ",", "labels", "map", "[", "string", "]", "string", ",", "value", "*", "uint64", ")", "{", "if", "value", "==", "nil", "{", "glog", ".", "V", "(", "9", ")", ".", "Infof", "(", "\"skipping labeled metric %s (%v) because the value was nil\"", ",", "metric", ".", "Name", ",", "labels", ")", "\n", "return", "\n", "}", "\n", "val", ":=", "LabeledMetric", "{", "Name", ":", "metric", ".", "Name", ",", "Labels", ":", "labels", ",", "MetricValue", ":", "MetricValue", "{", "ValueType", ":", "ValueInt64", ",", "MetricType", ":", "metric", ".", "Type", ",", "IntValue", ":", "int64", "(", "*", "value", ")", ",", "}", ",", "}", "\n", "metrics", ".", "LabeledMetrics", "=", "append", "(", "metrics", ".", "LabeledMetrics", ",", "val", ")", "\n", "}" ]
// addLabeledIntMetric is a convenience method for adding the labeled metric and value to the metric set.
[ "addLabeledIntMetric", "is", "a", "convenience", "method", "for", "adding", "the", "labeled", "metric", "and", "value", "to", "the", "metric", "set", "." ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sources/summary/summary.go#L384-L400
train
kubernetes-retired/heapster
metrics/sources/summary/summary.go
getSystemContainerName
func (this *summaryMetricsSource) getSystemContainerName(c *stats.ContainerStats) string { if legacyName, ok := systemNameMap[c.Name]; ok { return legacyName } return c.Name }
go
func (this *summaryMetricsSource) getSystemContainerName(c *stats.ContainerStats) string { if legacyName, ok := systemNameMap[c.Name]; ok { return legacyName } return c.Name }
[ "func", "(", "this", "*", "summaryMetricsSource", ")", "getSystemContainerName", "(", "c", "*", "stats", ".", "ContainerStats", ")", "string", "{", "if", "legacyName", ",", "ok", ":=", "systemNameMap", "[", "c", ".", "Name", "]", ";", "ok", "{", "return", "legacyName", "\n", "}", "\n", "return", "c", ".", "Name", "\n", "}" ]
// Translate system container names to the legacy names for backwards compatibility.
[ "Translate", "system", "container", "names", "to", "the", "legacy", "names", "for", "backwards", "compatibility", "." ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sources/summary/summary.go#L403-L408
train
kubernetes-retired/heapster
common/riemann/riemann.go
GetRiemannClient
func GetRiemannClient(config RiemannConfig) (riemanngo.Client, error) { glog.Infof("Connect Riemann client...") client := riemanngo.NewTcpClient(config.Host) runtime.SetFinalizer(client, func(c riemanngo.Client) { c.Close() }) // 5 seconds timeout err := client.Connect(5) if err != nil { return nil, err } return client, nil }
go
func GetRiemannClient(config RiemannConfig) (riemanngo.Client, error) { glog.Infof("Connect Riemann client...") client := riemanngo.NewTcpClient(config.Host) runtime.SetFinalizer(client, func(c riemanngo.Client) { c.Close() }) // 5 seconds timeout err := client.Connect(5) if err != nil { return nil, err } return client, nil }
[ "func", "GetRiemannClient", "(", "config", "RiemannConfig", ")", "(", "riemanngo", ".", "Client", ",", "error", ")", "{", "glog", ".", "Infof", "(", "\"Connect Riemann client...\"", ")", "\n", "client", ":=", "riemanngo", ".", "NewTcpClient", "(", "config", ".", "Host", ")", "\n", "runtime", ".", "SetFinalizer", "(", "client", ",", "func", "(", "c", "riemanngo", ".", "Client", ")", "{", "c", ".", "Close", "(", ")", "}", ")", "\n", "err", ":=", "client", ".", "Connect", "(", "5", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "client", ",", "nil", "\n", "}" ]
// Receives a sink, connect the riemann client.
[ "Receives", "a", "sink", "connect", "the", "riemann", "client", "." ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/common/riemann/riemann.go#L102-L112
train
kubernetes-retired/heapster
common/riemann/riemann.go
SendData
func SendData(client riemanngo.Client, events []riemanngo.Event) error { // do nothing if we are not connected if client == nil { glog.Warningf("Riemann sink not connected") return nil } start := time.Now() _, err := riemanngo.SendEvents(client, &events) end := time.Now() if err == nil { glog.V(4).Infof("Exported %d events to riemann in %s", len(events), end.Sub(start)) return nil } else { glog.Warningf("There were errors sending events to Riemman, forcing reconnection. Error : %+v", err) return err } }
go
func SendData(client riemanngo.Client, events []riemanngo.Event) error { // do nothing if we are not connected if client == nil { glog.Warningf("Riemann sink not connected") return nil } start := time.Now() _, err := riemanngo.SendEvents(client, &events) end := time.Now() if err == nil { glog.V(4).Infof("Exported %d events to riemann in %s", len(events), end.Sub(start)) return nil } else { glog.Warningf("There were errors sending events to Riemman, forcing reconnection. Error : %+v", err) return err } }
[ "func", "SendData", "(", "client", "riemanngo", ".", "Client", ",", "events", "[", "]", "riemanngo", ".", "Event", ")", "error", "{", "if", "client", "==", "nil", "{", "glog", ".", "Warningf", "(", "\"Riemann sink not connected\"", ")", "\n", "return", "nil", "\n", "}", "\n", "start", ":=", "time", ".", "Now", "(", ")", "\n", "_", ",", "err", ":=", "riemanngo", ".", "SendEvents", "(", "client", ",", "&", "events", ")", "\n", "end", ":=", "time", ".", "Now", "(", ")", "\n", "if", "err", "==", "nil", "{", "glog", ".", "V", "(", "4", ")", ".", "Infof", "(", "\"Exported %d events to riemann in %s\"", ",", "len", "(", "events", ")", ",", "end", ".", "Sub", "(", "start", ")", ")", "\n", "return", "nil", "\n", "}", "else", "{", "glog", ".", "Warningf", "(", "\"There were errors sending events to Riemman, forcing reconnection. Error : %+v\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "}" ]
// Send Events to Riemann using the client from the sink.
[ "Send", "Events", "to", "Riemann", "using", "the", "client", "from", "the", "sink", "." ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/common/riemann/riemann.go#L115-L131
train
kubernetes-retired/heapster
events/sinks/manager.go
ExportEvents
func (this *sinkManager) ExportEvents(data *core.EventBatch) { var wg sync.WaitGroup for _, sh := range this.sinkHolders { wg.Add(1) go func(sh sinkHolder, wg *sync.WaitGroup) { defer wg.Done() glog.V(2).Infof("Pushing events to: %s", sh.sink.Name()) select { case sh.eventBatchChannel <- data: glog.V(2).Infof("Data events completed: %s", sh.sink.Name()) // everything ok case <-time.After(this.exportEventsTimeout): glog.Warningf("Failed to events data to sink: %s", sh.sink.Name()) } }(sh, &wg) } // Wait for all pushes to complete or timeout. wg.Wait() }
go
func (this *sinkManager) ExportEvents(data *core.EventBatch) { var wg sync.WaitGroup for _, sh := range this.sinkHolders { wg.Add(1) go func(sh sinkHolder, wg *sync.WaitGroup) { defer wg.Done() glog.V(2).Infof("Pushing events to: %s", sh.sink.Name()) select { case sh.eventBatchChannel <- data: glog.V(2).Infof("Data events completed: %s", sh.sink.Name()) // everything ok case <-time.After(this.exportEventsTimeout): glog.Warningf("Failed to events data to sink: %s", sh.sink.Name()) } }(sh, &wg) } // Wait for all pushes to complete or timeout. wg.Wait() }
[ "func", "(", "this", "*", "sinkManager", ")", "ExportEvents", "(", "data", "*", "core", ".", "EventBatch", ")", "{", "var", "wg", "sync", ".", "WaitGroup", "\n", "for", "_", ",", "sh", ":=", "range", "this", ".", "sinkHolders", "{", "wg", ".", "Add", "(", "1", ")", "\n", "go", "func", "(", "sh", "sinkHolder", ",", "wg", "*", "sync", ".", "WaitGroup", ")", "{", "defer", "wg", ".", "Done", "(", ")", "\n", "glog", ".", "V", "(", "2", ")", ".", "Infof", "(", "\"Pushing events to: %s\"", ",", "sh", ".", "sink", ".", "Name", "(", ")", ")", "\n", "select", "{", "case", "sh", ".", "eventBatchChannel", "<-", "data", ":", "glog", ".", "V", "(", "2", ")", ".", "Infof", "(", "\"Data events completed: %s\"", ",", "sh", ".", "sink", ".", "Name", "(", ")", ")", "\n", "case", "<-", "time", ".", "After", "(", "this", ".", "exportEventsTimeout", ")", ":", "glog", ".", "Warningf", "(", "\"Failed to events data to sink: %s\"", ",", "sh", ".", "sink", ".", "Name", "(", ")", ")", "\n", "}", "\n", "}", "(", "sh", ",", "&", "wg", ")", "\n", "}", "\n", "wg", ".", "Wait", "(", ")", "\n", "}" ]
// Guarantees that the export will complete in exportEventsTimeout.
[ "Guarantees", "that", "the", "export", "will", "complete", "in", "exportEventsTimeout", "." ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/events/sinks/manager.go#L96-L114
train
kubernetes-retired/heapster
metrics/sinks/hawkular/client.go
cache
func (h *hawkularSink) cache(md *metrics.MetricDefinition) { h.pushToCache(md.ID, hashDefinition(md)) }
go
func (h *hawkularSink) cache(md *metrics.MetricDefinition) { h.pushToCache(md.ID, hashDefinition(md)) }
[ "func", "(", "h", "*", "hawkularSink", ")", "cache", "(", "md", "*", "metrics", ".", "MetricDefinition", ")", "{", "h", ".", "pushToCache", "(", "md", ".", "ID", ",", "hashDefinition", "(", "md", ")", ")", "\n", "}" ]
// cache inserts the item to the cache
[ "cache", "inserts", "the", "item", "to", "the", "cache" ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/client.go#L50-L52
train
kubernetes-retired/heapster
metrics/sinks/hawkular/client.go
pushToCache
func (h *hawkularSink) pushToCache(key string, hash uint64) { h.regLock.Lock() h.expReg[key] = &expiringItem{ hash: hash, ttl: h.runId, } h.regLock.Unlock() }
go
func (h *hawkularSink) pushToCache(key string, hash uint64) { h.regLock.Lock() h.expReg[key] = &expiringItem{ hash: hash, ttl: h.runId, } h.regLock.Unlock() }
[ "func", "(", "h", "*", "hawkularSink", ")", "pushToCache", "(", "key", "string", ",", "hash", "uint64", ")", "{", "h", ".", "regLock", ".", "Lock", "(", ")", "\n", "h", ".", "expReg", "[", "key", "]", "=", "&", "expiringItem", "{", "hash", ":", "hash", ",", "ttl", ":", "h", ".", "runId", ",", "}", "\n", "h", ".", "regLock", ".", "Unlock", "(", ")", "\n", "}" ]
// toCache inserts the item and updates the TTL in the cache to current time
[ "toCache", "inserts", "the", "item", "and", "updates", "the", "TTL", "in", "the", "cache", "to", "current", "time" ]
e1e83412787b60d8a70088f09a2cb12339b305c3
https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/client.go#L55-L62
train
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", "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", "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", "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", "{", "live", ".", "Tags", "[", "k", "]", "=", "v", "\n", "recent", "=", "false", "\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", "for", "_", ",", "l", ":=", "range", "md", ".", "Labels", "{", "if", "len", "(", "l", ".", "Description", ")", ">", "0", "{", "tags", "[", "l", ".", "Key", "+", "descriptionTag", "]", "=", "l", ".", "Description", "\n", "}", "\n", "}", "\n", "if", "len", "(", "md", ".", "Units", ".", "String", "(", ")", ")", ">", "0", "{", "tags", "[", "unitsTag", "]", "=", "md", ".", "Units", ".", "String", "(", ")", "\n", "}", "\n", "tags", "[", "descriptorTag", "]", "=", "md", ".", "Name", "\n", "hmd", ":=", "metrics", ".", "MetricDefinition", "{", "ID", ":", "md", ".", "Name", ",", "Tags", ":", "tags", ",", "Type", ":", "heapsterTypeToHawkularType", "(", "md", ".", "Type", ")", ",", "}", "\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", "var", "value", "float64", "\n", "if", "metric", ".", "ValueType", "==", "core", ".", "ValueInt64", "{", "value", "=", "float64", "(", "metric", ".", "IntValue", ")", "\n", "}", "else", "{", "value", "=", "float64", "(", "metric", ".", "FloatValue", ")", "\n", "}", "\n", "m", ":=", "metrics", ".", "Datapoint", "{", "Value", ":", "value", ",", "Timestamp", ":", "timestamp", ",", "}", "\n", "mh", ":=", "&", "metrics", ".", "MetricHeader", "{", "ID", ":", "name", ",", "Data", ":", "[", "]", "metrics", ".", "Datapoint", "{", "m", "}", ",", "Type", ":", "heapsterTypeToHawkularType", "(", "metric", ".", "MetricType", ")", ",", "}", "\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", "(", "\"Incorrect syntax in filter parameters, missing (\"", ")", "\n", "}", "\n", "if", "strings", ".", "Index", "(", "s", ",", "\")\"", ")", "!=", "len", "(", "s", ")", "-", "1", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"Incorrect syntax in filter parameters, missing )\"", ")", "\n", "}", "\n", "t", ":=", "Unknown", ".", "From", "(", "s", "[", ":", "p", "]", ")", "\n", "if", "t", "==", "Unknown", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"Unknown filter type\"", ")", "\n", "}", "\n", "command", ":=", "s", "[", "p", "+", "1", ":", "len", "(", "s", ")", "-", "1", "]", "\n", "switch", "t", "{", "case", "Label", ":", "proto", ":=", "strings", ".", "SplitN", "(", "command", ",", "\":\"", ",", "2", ")", "\n", "if", "len", "(", "proto", ")", "<", "2", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"Missing : from label filter\"", ")", "\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", "s", ",", "e", ":=", "tcell", ".", "NewScreen", "(", ")", "\n", "if", "e", "!=", "nil", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"%v\\n\"", ",", "\\n", ")", "\n", "e", "\n", "}", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "if", "e", ":=", "s", ".", "Init", "(", ")", ";", "e", "!=", "nil", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"%v\\n\"", ",", "\\n", ")", "\n", "e", "\n", "}", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "defStyle", "=", "tcell", ".", "StyleDefault", ".", "Background", "(", "tcell", ".", "ColorBlack", ")", ".", "Foreground", "(", "tcell", ".", "ColorWhite", ")", "\n", "s", ".", "SetStyle", "(", "defStyle", ")", "\n", "s", ".", "EnableMouse", "(", ")", "\n", "s", ".", "Clear", "(", ")", "\n", "posfmt", ":=", "\"Mouse: %d, %d \"", "\n", "btnfmt", ":=", "\"Buttons: %s\"", "\n", "keyfmt", ":=", "\"Keys: %s\"", "\n", "white", ":=", "tcell", ".", "StyleDefault", ".", "Foreground", "(", "tcell", ".", "ColorWhite", ")", ".", "Background", "(", "tcell", ".", "ColorRed", ")", "\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", "}" ]
// 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", "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", "t", ".", "left", ".", "Resize", "(", ")", "\n", "t", ".", "center", ".", "Resize", "(", ")", "\n", "t", ".", "right", ".", "Resize", "(", ")", "\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", "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", "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", "{", "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", "\"\\n\"", "\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", "width", ",", "height", ":=", "v", ".", "Size", "(", ")", "\n", "if", "width", "==", "0", "||", "height", "==", "0", "{", "return", "\n", "}", "\n", "t", ".", "clear", "(", ")", "\n", "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", "}", "else", "if", "t", ".", "widths", "[", "i", "]", "==", "0", "&&", "length", "==", "0", "{", "t", ".", "widths", "=", "append", "(", "t", ".", "widths", ",", "0", ")", "\n", "copy", "(", "t", ".", "widths", "[", "i", "+", "1", ":", "]", ",", "t", ".", "widths", "[", "i", ":", "]", ")", "\n", "t", ".", "widths", "[", "i", "]", "=", "1", "\n", "t", ".", "text", "=", "append", "(", "t", ".", "text", ",", "' '", ")", "\n", "copy", "(", "t", ".", "text", "[", "i", "+", "1", ":", "]", ",", "t", ".", "text", "[", "i", ":", "]", ")", "\n", "t", ".", "text", "[", "i", "]", "=", "' '", "\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", "{", "return", "Event", "{", "Type", ":", "EventError", ",", "Err", ":", "errors", ".", "New", "(", "\"no raw events\"", ")", "}", "\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", "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", ",", "\"Shift\"", ")", "\n", "}", "\n", "if", "ev", ".", "mod", "&", "ModAlt", "!=", "0", "{", "m", "=", "append", "(", "m", ",", "\"Alt\"", ")", "\n", "}", "\n", "if", "ev", ".", "mod", "&", "ModMeta", "!=", "0", "{", "m", "=", "append", "(", "m", ",", "\"Meta\"", ")", "\n", "}", "\n", "if", "ev", ".", "mod", "&", "ModCtrl", "!=", "0", "{", "m", "=", "append", "(", "m", ",", "\"Ctrl\"", ")", "\n", "}", "\n", "ok", ":=", "false", "\n", "if", "s", ",", "ok", "=", "KeyNames", "[", "ev", ".", "key", "]", ";", "!", "ok", "{", "if", "ev", ".", "key", "==", "KeyRune", "{", "s", "=", "\"Rune[\"", "+", "string", "(", "ev", ".", "ch", ")", "+", "\"]\"", "\n", "}", "else", "{", "s", "=", "fmt", ".", "Sprintf", "(", "\"Key[%d,%d]\"", ",", "ev", ".", "key", ",", "int", "(", "ev", ".", "ch", ")", ")", "\n", "}", "\n", "}", "\n", "if", "len", "(", "m", ")", "!=", "0", "{", "if", "ev", ".", "mod", "&", "ModCtrl", "!=", "0", "&&", "strings", ".", "HasPrefix", "(", "s", ",", "\"Ctrl-\"", ")", "{", "s", "=", "s", "[", "5", ":", "]", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"%s+%s\"", ",", "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", "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", "state", ":=", "0", "\n", "btn", ":=", "0", "\n", "x", ":=", "0", "\n", "y", ":=", "0", "\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", "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", ":", "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