MCPcopy
hub / github.com/mum4k/termdash / ForPosition

Method ForPosition

private/attrrange/attrrange.go:77–103  ·  view source on GitHub ↗

ForPosition returns attribute index that apply to the specified position. Returns ErrNotFound when the requested position wasn't found in any of the known ranges.

(pos int)

Source from the content-addressed store, hash-verified

75// Returns ErrNotFound when the requested position wasn't found in any of the
76// known ranges.
77func (t *Tracker) ForPosition(pos int) (*AttrRange, error) {
78 if ar, ok := t.ranges[pos]; ok {
79 return ar, nil
80 }
81
82 var keys []int
83 for k := range t.ranges {
84 keys = append(keys, k)
85 }
86 sort.Ints(keys)
87
88 var res *AttrRange
89 for _, k := range keys {
90 ar := t.ranges[k]
91 if ar.Low > pos {
92 break
93 }
94 if ar.High > pos {
95 res = ar
96 }
97 }
98
99 if res == nil {
100 return nil, fmt.Errorf("did not find attribute range for position %d", pos)
101 }
102 return res, nil
103}

Callers 4

ExampleFunction · 0.95
TestForPositionFunction · 0.95
DrawMethod · 0.80
drawTextMethod · 0.80

Calls

no outgoing calls

Tested by 2

ExampleFunction · 0.76
TestForPositionFunction · 0.76