<commit_before>import urwid
from projects.project_selector import ProjectSelector
from projects.gui import generate_gui_string


def select_project(project_list):
    max_width = len(max(project_list, key=len))
    f = ProjectSelector(project_list, 'normal', 'highlighted', 'selected')

    def refresh_list(key=''):
        if key:
            if key in ('delete', 'backspace'):
                f.remove_key()
            else:
                if key in '<KEY> .':
                    f.add_key(key)
        s = f.render()
        txt.set_text(s)

    def exit_on_q(key):
        if key in ('Q',):
            raise urwid.ExitMainLoop()
        if key == 'up':
            f.up()
        if key == 'down':
            f.down()
        if key == 'enter':
            result = f.select()
            print(result)
            # raise urwid.ExitMainLoop()
        key = key.lower()
        refresh_list(key)


    palette = [
        ('normal', 'light gray', ''),
        ('selected', 'yellow, bold', ''),
        ('highlighted', 'black, bold', 'yellow'),
        ('quit button', 'dark red,bold', '')
    ]

    txt = urwid.Text('', align='left')
    fill = urwid.Filler(txt)
    pad = urwid.Padding(fill, align='center', width=max_width+4)
    box = urwid.LineBox(pad, title="Projects")

    footer = urwid.Text(['Start typing to search project. Use arrow keys to navigate. Press (Enter) to select project. ', 'Press (', ('quit button', 'Q'), ') to exit.'])
    frame = urwid.Frame(body=box, footer=footer)

    loop = urwid.MainLoop(frame, palette, unhandled_input=exit_on_q)
    refresh_list()
    loop.run()

if __name__ == '__main__':
    print('starting gui')
    l = [
        'imre',
        'bela',
        'gizike',
        'adorjan',
        'hello',
        'laskdjflkasj',
        'dkjfgiuenkjnc',
        'asdfarg',
        'asoiulsihf',
        'asdfhekrjher',
        'tseoijteo',
        'oeitjgoj',
        'oierjogijef',
        'oeisrofisf',
        'oeiroijiuhsdkj'
    ]
    select_project(l)<commit_msg>Help line edited.<commit_after>import urwid
from projects.project_selector import ProjectSelector
from projects.gui import generate_gui_string


def select_project(project_list):
    max_width = len(max(project_list, key=len))
    f = ProjectSelector(project_list, 'normal', 'highlighted', 'selected')

    def refresh_list(key=''):
        if key:
            if key in ('delete', 'backspace'):
                f.remove_key()
            else:
                if key in 'abcdefghijklmnopqrstuvwxyz- .':
                    f.add_key(key)
        s = f.render()
        txt.set_text(s)

    def exit_on_q(key):
        if key in ('Q',):
            raise urwid.ExitMainLoop()
        if key == 'up':
            f.up()
        if key == 'down':
            f.down()
        if key == 'enter':
            result = f.select()
            print(result)
            # raise urwid.ExitMainLoop()
        key = key.lower()
        refresh_list(key)


    palette = [
        ('normal', 'light gray', ''),
        ('selected', 'yellow, bold', ''),
        ('highlighted', 'black, bold', 'yellow'),
        ('quit button', 'light red, bold', ''),
        ('enter button', 'light green, bold', '')
    ]

    txt = urwid.Text('', align='left')
    fill = urwid.Filler(txt)
    pad = urwid.Padding(fill, align='center', width=max_width+4)
    box = urwid.LineBox(pad, title="Projects")

    footer = urwid.Text(['Start typing to search. Use arrow keys to navigate. Press (', ('enter button', 'Enter'), ') to select project. ', 'Press (', ('quit button', 'Q'), ') to exit.'])
    frame = urwid.Frame(body=box, footer=footer)

    loop = urwid.MainLoop(frame, palette, unhandled_input=exit_on_q)
    refresh_list()
    loop.run()

if __name__ == '__main__':
    print('starting gui')
    l = [
        'imre',
        'bela',
        'gizike',
        'adorjan',
        'hello',
        'laskdjflkasj',
        'dkjfgiuenkjnc',
        'asdfarg',
        'asoiulsihf',
        'asdfhekrjher',
        'tseoijteo',
        'oeitjgoj',
        'oierjogijef',
        'oeisrofisf',
        'oeiroijiuhsdkj'
    ]
    select_project(l)
{'fraction_non_alphanumeric': 0.1503015681544029, 'fraction_numerical': 0.0004825090470446321, 'mean_word_length': 2.0963405526512324, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3235555', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1332, 'n_words': 300}