repo
stringlengths 5
67
| sha
stringlengths 40
40
| path
stringlengths 4
234
| url
stringlengths 85
339
| language
stringclasses 6
values | split
stringclasses 3
values | doc
stringlengths 3
51.2k
| sign
stringlengths 5
8.01k
| problem
stringlengths 13
51.2k
| output
stringlengths 0
3.87M
|
---|---|---|---|---|---|---|---|---|---|
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/api/v1/historical_handlers.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L781-L787 | go | train | // extractMetricValue checks to see if the given metric was present in the results, and if so,
// returns it in API form | func extractMetricValue(aggregations *core.AggregationValue, aggName core.AggregationType) *types.MetricValue | // extractMetricValue checks to see if the given metric was present in the results, and if so,
// returns it in API form
func extractMetricValue(aggregations *core.AggregationValue, aggName core.AggregationType) *types.MetricValue | {
if inputVal, ok := aggregations.Aggregations[aggName]; ok {
return exportMetricValue(&inputVal)
} else {
return nil
}
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/api/v1/historical_handlers.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L790-L828 | go | train | // exportTimestampedAggregationValue converts a core.TimestampedAggregationValue into an API MetricAggregationResult | func exportTimestampedAggregationValue(values []core.TimestampedAggregationValue) types.MetricAggregationResult | // exportTimestampedAggregationValue converts a core.TimestampedAggregationValue into an API MetricAggregationResult
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
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/api/v1/historical_handlers.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/api/v1/historical_handlers.go#L837-L848 | go | train | // getStartEndTimeHistorical fetches the start and end times of the request. Unlike
// getStartEndTime, this function returns an error if the start time is not passed
// (or is zero, since many things in go use time.Time{} as an empty value) --
// different sinks have different defaults, and certain sinks have issues if an actual
// time of zero (i.e. the epoch) is used (because that would be too many data points
// to consider in certain cases). Require applications to pass an explicit start time
// that they can deal with. | func getStartEndTimeHistorical(request *restful.Request) (time.Time, time.Time, error) | // getStartEndTimeHistorical fetches the start and end times of the request. Unlike
// getStartEndTime, this function returns an error if the start time is not passed
// (or is zero, since many things in go use time.Time{} as an empty value) --
// different sinks have different defaults, and certain sinks have issues if an actual
// time of zero (i.e. the epoch) is used (because that would be too many data points
// to consider in certain cases). Require applications to pass an explicit start time
// that they can deal with.
func getStartEndTimeHistorical(request *restful.Request) (time.Time, time.Time, error) | {
start, end, err := getStartEndTime(request)
if err != nil {
return start, end, err
}
if start.IsZero() {
return start, end, fmt.Errorf("no start time (or a start time of zero) provided")
}
return start, end, err
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/cmd/heapster-apiserver/app/heapstermetrics.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/cmd/heapster-apiserver/app/heapstermetrics.go#L62-L76 | go | train | // This function is directly copied from https://github.com/kubernetes/metrics/blob/master/pkg/apis/metrics/install/install.go#L31 with only changes by replacing v1beta1 to v1alpha1.
// This function should be deleted only after move metrics to v1beta1.
// Install registers the API group and adds types to a scheme | func install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *registered.APIRegistrationManager, scheme *runtime.Scheme) | // This function is directly copied from https://github.com/kubernetes/metrics/blob/master/pkg/apis/metrics/install/install.go#L31 with only changes by replacing v1beta1 to v1alpha1.
// This function should be deleted only after move metrics to v1beta1.
// Install registers the API group and adds types to a scheme
func install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *registered.APIRegistrationManager, scheme *runtime.Scheme) | {
if err := announced.NewGroupMetaFactory(
&announced.GroupMetaFactoryArgs{
GroupName: metrics.GroupName,
VersionPreferenceOrder: []string{metrics_api.SchemeGroupVersion.Version},
RootScopedKinds: sets.NewString("NodeMetrics"),
AddInternalObjectsToScheme: metrics.AddToScheme,
},
announced.VersionToSchemeFunc{
metrics_api.SchemeGroupVersion.Version: metrics_api.AddToScheme,
},
).Announce(groupFactoryRegistry).RegisterAndEnable(registry, scheme); err != nil {
panic(err)
}
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/storage/podmetrics/reststorage.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/storage/podmetrics/reststorage.go#L75-L97 | go | train | // Lister interface | func (m *MetricStorage) List(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (runtime.Object, error) | // Lister interface
func (m *MetricStorage) List(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (runtime.Object, error) | {
labelSelector := labels.Everything()
if options != nil && options.LabelSelector != nil {
labelSelector = options.LabelSelector
}
namespace := genericapirequest.NamespaceValue(ctx)
pods, err := m.podLister.Pods(namespace).List(labelSelector)
if err != nil {
errMsg := fmt.Errorf("Error while listing pods for selector %v: %v", labelSelector, err)
glog.Error(errMsg)
return &metrics.PodMetricsList{}, errMsg
}
res := metrics.PodMetricsList{}
for _, pod := range pods {
if podMetrics := m.getPodMetrics(pod); podMetrics != nil {
res.Items = append(res.Items, *podMetrics)
} else {
glog.Infof("No metrics for pod %s/%s", pod.Namespace, pod.Name)
}
}
return &res, nil
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/storage/podmetrics/reststorage.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/storage/podmetrics/reststorage.go#L100-L118 | go | train | // Getter interface | func (m *MetricStorage) Get(ctx genericapirequest.Context, name string, opts *metav1.GetOptions) (runtime.Object, error) | // Getter interface
func (m *MetricStorage) Get(ctx genericapirequest.Context, name string, opts *metav1.GetOptions) (runtime.Object, error) | {
namespace := genericapirequest.NamespaceValue(ctx)
pod, err := m.podLister.Pods(namespace).Get(name)
if err != nil {
errMsg := fmt.Errorf("Error while getting pod %v: %v", name, err)
glog.Error(errMsg)
return &metrics.PodMetrics{}, errMsg
}
if pod == nil {
return &metrics.PodMetrics{}, errors.NewNotFound(v1.Resource("Pod"), fmt.Sprintf("%v/%v", namespace, name))
}
podMetrics := m.getPodMetrics(pod)
if podMetrics == nil {
return &metrics.PodMetrics{}, errors.NewNotFound(m.groupResource, fmt.Sprintf("%v/%v", namespace, name))
}
return podMetrics, nil
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/sources/summary/summary.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sources/summary/summary.go#L120-L137 | go | train | // decodeSummary translates the kubelet statsSummary API into the flattened heapster MetricSet API. | func (this *summaryMetricsSource) decodeSummary(summary *stats.Summary) map[string]*MetricSet | // decodeSummary translates the kubelet statsSummary API into the flattened heapster MetricSet API.
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
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/sources/summary/summary.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sources/summary/summary.go#L140-L146 | go | train | // Convenience method for labels deep copy. | func (this *summaryMetricsSource) cloneLabels(labels map[string]string) map[string]string | // Convenience method for labels deep copy.
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
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/sources/summary/summary.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sources/summary/summary.go#L370-L381 | go | train | // addIntMetric is a convenience method for adding the metric and value to the metric set. | func (this *summaryMetricsSource) addIntMetric(metrics *MetricSet, metric *Metric, value *uint64) | // addIntMetric is a convenience method for adding the metric and value to the metric set.
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
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/sources/summary/summary.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sources/summary/summary.go#L384-L400 | go | train | // addLabeledIntMetric is a convenience method for adding the labeled metric and value to the metric set. | func (this *summaryMetricsSource) addLabeledIntMetric(metrics *MetricSet, metric *Metric, labels map[string]string, value *uint64) | // addLabeledIntMetric is a convenience method for adding the labeled metric and value to the metric set.
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)
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/sources/summary/summary.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sources/summary/summary.go#L403-L408 | go | train | // Translate system container names to the legacy names for backwards compatibility. | func (this *summaryMetricsSource) getSystemContainerName(c *stats.ContainerStats) string | // Translate system container names to the legacy names for backwards compatibility.
func (this *summaryMetricsSource) getSystemContainerName(c *stats.ContainerStats) string | {
if legacyName, ok := systemNameMap[c.Name]; ok {
return legacyName
}
return c.Name
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | common/riemann/riemann.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/common/riemann/riemann.go#L45-L99 | go | train | // creates a Riemann sink. Returns a riemannSink | func CreateRiemannSink(uri *url.URL) (*RiemannSink, error) | // creates a Riemann sink. Returns a riemannSink
func CreateRiemannSink(uri *url.URL) (*RiemannSink, error) | {
// Default configuration
c := RiemannConfig{
Host: "riemann-heapster:5555",
Ttl: 60.0,
State: "",
Tags: make([]string, 0),
BatchSize: 1000,
}
// check host
if len(uri.Host) > 0 {
c.Host = uri.Host
}
options := uri.Query()
// check ttl
if len(options["ttl"]) > 0 {
var ttl, err = strconv.ParseFloat(options["ttl"][0], 32)
if err != nil {
return nil, err
}
c.Ttl = float32(ttl)
}
// check batch size
if len(options["batchsize"]) > 0 {
var batchSize, err = strconv.Atoi(options["batchsize"][0])
if err != nil {
return nil, err
}
c.BatchSize = batchSize
}
// check state
if len(options["state"]) > 0 {
c.State = options["state"][0]
}
// check tags
if len(options["tags"]) > 0 {
c.Tags = options["tags"]
} else {
c.Tags = []string{"heapster"}
}
glog.Infof("Riemann sink URI: '%+v', host: '%+v', options: '%+v', ", uri, c.Host, options)
rs := &RiemannSink{
Client: nil,
Config: c,
}
client, err := GetRiemannClient(rs.Config)
if err != nil {
glog.Warningf("Riemann sink not connected: %v", err)
// Warn but return the sink => the client in the sink can be nil
}
rs.Client = client
return rs, nil
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | common/riemann/riemann.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/common/riemann/riemann.go#L102-L112 | go | train | // Receives a sink, connect the riemann client. | func GetRiemannClient(config RiemannConfig) (riemanngo.Client, error) | // Receives a sink, connect the riemann client.
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
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | common/riemann/riemann.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/common/riemann/riemann.go#L115-L131 | go | train | // Send Events to Riemann using the client from the sink. | func SendData(client riemanngo.Client, events []riemanngo.Event) error | // Send Events to Riemann using the client from the sink.
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
}
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/auth.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/auth.go#L70-L87 | go | train | // newAuthenticatorFromClientCAFile returns an authenticator.Request or an error | func newAuthenticatorFromClientCAFile(clientCAFile string) (authenticator.Request, error) | // newAuthenticatorFromClientCAFile returns an authenticator.Request or an error
func newAuthenticatorFromClientCAFile(clientCAFile string) (authenticator.Request, error) | {
opts := x509request.DefaultVerifyOptions()
// If at custom CA bundle is provided, load it (otherwise just use system roots)
if len(clientCAFile) > 0 {
if caData, err := ioutil.ReadFile(clientCAFile); err != nil {
return nil, err
} else if len(caData) > 0 {
roots := x509.NewCertPool()
if !roots.AppendCertsFromPEM(caData) {
return nil, fmt.Errorf("no valid certs found in %s", clientCAFile)
}
opts.Roots = roots
}
}
return x509request.New(opts, x509request.CommonNameUserConversion), nil
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | events/sinks/manager.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/events/sinks/manager.go#L96-L114 | go | train | // Guarantees that the export will complete in exportEventsTimeout. | func (this *sinkManager) ExportEvents(data *core.EventBatch) | // Guarantees that the export will complete in exportEventsTimeout.
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()
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/sinks/hawkular/client.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/client.go#L32-L47 | go | train | // cacheDefinitions Fetches all known definitions from all tenants (all projects in Openshift) | func (h *hawkularSink) cacheDefinitions() error | // cacheDefinitions Fetches all known definitions from all tenants (all projects in Openshift)
func (h *hawkularSink) cacheDefinitions() error | {
if !h.disablePreCaching {
mds, err := h.client.AllDefinitions(h.modifiers...)
if err != nil {
return err
}
err = h.updateDefinitions(mds)
if err != nil {
return err
}
}
glog.V(4).Infof("Hawkular definition pre-caching completed, cached %d definitions\n", len(h.expReg))
return nil
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/sinks/hawkular/client.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/client.go#L50-L52 | go | train | // cache inserts the item to the cache | func (h *hawkularSink) cache(md *metrics.MetricDefinition) | // cache inserts the item to the cache
func (h *hawkularSink) cache(md *metrics.MetricDefinition) | {
h.pushToCache(md.ID, hashDefinition(md))
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/sinks/hawkular/client.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/client.go#L55-L62 | go | train | // toCache inserts the item and updates the TTL in the cache to current time | func (h *hawkularSink) pushToCache(key string, hash uint64) | // toCache inserts the item and updates the TTL in the cache to current time
func (h *hawkularSink) pushToCache(key string, hash uint64) | {
h.regLock.Lock()
h.expReg[key] = &expiringItem{
hash: hash,
ttl: h.runId,
}
h.regLock.Unlock()
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/sinks/hawkular/client.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/client.go#L65-L75 | go | train | // checkCache returns false if the cached instance is not current. Updates the TTL in the cache | func (h *hawkularSink) checkCache(key string, hash uint64) bool | // checkCache returns false if the cached instance is not current. Updates the TTL in the cache
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
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/sinks/hawkular/client.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/client.go#L78-L87 | go | train | // expireCache will process the map and check for any item that has been expired and release it | func (h *hawkularSink) expireCache(runId uint64) | // expireCache will process the map and check for any item that has been expired and release it
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)
}
}
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/sinks/hawkular/client.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/client.go#L90-L101 | go | train | // Fetches definitions from the server and checks that they're matching the descriptors | func (h *hawkularSink) updateDefinitions(mds []*metrics.MetricDefinition) error | // Fetches definitions from the server and checks that they're matching the descriptors
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
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/sinks/hawkular/client.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/client.go#L125-L136 | go | train | // Checks that stored definition is up to date with the model | func (h *hawkularSink) recent(live *metrics.MetricDefinition, model *metrics.MetricDefinition) bool | // Checks that stored definition is up to date with the model
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
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/sinks/hawkular/client.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/client.go#L139-L161 | go | train | // Transform the MetricDescriptor to a format used by Hawkular-Metrics | func (h *hawkularSink) descriptorToDefinition(md *core.MetricDescriptor) metrics.MetricDefinition | // Transform the MetricDescriptor to a format used by Hawkular-Metrics
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
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/sinks/hawkular/client.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/client.go#L356-L382 | go | train | // Converts Timeseries to metric structure used by the Hawkular | func (h *hawkularSink) pointToLabeledMetricHeader(ms *core.MetricSet, metric core.LabeledMetric, timestamp time.Time) (*metrics.MetricHeader, error) | // Converts Timeseries to metric structure used by the Hawkular
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
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/sinks/hawkular/client.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/sinks/hawkular/client.go#L385-L426 | go | train | // If Heapster gets filters, remove these.. | func parseFilters(v []string) ([]Filter, error) | // If Heapster gets filters, remove these..
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
} |
kubernetes-retired/heapster | e1e83412787b60d8a70088f09a2cb12339b305c3 | metrics/heapster.go | https://github.com/kubernetes-retired/heapster/blob/e1e83412787b60d8a70088f09a2cb12339b305c3/metrics/heapster.go#L318-L325 | go | train | // Gets the address of the kubernetes source from the list of source URIs.
// Possible kubernetes sources are: 'kubernetes' and 'kubernetes.summary_api' | func getKubernetesAddress(args flags.Uris) (*url.URL, error) | // Gets the address of the kubernetes source from the list of source URIs.
// Possible kubernetes sources are: 'kubernetes' and 'kubernetes.summary_api'
func getKubernetesAddress(args flags.Uris) (*url.URL, error) | {
for _, uri := range args {
if strings.SplitN(uri.Key, ".", 2)[0] == "kubernetes" {
return &uri.Val, nil
}
}
return nil, fmt.Errorf("No kubernetes source found.")
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | _demos/mouse.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/_demos/mouse.go#L101-L250 | go | train | // This program just shows simple mouse and keyboard events. Press ESC twice to
// exit. | func main() | // This program just shows simple mouse and keyboard events. Press ESC twice to
// exit.
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)
}
}
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | encoding.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/encoding.go#L71-L76 | go | train | // RegisterEncoding may be called by the application to register an encoding.
// The presence of additional encodings will facilitate application usage with
// terminal environments where the I/O subsystem does not support Unicode.
//
// Windows systems use Unicode natively, and do not need any of the encoding
// subsystem when using Windows Console screens.
//
// Please see the Go documentation for golang.org/x/text/encoding -- most of
// the common ones exist already as stock variables. For example, ISO8859-15
// can be registered using the following code:
//
// import "golang.org/x/text/encoding/charmap"
//
// ...
// RegisterEncoding("ISO8859-15", charmap.ISO8859_15)
//
// Aliases can be registered as well, for example "8859-15" could be an alias
// for "ISO8859-15".
//
// For POSIX systems, the tcell package will check the environment variables
// LC_ALL, LC_CTYPE, and LANG (in that order) to determine the character set.
// These are expected to have the following pattern:
//
// $language[.$codeset[@$variant]
//
// We extract only the $codeset part, which will usually be something like
// UTF-8 or ISO8859-15 or KOI8-R. Note that if the locale is either "POSIX"
// or "C", then we assume US-ASCII (the POSIX 'portable character set'
// and assume all other characters are somehow invalid.)
//
// Modern POSIX systems and terminal emulators may use UTF-8, and for those
// systems, this API is also unnecessary. For example, Darwin (MacOS X) and
// modern Linux running modern xterm generally will out of the box without
// any of this. Use of UTF-8 is recommended when possible, as it saves
// quite a lot processing overhead.
//
// Note that some encodings are quite large (for example GB18030 which is a
// superset of Unicode) and so the application size can be expected ot
// increase quite a bit as each encoding is added. The East Asian encodings
// have been seen to add 100-200K per encoding to the application size.
// | func RegisterEncoding(charset string, enc encoding.Encoding) | // RegisterEncoding may be called by the application to register an encoding.
// The presence of additional encodings will facilitate application usage with
// terminal environments where the I/O subsystem does not support Unicode.
//
// Windows systems use Unicode natively, and do not need any of the encoding
// subsystem when using Windows Console screens.
//
// Please see the Go documentation for golang.org/x/text/encoding -- most of
// the common ones exist already as stock variables. For example, ISO8859-15
// can be registered using the following code:
//
// import "golang.org/x/text/encoding/charmap"
//
// ...
// RegisterEncoding("ISO8859-15", charmap.ISO8859_15)
//
// Aliases can be registered as well, for example "8859-15" could be an alias
// for "ISO8859-15".
//
// For POSIX systems, the tcell package will check the environment variables
// LC_ALL, LC_CTYPE, and LANG (in that order) to determine the character set.
// These are expected to have the following pattern:
//
// $language[.$codeset[@$variant]
//
// We extract only the $codeset part, which will usually be something like
// UTF-8 or ISO8859-15 or KOI8-R. Note that if the locale is either "POSIX"
// or "C", then we assume US-ASCII (the POSIX 'portable character set'
// and assume all other characters are somehow invalid.)
//
// Modern POSIX systems and terminal emulators may use UTF-8, and for those
// systems, this API is also unnecessary. For example, Darwin (MacOS X) and
// modern Linux running modern xterm generally will out of the box without
// any of this. Use of UTF-8 is recommended when possible, as it saves
// quite a lot processing overhead.
//
// Note that some encodings are quite large (for example GB18030 which is a
// superset of Unicode) and so the application size can be expected ot
// increase quite a bit as each encoding is added. The East Asian encodings
// have been seen to add 100-200K per encoding to the application size.
//
func RegisterEncoding(charset string, enc encoding.Encoding) | {
encodingLk.Lock()
charset = strings.ToLower(charset)
encodings[charset] = enc
encodingLk.Unlock()
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | encoding.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/encoding.go#L115-L129 | go | train | // GetEncoding is used by Screen implementors who want to locate an encoding
// for the given character set name. Note that this will return nil for
// either the Unicode (UTF-8) or ASCII encodings, since we don't use
// encodings for them but instead have our own native methods. | func GetEncoding(charset string) encoding.Encoding | // GetEncoding is used by Screen implementors who want to locate an encoding
// for the given character set name. Note that this will return nil for
// either the Unicode (UTF-8) or ASCII encodings, since we don't use
// encodings for them but instead have our own native methods.
func GetEncoding(charset string) encoding.Encoding | {
charset = strings.ToLower(charset)
encodingLk.Lock()
defer encodingLk.Unlock()
if enc, ok := encodings[charset]; ok {
return enc
}
switch encodingFallback {
case EncodingFallbackASCII:
return gencoding.ASCII
case EncodingFallbackUTF8:
return encoding.Nop
}
return nil
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/view.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L73-L81 | go | train | // Fill fills the displayed view port with the given character and style. | func (v *ViewPort) Fill(ch rune, style tcell.Style) | // Fill fills the displayed view port with the given character and 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)
}
}
}
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/view.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L91-L96 | go | train | // 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. | func (v *ViewPort) Reset() | // 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.
func (v *ViewPort) Reset() | {
v.limx = 0
v.limy = 0
v.viewx = 0
v.viewy = 0
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/view.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L104-L124 | go | train | // SetContent is used to place data at the given cell location. Note that
// since the ViewPort doesn't retain this data, if the location is outside
// of the visible area, it is simply discarded.
//
// Generally, this is called during the Draw() phase by the object that
// represents the content. | func (v *ViewPort) SetContent(x, y int, ch rune, comb []rune, s tcell.Style) | // SetContent is used to place data at the given cell location. Note that
// since the ViewPort doesn't retain this data, if the location is outside
// of the visible area, it is simply discarded.
//
// Generally, this is called during the Draw() phase by the object that
// represents the content.
func (v *ViewPort) SetContent(x, y int, ch rune, comb []rune, s tcell.Style) | {
if v.v == nil {
return
}
if x > v.limx && !v.locked {
v.limx = x
}
if y > v.limy && !v.locked {
v.limy = y
}
if x < v.viewx || y < v.viewy {
return
}
if x >= (v.viewx + v.width) {
return
}
if y >= (v.viewy + v.height) {
return
}
v.v.SetContent(x-v.viewx+v.physx, y-v.viewy+v.physy, ch, comb, s)
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/view.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L130-L144 | go | train | // 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. | func (v *ViewPort) MakeVisible(x, y int) | // 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.
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()
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/view.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L148-L155 | go | train | // ValidateViewY ensures that the Y offset of the view port is limited so that
// it cannot scroll away from the content. | func (v *ViewPort) ValidateViewY() | // ValidateViewY ensures that the Y offset of the view port is limited so that
// it cannot scroll away from the content.
func (v *ViewPort) ValidateViewY() | {
if v.viewy >= v.limy-v.height {
v.viewy = (v.limy - v.height)
}
if v.viewy < 0 {
v.viewy = 0
}
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/view.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L159-L166 | go | train | // ValidateViewX ensures that the X offset of the view port is limited so that
// it cannot scroll away from the content. | func (v *ViewPort) ValidateViewX() | // ValidateViewX ensures that the X offset of the view port is limited so that
// it cannot scroll away from the content.
func (v *ViewPort) ValidateViewX() | {
if v.viewx >= v.limx-v.width {
v.viewx = (v.limx - v.width)
}
if v.viewx < 0 {
v.viewx = 0
}
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/view.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L176-L183 | go | train | // Center centers the point, if possible, in the View. | func (v *ViewPort) Center(x, y int) | // Center centers the point, if possible, in the View.
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()
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/view.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L186-L189 | go | train | // ScrollUp moves the view up, showing lower numbered rows of content. | func (v *ViewPort) ScrollUp(rows int) | // ScrollUp moves the view up, showing lower numbered rows of content.
func (v *ViewPort) ScrollUp(rows int) | {
v.viewy -= rows
v.ValidateViewY()
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/view.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L192-L195 | go | train | // ScrollDown moves the view down, showingh higher numbered rows of content. | func (v *ViewPort) ScrollDown(rows int) | // ScrollDown moves the view down, showingh higher numbered rows of content.
func (v *ViewPort) ScrollDown(rows int) | {
v.viewy += rows
v.ValidateViewY()
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/view.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L198-L201 | go | train | // ScrollLeft moves the view to the left. | func (v *ViewPort) ScrollLeft(cols int) | // ScrollLeft moves the view to the left.
func (v *ViewPort) ScrollLeft(cols int) | {
v.viewx -= cols
v.ValidateViewX()
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/view.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L204-L207 | go | train | // ScrollRight moves the view to the left. | func (v *ViewPort) ScrollRight(cols int) | // ScrollRight moves the view to the left.
func (v *ViewPort) ScrollRight(cols int) | {
v.viewx += cols
v.ValidateViewX()
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/view.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L211-L215 | go | train | // 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. | func (v *ViewPort) SetSize(width, height int) | // 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.
func (v *ViewPort) SetSize(width, height int) | {
v.height = height
v.width = width
v.ValidateView()
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/view.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L222-L224 | go | train | // 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. | func (v *ViewPort) GetVisible() (int, int, int, int) | // 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.
func (v *ViewPort) GetVisible() (int, int, int, int) | {
return v.viewx, v.viewy, v.viewx + v.width - 1, v.viewy + v.height - 1
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/view.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L229-L231 | go | train | // 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. | func (v *ViewPort) GetPhysical() (int, int, int, int) | // 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.
func (v *ViewPort) GetPhysical() (int, int, int, int) | {
return v.physx, v.physy, v.physx + v.width - 1, v.physy + v.height - 1
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/view.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L239-L244 | go | train | // SetContentSize sets the size of the content area; this is used to limit
// scrolling and view moment. If locked is true, then the content size will
// not automatically grow even if content is placed outside of this area
// with the SetContent() method. If false, and content is drawn outside
// of the existing size, then the size will automatically grow to include
// the new content. | func (v *ViewPort) SetContentSize(width, height int, locked bool) | // SetContentSize sets the size of the content area; this is used to limit
// scrolling and view moment. If locked is true, then the content size will
// not automatically grow even if content is placed outside of this area
// with the SetContent() method. If false, and content is drawn outside
// of the existing size, then the size will automatically grow to include
// the new content.
func (v *ViewPort) SetContentSize(width, height int, locked bool) | {
v.limx = width
v.limy = height
v.locked = locked
v.ValidateView()
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/view.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L257-L280 | go | train | // 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. | func (v *ViewPort) Resize(x, y, width, height int) | // 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.
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
}
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/view.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/view.go#L292-L300 | go | train | // NewViewPort returns a new ViewPort (and hence also a View).
// The x and y coordinates are an offset relative to the parent.
// The origin 0,0 represents the upper left. The width and height
// indicate a width and height. If the value -1 is supplied, then the
// dimension is calculated from the parent. | func NewViewPort(view View, x, y, width, height int) *ViewPort | // NewViewPort returns a new ViewPort (and hence also a View).
// The x and y coordinates are an offset relative to the parent.
// The origin 0,0 represents the upper left. The width and height
// indicate a width and height. If the value -1 is supplied, then the
// dimension is calculated from the parent.
func NewViewPort(view View, x, y, width, height int) *ViewPort | {
v := &ViewPort{v: view}
// initial (and possibly poor) assumptions -- all visible
// cells are addressible, but none beyond that.
v.limx = width
v.limy = height
v.Resize(x, y, width, height)
return v
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/textbar.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textbar.go#L44-L51 | go | train | // SetCenter sets the center text for the textbar. The text is
// always center aligned. | func (t *TextBar) SetCenter(s string, style tcell.Style) | // SetCenter sets the center text for the textbar. The text is
// always center aligned.
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)
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/textbar.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textbar.go#L54-L61 | go | train | // SetLeft sets the left text for the textbar. It is always left-aligned. | func (t *TextBar) SetLeft(s string, style tcell.Style) | // SetLeft sets the left text for the textbar. It is always left-aligned.
func (t *TextBar) SetLeft(s string, style tcell.Style) | {
t.initialize()
if style == tcell.StyleDefault {
style = t.style
}
t.left.SetText(s)
t.left.SetStyle(style)
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/textbar.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textbar.go#L64-L71 | go | train | // SetRight sets the right text for the textbar. It is always right-aligned. | func (t *TextBar) SetRight(s string, style tcell.Style) | // SetRight sets the right text for the textbar. It is always right-aligned.
func (t *TextBar) SetRight(s string, style tcell.Style) | {
t.initialize()
if style == tcell.StyleDefault {
style = t.style
}
t.right.SetText(s)
t.right.SetStyle(style)
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/textbar.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textbar.go#L76-L79 | go | train | // 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. | func (t *TextBar) SetStyle(style tcell.Style) | // 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.
func (t *TextBar) SetStyle(style tcell.Style) | {
t.initialize()
t.style = style
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/textbar.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textbar.go#L110-L117 | go | train | // SetView sets the View drawing context for this TextBar. | func (t *TextBar) SetView(view View) | // SetView sets the View drawing context for this TextBar.
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
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/textbar.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textbar.go#L120-L138 | go | train | // Draw draws the TextBar into its View context. | func (t *TextBar) Draw() | // Draw draws the TextBar into its View context.
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()
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/textbar.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textbar.go#L142-L151 | go | train | // Resize is called when the TextBar's View changes size, and
// updates the layout. | func (t *TextBar) Resize() | // Resize is called when the TextBar's View changes size, and
// updates the layout.
func (t *TextBar) Resize() | {
t.initialize()
t.layout()
t.left.Resize()
t.center.Resize()
t.right.Resize()
t.PostEventWidgetResize(t)
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/textbar.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textbar.go#L155-L174 | go | train | // Size implements the Size method for Widget, returning the width
// and height in character cells. | func (t *TextBar) Size() (int, int) | // Size implements the Size method for Widget, returning the width
// and height in character cells.
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
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/textbar.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textbar.go#L179-L186 | go | train | // HandleEvent handles incoming events. The only events handled are
// those for the Text objects; when those change, the TextBar adjusts
// the layout to accommodate. | func (t *TextBar) HandleEvent(ev tcell.Event) bool | // HandleEvent handles incoming events. The only events handled are
// those for the Text objects; when those change, the TextBar adjusts
// the layout to accommodate.
func (t *TextBar) HandleEvent(ev tcell.Event) bool | {
switch ev.(type) {
case *EventWidgetContent:
t.changed = true
return true
}
return false
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | color.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/color.go#L975-L983 | go | train | // 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. | func (c Color) Hex() int32 | // 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.
func (c Color) Hex() int32 | {
if c&ColorIsRGB != 0 {
return (int32(c) & 0xffffff)
}
if v, ok := ColorValues[c]; ok {
return v
}
return -1
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | color.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/color.go#L988-L994 | go | train | // RGB returns the red, green, and blue components of the color, with
// each component represented as a value 0-255. In the event that the
// color cannot be broken up (not set usually), -1 is returned for each value. | func (c Color) RGB() (int32, int32, int32) | // RGB returns the red, green, and blue components of the color, with
// each component represented as a value 0-255. In the event that the
// color cannot be broken up (not set usually), -1 is returned for each value.
func (c Color) RGB() (int32, int32, int32) | {
v := c.Hex()
if v < 0 {
return -1, -1, -1
}
return (v >> 16) & 0xff, (v >> 8) & 0xff, v & 0xff
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | color.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/color.go#L998-L1000 | go | train | // NewRGBColor returns a new color with the given red, green, and blue values.
// Each value must be represented in the range 0-255. | func NewRGBColor(r, g, b int32) Color | // NewRGBColor returns a new color with the given red, green, and blue values.
// Each value must be represented in the range 0-255.
func NewRGBColor(r, g, b int32) Color | {
return NewHexColor(((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff))
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | color.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/color.go#L1009-L1019 | go | train | // GetColor creates a Color from a color name (W3C name). A hex value may
// be supplied as a string in the format "#ffffff". | func GetColor(name string) Color | // GetColor creates a Color from a color name (W3C name). A hex value may
// be supplied as a string in the format "#ffffff".
func GetColor(name string) Color | {
if c, ok := ColorNames[name]; ok {
return c
}
if len(name) == 7 && name[0] == '#' {
if v, e := strconv.ParseInt(name[1:], 16, 32); e == nil {
return NewHexColor(int32(v))
}
}
return ColorDefault
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | cell.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/cell.go#L45-L59 | go | train | // SetContent sets the contents (primary rune, combining runes,
// and style) for a cell at a given location. | func (cb *CellBuffer) SetContent(x int, y int,
mainc rune, combc []rune, style Style) | // SetContent sets the contents (primary rune, combining runes,
// and style) for a cell at a given location.
func (cb *CellBuffer) SetContent(x int, y int,
mainc rune, combc []rune, style Style) | {
if x >= 0 && y >= 0 && x < cb.w && y < cb.h {
c := &cb.cells[(y*cb.w)+x]
c.currComb = append([]rune{}, combc...)
if c.currMain != mainc {
c.width = runewidth.RuneWidth(mainc)
}
c.currMain = mainc
c.currStyle = style
}
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | cell.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/cell.go#L65-L79 | go | train | // GetContent returns the contents of a character cell, including the
// primary rune, any combining character runes (which will usually be
// nil), the style, and the display width in cells. (The width can be
// either 1, normally, or 2 for East Asian full-width characters.) | func (cb *CellBuffer) GetContent(x, y int) (rune, []rune, Style, int) | // GetContent returns the contents of a character cell, including the
// primary rune, any combining character runes (which will usually be
// nil), the style, and the display width in cells. (The width can be
// either 1, normally, or 2 for East Asian full-width characters.)
func (cb *CellBuffer) GetContent(x, y int) (rune, []rune, Style, int) | {
var mainc rune
var combc []rune
var style Style
var width int
if x >= 0 && y >= 0 && x < cb.w && y < cb.h {
c := &cb.cells[(y*cb.w)+x]
mainc, combc, style = c.currMain, c.currComb, c.currStyle
if width = c.width; width == 0 || mainc < ' ' {
width = 1
mainc = ' '
}
}
return mainc, combc, style, width
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | cell.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/cell.go#L87-L91 | go | train | // Invalidate marks all characters within the buffer as dirty. | func (cb *CellBuffer) Invalidate() | // Invalidate marks all characters within the buffer as dirty.
func (cb *CellBuffer) Invalidate() | {
for i := range cb.cells {
cb.cells[i].lastMain = rune(0)
}
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | cell.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/cell.go#L97-L119 | go | train | // 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. | func (cb *CellBuffer) Dirty(x, y int) bool | // 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.
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
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | cell.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/cell.go#L124-L138 | go | train | // SetDirty is normally used to indicate that a cell has
// been displayed (in which case dirty is false), or to manually
// force a cell to be marked dirty. | func (cb *CellBuffer) SetDirty(x, y int, dirty bool) | // SetDirty is normally used to indicate that a cell has
// been displayed (in which case dirty is false), or to manually
// force a cell to be marked dirty.
func (cb *CellBuffer) SetDirty(x, y int, dirty bool) | {
if x >= 0 && y >= 0 && x < cb.w && y < cb.h {
c := &cb.cells[(y*cb.w)+x]
if dirty {
c.lastMain = rune(0)
} else {
if c.currMain == rune(0) {
c.currMain = ' '
}
c.lastMain = c.currMain
c.lastComb = c.currComb
c.lastStyle = c.currStyle
}
}
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | cell.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/cell.go#L143-L164 | go | train | // 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. | func (cb *CellBuffer) Resize(w, h int) | // 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.
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
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | cell.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/cell.go#L169-L177 | go | train | // 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. | func (cb *CellBuffer) Fill(r rune, style Style) | // 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.
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
}
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | terminfo/mkinfo.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/terminfo/mkinfo.go#L229-L469 | go | train | // This program is used to collect data from the system's terminfo library,
// and write it into Go source code. That is, we maintain our terminfo
// capabilities encoded in the program. It should never need to be run by
// an end user, but developers can use this to add codes for additional
// terminal types. | func getinfo(name string) (*terminfo.Terminfo, string, error) | // This program is used to collect data from the system's terminfo library,
// and write it into Go source code. That is, we maintain our terminfo
// capabilities encoded in the program. It should never need to be run by
// an end user, but developers can use this to add codes for additional
// terminal types.
func getinfo(name string) (*terminfo.Terminfo, string, error) | {
var tc termcap
if err := tc.setupterm(name); err != nil {
if err != nil {
return nil, "", err
}
}
t := &terminfo.Terminfo{}
// If this is an alias record, then just emit the alias
t.Name = tc.name
if t.Name != name {
return t, "", nil
}
t.Aliases = tc.aliases
t.Colors = tc.getnum("colors")
t.Columns = tc.getnum("cols")
t.Lines = tc.getnum("lines")
t.Bell = tc.getstr("bel")
t.Clear = tc.getstr("clear")
t.EnterCA = tc.getstr("smcup")
t.ExitCA = tc.getstr("rmcup")
t.ShowCursor = tc.getstr("cnorm")
t.HideCursor = tc.getstr("civis")
t.AttrOff = tc.getstr("sgr0")
t.Underline = tc.getstr("smul")
t.Bold = tc.getstr("bold")
t.Blink = tc.getstr("blink")
t.Dim = tc.getstr("dim")
t.Reverse = tc.getstr("rev")
t.EnterKeypad = tc.getstr("smkx")
t.ExitKeypad = tc.getstr("rmkx")
t.SetFg = tc.getstr("setaf")
t.SetBg = tc.getstr("setab")
t.SetCursor = tc.getstr("cup")
t.CursorBack1 = tc.getstr("cub1")
t.CursorUp1 = tc.getstr("cuu1")
t.KeyF1 = tc.getstr("kf1")
t.KeyF2 = tc.getstr("kf2")
t.KeyF3 = tc.getstr("kf3")
t.KeyF4 = tc.getstr("kf4")
t.KeyF5 = tc.getstr("kf5")
t.KeyF6 = tc.getstr("kf6")
t.KeyF7 = tc.getstr("kf7")
t.KeyF8 = tc.getstr("kf8")
t.KeyF9 = tc.getstr("kf9")
t.KeyF10 = tc.getstr("kf10")
t.KeyF11 = tc.getstr("kf11")
t.KeyF12 = tc.getstr("kf12")
t.KeyF13 = tc.getstr("kf13")
t.KeyF14 = tc.getstr("kf14")
t.KeyF15 = tc.getstr("kf15")
t.KeyF16 = tc.getstr("kf16")
t.KeyF17 = tc.getstr("kf17")
t.KeyF18 = tc.getstr("kf18")
t.KeyF19 = tc.getstr("kf19")
t.KeyF20 = tc.getstr("kf20")
t.KeyF21 = tc.getstr("kf21")
t.KeyF22 = tc.getstr("kf22")
t.KeyF23 = tc.getstr("kf23")
t.KeyF24 = tc.getstr("kf24")
t.KeyF25 = tc.getstr("kf25")
t.KeyF26 = tc.getstr("kf26")
t.KeyF27 = tc.getstr("kf27")
t.KeyF28 = tc.getstr("kf28")
t.KeyF29 = tc.getstr("kf29")
t.KeyF30 = tc.getstr("kf30")
t.KeyF31 = tc.getstr("kf31")
t.KeyF32 = tc.getstr("kf32")
t.KeyF33 = tc.getstr("kf33")
t.KeyF34 = tc.getstr("kf34")
t.KeyF35 = tc.getstr("kf35")
t.KeyF36 = tc.getstr("kf36")
t.KeyF37 = tc.getstr("kf37")
t.KeyF38 = tc.getstr("kf38")
t.KeyF39 = tc.getstr("kf39")
t.KeyF40 = tc.getstr("kf40")
t.KeyF41 = tc.getstr("kf41")
t.KeyF42 = tc.getstr("kf42")
t.KeyF43 = tc.getstr("kf43")
t.KeyF44 = tc.getstr("kf44")
t.KeyF45 = tc.getstr("kf45")
t.KeyF46 = tc.getstr("kf46")
t.KeyF47 = tc.getstr("kf47")
t.KeyF48 = tc.getstr("kf48")
t.KeyF49 = tc.getstr("kf49")
t.KeyF50 = tc.getstr("kf50")
t.KeyF51 = tc.getstr("kf51")
t.KeyF52 = tc.getstr("kf52")
t.KeyF53 = tc.getstr("kf53")
t.KeyF54 = tc.getstr("kf54")
t.KeyF55 = tc.getstr("kf55")
t.KeyF56 = tc.getstr("kf56")
t.KeyF57 = tc.getstr("kf57")
t.KeyF58 = tc.getstr("kf58")
t.KeyF59 = tc.getstr("kf59")
t.KeyF60 = tc.getstr("kf60")
t.KeyF61 = tc.getstr("kf61")
t.KeyF62 = tc.getstr("kf62")
t.KeyF63 = tc.getstr("kf63")
t.KeyF64 = tc.getstr("kf64")
t.KeyInsert = tc.getstr("kich1")
t.KeyDelete = tc.getstr("kdch1")
t.KeyBackspace = tc.getstr("kbs")
t.KeyHome = tc.getstr("khome")
t.KeyEnd = tc.getstr("kend")
t.KeyUp = tc.getstr("kcuu1")
t.KeyDown = tc.getstr("kcud1")
t.KeyRight = tc.getstr("kcuf1")
t.KeyLeft = tc.getstr("kcub1")
t.KeyPgDn = tc.getstr("knp")
t.KeyPgUp = tc.getstr("kpp")
t.KeyBacktab = tc.getstr("kcbt")
t.KeyExit = tc.getstr("kext")
t.KeyCancel = tc.getstr("kcan")
t.KeyPrint = tc.getstr("kprt")
t.KeyHelp = tc.getstr("khlp")
t.KeyClear = tc.getstr("kclr")
t.AltChars = tc.getstr("acsc")
t.EnterAcs = tc.getstr("smacs")
t.ExitAcs = tc.getstr("rmacs")
t.EnableAcs = tc.getstr("enacs")
t.Mouse = tc.getstr("kmous")
t.KeyShfRight = tc.getstr("kRIT")
t.KeyShfLeft = tc.getstr("kLFT")
t.KeyShfHome = tc.getstr("kHOM")
t.KeyShfEnd = tc.getstr("kEND")
// Terminfo lacks descriptions for a bunch of modified keys,
// but modern XTerm and emulators often have them. Let's add them,
// if the shifted right and left arrows are defined.
if t.KeyShfRight == "\x1b[1;2C" && t.KeyShfLeft == "\x1b[1;2D" {
t.KeyShfUp = "\x1b[1;2A"
t.KeyShfDown = "\x1b[1;2B"
t.KeyMetaUp = "\x1b[1;9A"
t.KeyMetaDown = "\x1b[1;9B"
t.KeyMetaRight = "\x1b[1;9C"
t.KeyMetaLeft = "\x1b[1;9D"
t.KeyAltUp = "\x1b[1;3A"
t.KeyAltDown = "\x1b[1;3B"
t.KeyAltRight = "\x1b[1;3C"
t.KeyAltLeft = "\x1b[1;3D"
t.KeyCtrlUp = "\x1b[1;5A"
t.KeyCtrlDown = "\x1b[1;5B"
t.KeyCtrlRight = "\x1b[1;5C"
t.KeyCtrlLeft = "\x1b[1;5D"
t.KeyAltShfUp = "\x1b[1;4A"
t.KeyAltShfDown = "\x1b[1;4B"
t.KeyAltShfRight = "\x1b[1;4C"
t.KeyAltShfLeft = "\x1b[1;4D"
t.KeyMetaShfUp = "\x1b[1;10A"
t.KeyMetaShfDown = "\x1b[1;10B"
t.KeyMetaShfRight = "\x1b[1;10C"
t.KeyMetaShfLeft = "\x1b[1;10D"
t.KeyCtrlShfUp = "\x1b[1;6A"
t.KeyCtrlShfDown = "\x1b[1;6B"
t.KeyCtrlShfRight = "\x1b[1;6C"
t.KeyCtrlShfLeft = "\x1b[1;6D"
}
// And also for Home and End
if t.KeyShfHome == "\x1b[1;2H" && t.KeyShfEnd == "\x1b[1;2F" {
t.KeyCtrlHome = "\x1b[1;5H"
t.KeyCtrlEnd = "\x1b[1;5F"
t.KeyAltHome = "\x1b[1;9H"
t.KeyAltEnd = "\x1b[1;9F"
t.KeyCtrlShfHome = "\x1b[1;6H"
t.KeyCtrlShfEnd = "\x1b[1;6F"
t.KeyAltShfHome = "\x1b[1;4H"
t.KeyAltShfEnd = "\x1b[1;4F"
t.KeyMetaShfHome = "\x1b[1;10H"
t.KeyMetaShfEnd = "\x1b[1;10F"
}
// And the same thing for rxvt and workalikes (Eterm, aterm, etc.)
// It seems that urxvt at least send ESC as ALT prefix for these,
// although some places seem to indicate a separate ALT key sesquence.
if t.KeyShfRight == "\x1b[c" && t.KeyShfLeft == "\x1b[d" {
t.KeyShfUp = "\x1b[a"
t.KeyShfDown = "\x1b[b"
t.KeyCtrlUp = "\x1b[Oa"
t.KeyCtrlDown = "\x1b[Ob"
t.KeyCtrlRight = "\x1b[Oc"
t.KeyCtrlLeft = "\x1b[Od"
}
if t.KeyShfHome == "\x1b[7$" && t.KeyShfEnd == "\x1b[8$" {
t.KeyCtrlHome = "\x1b[7^"
t.KeyCtrlEnd = "\x1b[8^"
}
// If the kmous entry is present, then we need to record the
// the codes to enter and exit mouse mode. Sadly, this is not
// part of the terminfo databases anywhere that I've found, but
// is an extension. The escape codes are documented in the XTerm
// manual, and all terminals that have kmous are expected to
// use these same codes, unless explicitly configured otherwise
// vi XM. Note that in any event, we only known how to parse either
// x11 or SGR mouse events -- if your terminal doesn't support one
// of these two forms, you maybe out of luck.
t.MouseMode = tc.getstr("XM")
if t.Mouse != "" && t.MouseMode == "" {
// we anticipate that all xterm mouse tracking compatible
// terminals understand mouse tracking (1000), but we hope
// that those that don't understand any-event tracking (1003)
// will at least ignore it. Likewise we hope that terminals
// that don't understand SGR reporting (1006) just ignore it.
t.MouseMode = "%?%p1%{1}%=%t%'h'%Pa%e%'l'%Pa%;" +
"\x1b[?1000%ga%c\x1b[?1002%ga%c\x1b[?1003%ga%c\x1b[?1006%ga%c"
}
// We only support colors in ANSI 8 or 256 color mode.
if t.Colors < 8 || t.SetFg == "" {
t.Colors = 0
}
if t.SetCursor == "" {
return nil, "", notaddressable
}
// For padding, we lookup the pad char. If that isn't present,
// and npc is *not* set, then we assume a null byte.
t.PadChar = tc.getstr("pad")
if t.PadChar == "" {
if !tc.getflag("npc") {
t.PadChar = "\u0000"
}
}
// For terminals that use "standard" SGR sequences, lets combine the
// foreground and background together.
if strings.HasPrefix(t.SetFg, "\x1b[") &&
strings.HasPrefix(t.SetBg, "\x1b[") &&
strings.HasSuffix(t.SetFg, "m") &&
strings.HasSuffix(t.SetBg, "m") {
fg := t.SetFg[:len(t.SetFg)-1]
r := regexp.MustCompile("%p1")
bg := r.ReplaceAllString(t.SetBg[2:], "%p2")
t.SetFgBg = fg + ";" + bg
}
return t, tc.desc, nil
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/widget.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/widget.go#L93-L98 | go | train | // Watch monitors this WidgetWatcher, causing the handler to be fired
// with EventWidget as they are occur on the watched Widget. | func (ww *WidgetWatchers) Watch(handler tcell.EventHandler) | // Watch monitors this WidgetWatcher, causing the handler to be fired
// with EventWidget as they are occur on the watched Widget.
func (ww *WidgetWatchers) Watch(handler tcell.EventHandler) | {
if ww.watchers == nil {
ww.watchers = make(map[tcell.EventHandler]struct{})
}
ww.watchers[handler] = struct{}{}
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/widget.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/widget.go#L102-L106 | go | train | // Unwatch stops monitoring this WidgetWatcher. The handler will no longer
// be fired for Widget events. | func (ww *WidgetWatchers) Unwatch(handler tcell.EventHandler) | // Unwatch stops monitoring this WidgetWatcher. The handler will no longer
// be fired for Widget events.
func (ww *WidgetWatchers) Unwatch(handler tcell.EventHandler) | {
if ww.watchers != nil {
delete(ww.watchers, handler)
}
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/widget.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/widget.go#L110-L115 | go | train | // PostEvent delivers the EventWidget to all registered watchers. It is
// to be called by the Widget implementation. | func (ww *WidgetWatchers) PostEvent(wev EventWidget) | // PostEvent delivers the EventWidget to all registered watchers. It is
// to be called by the Widget implementation.
func (ww *WidgetWatchers) PostEvent(wev EventWidget) | {
for watcher := range ww.watchers {
// Deliver events to all listeners, ignoring return value.
watcher.HandleEvent(wev)
}
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/widget.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/widget.go#L119-L124 | go | train | // PostEventWidgetContent is called by the Widget when its content is
// changed, delivering EventWidgetContent to all watchers. | func (ww *WidgetWatchers) PostEventWidgetContent(w Widget) | // PostEventWidgetContent is called by the Widget when its content is
// changed, delivering EventWidgetContent to all watchers.
func (ww *WidgetWatchers) PostEventWidgetContent(w Widget) | {
ev := &EventWidgetContent{}
ev.SetWidget(w)
ev.SetEventNow()
ww.PostEvent(ev)
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/widget.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/widget.go#L128-L133 | go | train | // PostEventWidgetResize is called by the Widget when the underlying View
// has resized, delivering EventWidgetResize to all watchers. | func (ww *WidgetWatchers) PostEventWidgetResize(w Widget) | // PostEventWidgetResize is called by the Widget when the underlying View
// has resized, delivering EventWidgetResize to all watchers.
func (ww *WidgetWatchers) PostEventWidgetResize(w Widget) | {
ev := &EventWidgetResize{}
ev.SetWidget(w)
ev.SetEventNow()
ww.PostEvent(ev)
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/widget.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/widget.go#L137-L142 | go | train | // PostEventWidgetMove is called by the Widget when it is moved to a new
// location, delivering EventWidgetMove to all watchers. | func (ww *WidgetWatchers) PostEventWidgetMove(w Widget) | // PostEventWidgetMove is called by the Widget when it is moved to a new
// location, delivering EventWidgetMove to all watchers.
func (ww *WidgetWatchers) PostEventWidgetMove(w Widget) | {
ev := &EventWidgetMove{}
ev.SetWidget(w)
ev.SetEventNow()
ww.PostEvent(ev)
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/textarea.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textarea.go#L91-L103 | go | train | // SetLines sets the content text to display. | func (ta *TextArea) SetLines(lines []string) | // SetLines sets the content text to display.
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)
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/textarea.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textarea.go#L111-L114 | go | train | // EnableCursor enables a soft cursor in the TextArea. | func (ta *TextArea) EnableCursor(on bool) | // EnableCursor enables a soft cursor in the TextArea.
func (ta *TextArea) EnableCursor(on bool) | {
ta.Init()
ta.model.cursor = on
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/textarea.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textarea.go#L119-L122 | go | train | // 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. | func (ta *TextArea) HideCursor(on bool) | // 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.
func (ta *TextArea) HideCursor(on bool) | {
ta.Init()
ta.model.hide = on
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/textarea.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textarea.go#L126-L130 | go | train | // SetContent is used to set the textual content, passed as a
// single string. Lines within the string are delimited by newlines. | func (ta *TextArea) SetContent(text string) | // SetContent is used to set the textual content, passed as a
// single string. Lines within the string are delimited by newlines.
func (ta *TextArea) SetContent(text string) | {
ta.Init()
lines := strings.Split(strings.Trim(text, "\n"), "\n")
ta.SetLines(lines)
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/textarea.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/textarea.go#L133-L140 | go | train | // Init initializes the TextArea. | func (ta *TextArea) Init() | // Init initializes the TextArea.
func (ta *TextArea) Init() | {
ta.once.Do(func() {
lm := &linesModel{lines: []string{}, width: 0}
ta.model = lm
ta.CellView.Init()
ta.CellView.SetModel(lm)
})
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/text.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/text.go#L51-L59 | go | train | // calcY figures the initial Y offset. Alignment is top by default. | func (t *Text) calcY(height int) int | // calcY figures the initial Y offset. Alignment is top by default.
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
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/text.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/text.go#L63-L71 | go | train | // calcX figures the initial X offset for the given line.
// Alignment is left by default. | func (t *Text) calcX(width, line int) int | // calcX figures the initial X offset for the given line.
// Alignment is left by default.
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
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/text.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/text.go#L74-L133 | go | train | // Draw draws the Text. | func (t *Text) Draw() | // Draw draws the Text.
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)
}
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/text.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/text.go#L136-L141 | go | train | // Size returns the width and height in character cells of the Text. | func (t *Text) Size() (int, int) | // Size returns the width and height in character cells of the Text.
func (t *Text) Size() (int, int) | {
if len(t.text) != 0 {
return t.width, t.height
}
return 0, 0
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/text.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/text.go#L146-L151 | go | train | // SetAlignment sets the alignment. Negative values
// indicate right justification, positive values are left,
// and zero indicates center aligned. | func (t *Text) SetAlignment(align Alignment) | // SetAlignment sets the alignment. Negative values
// indicate right justification, positive values are left,
// and zero indicates center aligned.
func (t *Text) SetAlignment(align Alignment) | {
if align != t.align {
t.align = align
t.PostEventWidgetContent(t)
}
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/text.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/text.go#L171-L223 | go | train | // 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. | func (t *Text) SetText(s string) | // 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.
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)
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/text.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/text.go#L232-L240 | go | train | // SetStyle sets the style used. This applies to every cell in the
// in the text. | func (t *Text) SetStyle(style tcell.Style) | // SetStyle sets the style used. This applies to every cell in the
// in the text.
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)
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/text.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/text.go#L253-L259 | go | train | // SetStyleAt sets the style at the given rune index. Note that for
// strings containing combining characters, it is not possible to
// change the style at the position of the combining character, but
// those positions *do* count for calculating the index. A lot of
// complexity can be avoided by avoiding the use of combining characters. | func (t *Text) SetStyleAt(pos int, style tcell.Style) | // SetStyleAt sets the style at the given rune index. Note that for
// strings containing combining characters, it is not possible to
// change the style at the position of the combining character, but
// those positions *do* count for calculating the index. A lot of
// complexity can be avoided by avoiding the use of combining characters.
func (t *Text) SetStyleAt(pos int, style tcell.Style) | {
if pos < 0 || pos >= len(t.text) || t.widths[pos] < 1 {
return
}
t.styles[pos] = style
t.PostEventWidgetContent(t)
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/text.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/text.go#L264-L269 | go | train | // 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. | func (t *Text) StyleAt(pos int) tcell.Style | // 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.
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]
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/sstextbar.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/sstextbar.go#L39-L42 | go | train | // SetRight sets the right text for the textbar.
// It is always right-aligned. | func (s *SimpleStyledTextBar) SetRight(m string) | // SetRight sets the right text for the textbar.
// It is always right-aligned.
func (s *SimpleStyledTextBar) SetRight(m string) | {
s.initialize()
s.right.SetMarkup(m)
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/sstextbar.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/sstextbar.go#L46-L49 | go | train | // SetLeft sets the left text for the textbar.
// It is always left-aligned. | func (s *SimpleStyledTextBar) SetLeft(m string) | // SetLeft sets the left text for the textbar.
// It is always left-aligned.
func (s *SimpleStyledTextBar) SetLeft(m string) | {
s.initialize()
s.left.SetMarkup(m)
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | views/sstextbar.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/sstextbar.go#L53-L56 | go | train | // SetCenter sets the center text for the textbar.
// It is always centered. | func (s *SimpleStyledTextBar) SetCenter(m string) | // SetCenter sets the center text for the textbar.
// It is always centered.
func (s *SimpleStyledTextBar) SetCenter(m string) | {
s.initialize()
s.center.SetMarkup(m)
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | termbox/compat.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/termbox/compat.go#L29-L39 | go | train | // Init initializes the screen for use. | func Init() error | // Init initializes the screen for use.
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
}
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | termbox/compat.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/termbox/compat.go#L134-L142 | go | train | // Clear clears the screen with the given attributes. | func Clear(fg, bg Attribute) | // Clear clears the screen with the given attributes.
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)
}
}
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | termbox/compat.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/termbox/compat.go#L175-L188 | go | train | // SetOutputMode is used to set the color palette used. | func SetOutputMode(mode OutputMode) OutputMode | // SetOutputMode is used to set the color palette used.
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
}
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | termbox/compat.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/termbox/compat.go#L198-L201 | go | train | // SetCell sets the character cell at a given location to the given
// content (rune) and attributes. | func SetCell(x, y int, ch rune, fg, bg Attribute) | // SetCell sets the character cell at a given location to the given
// content (rune) and attributes.
func SetCell(x, y int, ch rune, fg, bg Attribute) | {
st := mkStyle(fg, bg)
screen.SetContent(x, y, ch, nil, st)
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | termbox/compat.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/termbox/compat.go#L332-L335 | go | train | // ParseEvent is not supported. | func ParseEvent(data []byte) Event | // ParseEvent is not supported.
func ParseEvent(data []byte) Event | {
// Not supported
return Event{Type: EventError, Err: errors.New("no raw events")}
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | errors.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/errors.go#L71-L73 | go | train | // NewEventError creates an ErrorEvent with the given error payload. | func NewEventError(err error) *EventError | // NewEventError creates an ErrorEvent with the given error payload.
func NewEventError(err error) *EventError | {
return &EventError{t: time.Now(), err: err}
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | style.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/style.go#L50-L56 | go | train | // Foreground returns a new style based on s, with the foreground color set
// as requested. ColorDefault can be used to select the global default. | func (s Style) Foreground(c Color) Style | // Foreground returns a new style based on s, with the foreground color set
// as requested. ColorDefault can be used to select the global default.
func (s Style) Foreground(c Color) Style | {
if c == ColorDefault {
return (s &^ (0x1ffffff00000000 | styleFgSet))
}
return (s &^ Style(0x1ffffff00000000)) |
((Style(c) & 0x1ffffff) << 32) | styleFgSet
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | style.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/style.go#L60-L65 | go | train | // Background returns a new style based on s, with the background color set
// as requested. ColorDefault can be used to select the global default. | func (s Style) Background(c Color) Style | // Background returns a new style based on s, with the background color set
// as requested. ColorDefault can be used to select the global default.
func (s Style) Background(c Color) Style | {
if c == ColorDefault {
return (s &^ (0x1ffffff | styleBgSet))
}
return (s &^ (0x1ffffff)) | (Style(c) & 0x1ffffff) | styleBgSet
} |
gdamore/tcell | dcf1bb30770eb1158b67005e1e472de6d74f055d | style.go | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/style.go#L69-L83 | go | train | // Decompose breaks a style up, returning the foreground, background,
// and other attributes. | func (s Style) Decompose() (fg Color, bg Color, attr AttrMask) | // Decompose breaks a style up, returning the foreground, background,
// and other attributes.
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
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.