def select_device_interactive(type_devices_dict: dict[str, list[str]], prompt="Select an instrument: ") -> tuple[str, str]: """ Select a device interactively from the command line Parameters ---------- type_devices_dict A dictionary of device types and their corresponding device names ------- The type and name of the selected device. These can be passed to the connect_device method of the led_control_device or voltage_measurement_device libraries """ res = type_devices_dict flat_res = [ (t, v) for t, l in res.items() for v in l ] for i, (t,v) in enumerate(flat_res): print(f"{i+1:02}: {t} - {v}") while len(flat_res) > 0: try: instr = int(input(prompt)) - 1 if instr < 0 or instr >= len(flat_res): raise ValueError return flat_res[instr] except ValueError: print(f"Enter a number between 1 and {len(flat_res)}") continue raise Exception("No devices found")