'REPL for interactive tutorials'

def example_repl(self, text, example, start_index, continue_flag):

    if start_index:
        start_index = (start_index + 1)
        cmd = u'    '.join(text.split()[:start_index])
        example_cli = CommandLineInterface(application=self.create_application(full_layout=False), eventloop=create_eventloop())
        example_cli.buffers[u'example_line'].reset(initial_document=Document(u'{}\n'.format(add_new_lines(example))))
        while (start_index < len(text.split())):
            if self.default_command:
                cmd = cmd.replace((self.default_command + u'    '), u'')
            example_cli.buffers[DEFAULT_BUFFER].reset(initial_document=Document(u'{}'.format(cmd), cursor_position=len(cmd)))
            example_cli.request_redraw()
            answer = example_cli.run()
            if (not answer):
                return (u'', True)
            answer = answer.text
            if (answer.strip(u'\n') == cmd.strip(u'\n')):
                continue
            elif (len(answer.split()) > 1):
                start_index += 1
                cmd += (((u'    ' + answer.split()[(-1)]) + u'    ') + u'    '.join(text.split()[start_index:(start_index + 1)]))
        example_cli.exit()
        del example_cli
    else:
        cmd = text
    return (cmd, continue_flag)
