Skip to content

CLEAR

Clear

Bases: Command

Command for clearing either the history log or console log.

Source code in src/textual_shell/commands/clear.py
class Clear(Command):
    """
    Command for clearing either the history log or 
    console log.
    """

    DEFINITION = {
        'clear': CommandNode(
            name='clear',
            description='Clear either the ConsoleLog or the HistoryLog.',
            children={
                'console': CommandNode(
                    name='console',
                    description='Clear the ConsoleLog',
                ),
                'history': CommandNode(
                    name='history',
                    description='Clear the HistoryLog.'
                )
            }
        )
    }

    def create_job(self, *args) -> Console | History:
        """Create the job to clear either the console or history."""
        if len(args) != 1:
            self.send_log('Invalid args!', logging.ERROR)
            return

        elif args[0] == 'console':
            return Console(
                shell=self.shell,
                cmd=self.name
            )

        elif args[0] == 'history':
            return History(
                shell=self.shell,
                cmd=self.name
            )

        else:
            self.shell.notify(
                message='Invalid subcommand.',
                title='Command: clear',
                severity='error'
            )

create_job(*args)

Create the job to clear either the console or history.

Source code in src/textual_shell/commands/clear.py
def create_job(self, *args) -> Console | History:
    """Create the job to clear either the console or history."""
    if len(args) != 1:
        self.send_log('Invalid args!', logging.ERROR)
        return

    elif args[0] == 'console':
        return Console(
            shell=self.shell,
            cmd=self.name
        )

    elif args[0] == 'history':
        return History(
            shell=self.shell,
            cmd=self.name
        )

    else:
        self.shell.notify(
            message='Invalid subcommand.',
            title='Command: clear',
            severity='error'
        )

Console

Bases: Job

Job to clear the console.

Source code in src/textual_shell/commands/clear.py
class Console(Job):
    """Job to clear the console."""

    class Clear(Message):
        """Signal the app to clear the console."""
        pass

    async def execute(self):
        self.running()
        self.shell.post_message(
            self.Clear()
        )
        self.completed()

Clear

Bases: Message

Signal the app to clear the console.

Source code in src/textual_shell/commands/clear.py
class Clear(Message):
    """Signal the app to clear the console."""
    pass

History

Bases: Job

Job to clear the history.

Source code in src/textual_shell/commands/clear.py
class History(Job):
    """Job to clear the history."""

    class Clear(Message):
        """Signal the app to clear the history."""
        pass

    async def execute(self):
        self.running()
        self.shell.post_message(
            self.Clear()
        )
        self.completed()

Clear

Bases: Message

Signal the app to clear the history.

Source code in src/textual_shell/commands/clear.py
class Clear(Message):
    """Signal the app to clear the history."""
    pass