()
| 23 | ) |
| 24 | |
| 25 | func Example() { |
| 26 | // Caller has a slice of some attributes, like a cell color that applies |
| 27 | // to a portion of text. |
| 28 | attrs := []cell.Color{cell.ColorRed, cell.ColorBlue} |
| 29 | redIdx := 0 |
| 30 | blueIdx := 1 |
| 31 | |
| 32 | // This is the text the colors apply to. |
| 33 | const text = "HelloWorld" |
| 34 | |
| 35 | // Assuming that we want the word "Hello" in red and the word "World" in |
| 36 | // green, we can set our ranges as follows: |
| 37 | tr := NewTracker() |
| 38 | if err := tr.Add(0, len("Hello"), redIdx); err != nil { |
| 39 | panic(err) |
| 40 | } |
| 41 | if err := tr.Add(len("Hello")+1, len(text), blueIdx); err != nil { |
| 42 | panic(err) |
| 43 | } |
| 44 | |
| 45 | // Now to get the index into attrs (i.e. the color) for a particular |
| 46 | // character, we can do: |
| 47 | for i, c := range text { |
| 48 | ar, err := tr.ForPosition(i) |
| 49 | if err != nil { |
| 50 | panic(err) |
| 51 | } |
| 52 | log.Printf("character at text[%d] = %q, color index %d = %v, range low:%d, high:%d", i, c, ar.AttrIdx, attrs[ar.AttrIdx], ar.Low, ar.High) |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | func TestForPosition(t *testing.T) { |
| 57 | tests := []struct { |
nothing calls this directly
no test coverage detected