#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributors.

from fenrirscreenreader.core.i18n import _
from fenrirscreenreader.core.tabCompletionManager import TabCompletionManager


class command:
    def __init__(self):
        self.manager = TabCompletionManager()

    def initialize(self, environment):
        self.env = environment
        self.manager.initialize(environment)

    def shutdown(self):
        pass

    def get_description(self):
        return _("Announces tab completions on cursor movement")

    def run(self):
        text = self.manager.process_update()
        if not text:
            return

        do_interrupt = True
        if self.env["runtime"]["SettingsManager"].get_setting_as_bool(
            "speech", "auto_read_incoming"
        ):
            do_interrupt = False

        self.env["runtime"]["OutputManager"].present_text(
            text,
            interrupt=do_interrupt,
            announce_capital=True,
            flush=False,
        )

    def set_callback(self, callback):
        pass
