import json


def user_io_loop(settings: dict):
    """
    This function is run on the main process as it interacts with the user.
    It asks for some command and it executes the proper task if the input
    was recgonized.

    Parameters
    ----------
    settings : proxy dict
        shared dictionary with information about hardware settings, status,
        and it holds the stop flag.

    Returns
    -------
    settings : dict
        Returns a copy of the proxy dict 'settings'. The copy is made after
        the stop signal is flagged.

    """
    print('Started analog in/out')
    while not settings['stop']:
        inp = input('analog i/o prompt >>>> ')
        if inp == 'q' or inp == 'quit' or inp == 'stop':
            settings['stop'] = True
        elif inp == 's' or inp == 'settings':
            print('settings =', json.dumps(dict(settings),sort_keys=False, indent=4))
        else:
            print('Input "', inp, '" is not recognized.', sep = '')
    return dict(settings)