from app.display import NeoPixel_64x64
from app.utils import align_font, colors
import app.display.fonts as fonts

class Font_Checker():
    font = fonts.font_3x5

    
    def __init__(self, display: NeoPixel_64x64):
        self.display = display

    def font_pretty(self, font):
        pretty_font = align_font(font, debug=False)
        print(pretty_font)

    def fonts_check(self, pretty=False) -> None:
        
        for fnt in fonts.fonts_installed:
            self.display.clear()
            self.display.set_font(fnt)

            height = self.display.font_height

            alphanum: str = ''.join(sorted(self.font.keys()))

            text_left = alphanum
            while text_left:
                # Text entsprechend des Display splitten
                scr_txt_dict = self.display.screen_text(text=text_left)
                print(f'scr_txt: {scr_txt_dict}')

                self.display.clear()
                for idx, row_text in enumerate(scr_txt_dict['visible']):
                    ypos = height * idx
                    # display.clear_row(ypos)
                    self.display.write_text(row_text, 0, ypos, colors.RAINBOW[idx % 6])

                text_left = scr_txt_dict['invisible']

            if pretty:
                self.font_pretty(self.font)
