# Class pyglet.text.runlist.RunList

List of contiguous runs of values.

A RunList is an efficient encoding of a sequence of values. For example, the sequence `aaaabbccccc` is encoded as `(4, a), (2, b), (5, c)`. The class provides methods for modifying and querying the run list without needing to deal with the tricky cases of splitting and merging the run list entries.

Run lists are used to represent formatted character data in pyglet. A separate run list is maintained for each style attribute, for example, bold, italic, font size, and so on. Unless you are overriding the document interfaces, the only interaction with run lists is via RunIterator.

The length and ranges of a run list always refer to the character positions in the decoded list. For example, in the above sequence, `set_run(2, 5, 'x')` would change the sequence to `aaxxxbccccc`.

## Methods

| __init__(self, size, initial) Create a run list of the given size and a default value.
| insert(self, pos, length) Insert characters into the run list.
| delete(self, start, end) Remove characters from the run list.
| set_run(self, start, end, value) Set the value of a range of characters.
| __iter__(self)
RunIterator | get_run_iterator(self) Get an extended iterator over the run list.
object | __getitem__(self, index) Get the value at a character position.
| __repr__(self)

## Method Details

### __init__

(Constructor) __init__(self, size, initial)
Create a run list of the given size and a default value.

Parameters:
  size : int
    Number of characters to represent initially.
  initial : object
    The value of all characters in the run list.

### insert

insert(self, pos, length)

Insert characters into the run list.

The inserted characters will take on the value immediately preceding the insertion point (or the value of the first character, if `pos` is 0).

Parameters:
  pos : int
    Insertion index
  length : int
    Number of characters to insert.

### delete

delete(self, start, end)
Remove characters from the run list.

Parameters:
  start : int
    Starting index to remove from.
  end : int
    End index, exclusive.

### set_run

set_run(self, start, end, value)
Set the value of a range of characters.

Parameters:
  start : int
    Start index of range.
  end : int
    End of range, exclusive.
  value : object
    Value to set over the range.

### __getitem__

(Indexing operator) __getitem__(self, index)
Get the value at a character position.

Parameters:
  index : int
    Index of character. Must be within range and non-negative.
Returns: object