def draw_lines_and_lineno(self):
        """Draw lines on scroll area with line numbers."""
        ### draw lineno panel
        self.lineno_panel.draw()

        ### reference attributes in local variables

        image = self.image
        offset = self.offset
        scroll_area = self.scroll_area

        ### iterate over each line and its respective line
        ### number

        for lineno, line in enumerate(self.lines, start=1):

            ## reference the line's rect locally
            line_rect = line.rect

            ## if the line is along the height of the
            ## scroll area draw the line and then its
            ## line number;
            ##
            ## regarding collisions we cannot use
            ## pygame.Rect.colliderect here, because empty
            ## lines have a rect without width (even though
            ## they have height), making it so the rect
            ## has area 0 (zero) and rects with area 0 never
            ## collide;
            ##
            ## we also cannot use pygame.Rect.contains here,
            ## cause when the user scrolls further to
            ## the right because of a large line, smaller
            ## lines may be pulled outside the boundaries
            ## of the scroll area to the left, and since
            ## they would not be contained in the scrolling
            ## area, their line numbers would not be drawn
            ##
            ## this is why we use this special within_height
            ## function

            if within_height(line_rect, scroll_area):

                ## draw line with offset topleft
                image.blit(line.image, line.rect.topleft + offset)

                ## draw line number
                self.draw_lineno(str(lineno), line_rect.y)
Draw lines on scroll area with line numbers.
nodezator/textman/viewer/op.py