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

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

from fenrirscreenreader.core.i18n import _


class command:
    def __init__(self):
        pass

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

    def shutdown(self):
        pass

    def get_description(self):
        return ""

    def run(self):
        if not self.env["runtime"]["SettingsManager"].get_setting_as_bool(
            "keyboard", "interrupt_on_key_press"
        ):
            return
        if self.env["runtime"]["InputManager"].no_key_pressed():
            return
        if self.env["runtime"]["ScreenManager"].is_screen_change():
            return
        if len(self.env["input"]["curr_input"]) <= len(
            self.env["input"]["prev_input"]
        ):
            return
        # if the filter is set
        if (
            self.env["runtime"]["SettingsManager"]
            .get_setting("keyboard", "interrupt_on_key_press_filter")
            .strip()
            != ""
        ):
            filter_list = (
                self.env["runtime"]["SettingsManager"]
                .get_setting("keyboard", "interrupt_on_key_press_filter")
                .split(",")
            )
            for curr_key in self.env["input"]["curr_input"]:
                if curr_key not in filter_list:
                    return
        self.env["runtime"]["OutputManager"].interrupt_output_async()

    def set_callback(self, callback):
        pass
