    def __getitem__(self, item):
        """
        Slice magic method.
        """
        if isinstance(item, int):
            start = self._raw_offsets[item]
            stop = None if item == len(self._raw_offsets) - 1 else self._raw_offsets[item + 1]
            step = 1
            colour_index = max(0, item - 1)
            base = self._raw_offsets[item]
            offsets = [0]
        else:
            try:
                start = None if item.start is None else self._raw_offsets[slice(item.start, None, None)][0]
            except IndexError:
                start = len(self._raw_text)
            try:
                stop = None if item.stop is None else self._raw_offsets[slice(item.stop, None, None)][0]
            except IndexError:
                stop = None
            step = item.step
            colour_index = max(0, item.start - 1 if item.start else 0)
            try:
                base = self._raw_offsets[item][0]
                offsets = [x - base for x in self._raw_offsets[item]]
            except IndexError:
                base = 0
                offsets = []
        try:
            colour = self._colour_map[colour_index]
        except IndexError:
            colour = self._init_colour
        return ColouredText(self._raw_text[slice(start, stop, step)],
                            parser=self._parser,
                            colour=colour,
                            text=self._text[item],
                            colour_map=self._colour_map[item],
                            offsets=offsets)
Slice magic method.
asciimatics/strings.py