import asyncio

from ..core.common.io import input
from .action_creator import ActionCreator


class REPL:
    def __init__(self, action_queue, config, *args, **kwargs):
        self.action_queue = action_queue
        self.config = config

    async def run(self):
        await asyncio.sleep(1)
        print("Insert command: ")
        action_creator = ActionCreator()
        while True:
            input_data = await input("~> ")
            if not input_data:
                for task in asyncio.all_tasks():
                    task.cancel()
                break
            action = action_creator.parse(*input_data.split())
            if action:
                self.action_queue.push_action(action)

[((13, 14, 13, 30), 'asyncio.sleep', 'asyncio.sleep', ({(13, 28, 13, 29): '(1)'}, {}), '(1)', False, 'import asyncio\n'), ((19, 28, 19, 47), 'asyncio.all_tasks', 'asyncio.all_tasks', ({}, {}), '()', False, 'import asyncio\n')]