def openFilePicker(self):
        """ Draw UI for selecting a file to load, return the filename """
        # get file list
        self.stdscr.nodelay(0) # wait for input when calling getch
        self.cursorOff()
        folders =  ["../"]
        default_masks = ['*.dur', '*.durf', '*.asc', '*.ans', '*.txt', '*.diz', '*.nfo', '*.ice', '*.ansi']
        masks = default_masks
        matched_files = []
        file_list = []
        preview_mov = None
        old_color_mode = self.appState.colorMode    # in case we switch while file picker is open
        #self.selected_item_number = 0
        self.sixteenc_api = None

        # set correct color mode for initial picker opening
        if self.appState.sixteenc_browsing:
            if self.appState.colorMode != "16":
                self.switchTo16ColorMode()
        elif not self.appState.sixteenc_browsing:
            # IF we aren't in the original mode, switch back
            if old_color_mode != self.appState.colorMode:
                if old_color_mode == "256":
                    self.switchTo256ColorMode()

        # Set the directory listing for local files
        if self.appState.workingLoadDirectory: 
            if os.path.exists(self.appState.workingLoadDirectory):
                current_directory = self.appState.workingLoadDirectory
            else:
                current_directory = os.getcwd()
        else:
            current_directory = os.getcwd()

        if not self.appState.sixteenc_browsing:
            file_list = []
            #folders += sorted(filter(os.path.isdir, glob.glob(os.path.join(current_directory, "*/"))))
            folders = ['../'] + sorted(filter(os.path.isdir, glob.glob(os.path.join(current_directory, "*/"))))
            # remove leading paths
            new_folders = []
            for path_string in folders:
                new_folders.append(os.path.sep.join(path_string.split(os.path.sep)[-2:]))
            folders = new_folders

            for file in os.listdir(current_directory):
                for mask in masks:
                    if fnmatch.fnmatch(file.lower(), mask.lower()):
                        matched_files.append(file)
                        break
        elif self.appState.sixteenc_browsing:
            self.sixteenc_api = SixteenColorsAPI()
            if self.sixteenc_years == None:
                self.sixteenc_years = self.sixteenc_api.list_years()
            # Set the initial listing/UI for 16colo.rs browsing
            if self.sixteenc_levels[self.sixteenc_level] == "root":
                self.appState.sixteenc_year = None
                sixteenc_packs = None
                folders = self.sixteenc_years
                file_list = []
                full_file_list = file_list
                search_files_list = file_list
                matched_files = search_files_list

            elif self.sixteenc_levels[self.sixteenc_level] == "year":
                sixteenc_packs = self.sixteenc_api.list_packs_for_year(self.appState.sixteenc_year)
                folders = ['../'] + sixteenc_packs
                #file_list = folders
                file_list = []
                full_file_list = file_list
                search_files_list = file_list

            elif self.sixteenc_levels[self.sixteenc_level] == "pack":
                sixteenc_files = self.sixteenc_api.list_files_for_pack(self.appState.sixteenc_pack)
                folders = ['../']
                #file_list = folders
                file_list = folders + sixteenc_files
                full_file_list = file_list
                search_files_list = file_list
                #file_list = sorted(file_list)



        if not self.appState.sixteenc_browsing:
            for dirname in folders:
                file_list.append(dirname)

        file_list += sorted(matched_files)

        # stash away file list so we can use it for search, and pop it back
        # in when user hits esc
        full_file_list = file_list
        black_frame = durmovie.Frame(80, 25)  # easy way to clear parts of the screen?

        # draw ui
        #self.selected_item_number = 0
        current_line_number = 0
        search_string = ''
        mask_all = False
        #tabbed = False
        #sections = ["main", "showall", "sixteenc"]  # Different sections of the UI we can tab through
        sections = ["main", "showall"]
        if self.appState.sixteenc_available:
            sections.append("sixteenc")
        current_section = 0
        show_modtime = True     # show a column for file modified times
        top_line = 0    # topmost viewable line, for scrolling
        showall_column = 0  # column for [X] Show All Files checkbox
        sixteen_column = 21 # Column for [X] 16colo.rs Archive
        prompting = True
        # Turn on keyboard buffer waiting here, if necessary..
        self.stdscr.nodelay(0)
        self.stdscr.clear()

        # stuff for 16colo.rs - caches to avoid hitting API repeatedly
        sixteenc_packs = []
        sixteenc_files = [] # cache for current file listing
        sixteenc_current_file = None

        while prompting:

            #file_list = []
            #full_file_list = []
            # If we need to cache 16c years, make it so.
            if self.appState.sixteenc_browsing:
                show_modtime = False
                # If there's no 16c cache, make a new API object and cache the years
                if self.sixteenc_api == None:
                    self.sixteenc_api = SixteenColorsAPI()
                if self.sixteenc_years == None:
                    self.sixteenc_years = self.sixteenc_api.list_years()
                # If we aren't in a year, then populate the directory list with years
                if self.appState.sixteenc_year == None:
                    # We are at the top level, so list the years.
                    folders = ["../"]
                    folders += self.sixteenc_years
                    file_list = self.sixteenc_years
                    full_file_list = file_list

            # Set search matching
            #filtered_list = [item for item in full_file_list if search_string.lower() in item.lower()]
            if search_string != '':
                file_list = [item for item in full_file_list if search_string.lower() in item.lower()]
                if len(file_list) == 0:
                    file_list = ["../"]
            else:
                file_list = full_file_list

            # draw list of files from top of the window to bottom
            realmaxY,realmaxX = self.realstdscr.getmaxyx()
            page_size = realmaxY - 4
            current_line_number = 0
            file_column_number = 0
            if show_modtime:
                file_column_number = 20
            if self.selected_item_number > top_line + page_size-1 or self.selected_item_number < top_line: # item is off the screen
                top_line = self.selected_item_number - int(page_size-3) # scroll so it's at the bottom
            # remove any files we can't open
            if not self.appState.sixteenc_browsing:
                for filename in file_list:
                    full_path = f"{current_directory}/{filename}"
                    try:
                        file_modtime_string = durfile.get_file_mod_date_time(full_path)
                    except FileNotFoundError:   # Probably a dead symlink.
                        # Access problems. Remove from list.
                        file_list = [item for item in file_list if filename not in item]

            for filename in file_list:
                if current_line_number >= top_line and current_line_number - top_line < page_size:  # If we're within screen size
                    if  self.selected_item_number == current_line_number and sections[current_section] == "main":    # if file is selected
                        if file_list[current_line_number] in folders:
                            self.addstr(current_line_number - top_line, 0, file_list[current_line_number], curses.A_REVERSE)
                        else:
                            # not a folder, print modified column
                            if show_modtime and not self.appState.sixteenc_browsing:
                                full_path = f"{current_directory}/{file_list[current_line_number]}"
                                file_modtime_string = durfile.get_file_mod_date_time(full_path)
                                self.addstr(current_line_number - top_line, 0, file_modtime_string, curses.color_pair(self.appState.theme['menuItemColor']))
                            self.addstr(current_line_number - top_line, file_column_number, file_list[current_line_number], curses.A_REVERSE)
                    else:
                        if file_list[current_line_number] in folders:
                            if file_list[current_line_number] in self.appState.sixteenc_dizcache and self.appState.sixteenc_browsing:
                                # file_id has been downloaded, so draw in bold
                                self.addstr(current_line_number - top_line, 0, file_list[current_line_number], curses.color_pair(self.appState.theme['menuTitleColor']) | curses.A_BOLD)
                            else:
                                self.addstr(current_line_number - top_line, 0, file_list[current_line_number], curses.color_pair(self.appState.theme['menuTitleColor']))
                        else:
                            if show_modtime and self.appState.sixteenc_browsing == False:
                                full_path = f"{current_directory}/{file_list[current_line_number]}"
                                file_modtime_string = durfile.get_file_mod_date_time(full_path)
                                self.addstr(current_line_number - top_line, 0, file_modtime_string, curses.color_pair(self.appState.theme['menuItemColor']))
                            self.addstr(current_line_number - top_line, file_column_number, file_list[current_line_number], curses.color_pair(self.appState.theme['promptColor']))
                current_line_number += 1

            if self.appState.sixteenc_browsing == False:
                if mask_all:
                    if sections[current_section] == "showall":
                        self.addstr(realmaxY - 4, showall_column, f"[X]", curses.A_REVERSE)
                    else:
                        self.addstr(realmaxY - 4, showall_column, f"[X]", curses.color_pair(self.appState.theme['clickColor']))
                else:
                    if sections[current_section] == "showall":
                        self.addstr(realmaxY - 4, showall_column, f"[ ]", curses.A_REVERSE)
                    else:
                        self.addstr(realmaxY - 4, showall_column, f"[ ]", curses.color_pair(self.appState.theme['clickColor']))
                self.addstr(realmaxY - 4, showall_column + 4, f"Show All Files", curses.color_pair(self.appState.theme['menuItemColor']))

            if self.appState.sixteenc_available:
                if self.appState.sixteenc_browsing:
                    if sections[current_section] == "sixteenc":
                        self.addstr(realmaxY - 4, sixteen_column, f"[X]", curses.A_REVERSE)
                    else:
                        self.addstr(realmaxY - 4, sixteen_column, f"[X]", curses.color_pair(self.appState.theme['clickColor']))
                else:
                    if sections[current_section] == "sixteenc":
                        self.addstr(realmaxY - 4, sixteen_column, f"[ ]", curses.A_REVERSE)
                    else:
                        self.addstr(realmaxY - 4, sixteen_column, f"[ ]", curses.color_pair(self.appState.theme['clickColor']))
                self.addstr(realmaxY - 4, sixteen_column + 4, f"16colo.rs Archive", curses.color_pair(self.appState.theme['menuItemColor']))

            #self.addstr(realmaxY - 4, 20, f"[PGUP]", curses.color_pair(self.appState.theme['clickColor']))
            #self.addstr(realmaxY - 4, 27, f"[PGDOWN]", curses.color_pair(self.appState.theme['clickColor']))
            #self.addstr(realmaxY - 4, 36, f"[OK]", curses.color_pair(self.appState.theme['clickColor']))
            #self.addstr(realmaxY - 4, 41, f"[CANCEL]", curses.color_pair(self.appState.theme['clickColor']))
            if self.appState.sixteenc_browsing:
                self.addstr(realmaxY - 3, 0, f"Year: {self.appState.sixteenc_year}, Pack: {self.appState.sixteenc_pack}, Level: {self.sixteenc_levels[self.sixteenc_level]}", curses.color_pair(self.appState.theme['menuTitleColor']))
            else:
                self.addstr(realmaxY - 3, 0, f"Folder: {current_directory}", curses.color_pair(self.appState.theme['menuTitleColor']))
            if search_string != "":
                self.addstr(realmaxY - 2, 0, f"search: ")
                self.addstr(realmaxY - 2, 8, f"{search_string}", curses.color_pair(self.appState.theme['menuItemColor']))

            if self.selected_item_number > len(file_list) - 1:
                self.selected_item_number = 0

            self.log.debug('selected item number', {'selected_item_number': self.selected_item_number, 'n_files': len(file_list)})

            #if not self.appState.sixteenc_browsing:
            #    try:
            #        filename = file_list[self.selected_item_number]
            #    except:
            #        pdb.set_trace()
            filename = None
            if len(file_list) > 0:
                filename = file_list[self.selected_item_number]

            if self.appState.sixteenc_browsing or filename is None:
                full_path = ''
            else:
                full_path = f"{current_directory}/{file_list[self.selected_item_number]}"
                
            if filename not in folders and filename is not None :
                # read sauce, if available
                #file_sauce = dursauce.SauceParser(full_path)
                file_sauce = dursauce.SauceParser()
                file_sauce.parse_file(full_path)
                sauce_title = file_sauce.title
                sauce_author = file_sauce.author
                sauce_width = file_sauce.width
                sauce_height = file_sauce.height
                sauce_date = file_sauce.date
                sauce_year = file_sauce.year
                sauce_month = file_sauce.month
                sauce_day = file_sauce.day
                sauce_width = file_sauce.width
                sauce_height = file_sauce.height
            else:
                file_sauce = dursauce.SauceParser() # empty placeholder sauce
                sauce_title = None
                sauce_author = None
                #sauce_width = file_sauce.width
                #sauce_height = file_sauce.height

            if self.appState.sixteenc_browsing or filename is None:
                file_size = None
                file_modtime_string = ""
            else:
                file_size = os.path.getsize(full_path)
                file_modtime_string = durfile.get_file_mod_date_time(full_path)

            # display file info - format data
            file_info = f"File: {filename}, Size: {file_size}, Modified: {file_modtime_string}"
            if file_sauce.sauce_found:
                file_info = f"{sauce_title}, Artist: {sauce_author}, Date: {sauce_year}/{sauce_month}/{sauce_day}, Width: {sauce_width}, Height: {sauce_height}, Size: {file_size}" 
            # show it on screen
            self.addstr(realmaxY - 1, 0, f"{file_info}")

            if self.appState.thread_update_string != None:
                self.thread_update_user(thread_update_string)


            # If there is a preview to load, load it
            if self.appState.sixteenc_browsing:
                selected_item = file_list[self.selected_item_number]
                if self.sixteenc_levels[self.sixteenc_level] == "year":
                    # If a pack is selected, download the file_id.diz and preview it
                    if selected_item != '../':
                        if selected_item not in self.appState.sixteenc_dizcache:
                            self.drawFrame(frame=black_frame, col_offset=40, preview=True)
                            #pass
                            #self.stdscr.clear()
                            #self.stdscr.refresh()
                            #self.sixteenc_update_diz_cache(self.appState.sixteenc_year)
                        if selected_item in self.appState.sixteenc_dizcache:
                            preview_frame = self.appState.sixteenc_dizcache[selected_item]
                            left_diz_column = max(40, realmaxX - preview_frame.sizeX - 3)  # anchor right
                            self.drawFrame(frame=preview_frame, col_offset=left_diz_column, preview=True)
                elif self.sixteenc_levels[self.sixteenc_level] == "pack":
                    if self.appState.sixteenc_pack in self.appState.sixteenc_dizcache:
                        preview_frame = self.appState.sixteenc_dizcache[self.appState.sixteenc_pack]
                        left_diz_column = max(40, realmaxX - preview_frame.sizeX - 3)  # anchor right
                        self.drawFrame(frame=preview_frame, col_offset=left_diz_column, preview=True)



            #self.stdscr.refresh()

            # Read keyboard input
            c = self.stdscr.getch()


            if c == curses.KEY_MOUSE:
                try:
                    _, mouseCol, mouseLine, _, mouseState = curses.getmouse()
                except:
                    pass
                if mouseState == curses.BUTTON1_CLICKED or mouseState == curses.BUTTON1_DOUBLE_CLICKED:
                    if mouseLine < realmaxY - 4:     # above the 'status bar,' in the file list
                        current_section = 0 # switch to "main" section
                        if mouseLine < len(file_list) - top_line:   # clicked item line
                            if mouseCol < len(file_list[top_line+mouseLine] + file_modtime_string): # clicked within item width
                                self.selected_item_number = top_line+mouseLine
                                if mouseState == curses.BUTTON1_DOUBLE_CLICKED:
                                    #self.notify("Double Clicked on item")
                                    if file_list[self.selected_item_number] in folders:  # clicked directory
                                        if not self.appState.sixteenc_browsing:
                                            # change directories. holy fuck this is deep
                                            if file_list[self.selected_item_number] == "../":
                                                # "cd .."
                                                if self.appState.sixteenc_browsing:
                                                    if self.sixteenc_level > 0:
                                                        self.sixteenc_level = self.sixteenc_level - 1
                                                else:
                                                    current_directory = os.path.split(current_directory)[0]
                                            else:
                                                current_directory = f"{current_directory}/{file_list[self.selected_item_number]}"
                                                if current_directory[-1] == "/":
                                                    current_directory = current_directory[:-1]
                                            # get file list
                                            folders =  ["../"]
                                            #folders += glob.glob("*/", root_dir=current_directory)
                                            if not self.appState.sixteenc_browsing: 
                                                folders += sorted(filter(os.path.isdir, glob.glob(os.path.join(current_directory, "*/"))))
                                                # remove leading paths
                                                new_folders = []
                                                for path_string in folders:
                                                    new_folders.append(os.path.sep.join(path_string.split(os.path.sep)[-2:]))
                                                folders = new_folders

                                            if mask_all:
                                                masks = ['*.*']
                                            else:
                                                masks = default_masks
                                            matched_files = []
                                            file_list = []
                                            for file in os.listdir(current_directory):
                                                for mask in masks:
                                                    if fnmatch.fnmatch(file.lower(), mask.lower()):
                                                        matched_files.append(file)
                                                        break
                                            for dirname in folders:
                                                file_list.append(dirname)
                                            file_list += sorted(matched_files)
                                            # reset ui
                                            self.selected_item_number = 0
                                            search_string = ""
                                        elif self.appState.sixteenc_browsing:
                                            #self.notify("Double Clicked on 16c item")
                                            search_string = ""
                                            # Clicked a year or pack name in 16c, so navigate in.
                                            if self.sixteenc_levels[self.sixteenc_level] == "root":
                                                # Enter into a year
                                                #if file_list[current_line_number] != '../':
                                                try:
                                                    self.appState.sixteenc_year = file_list[self.selected_item_number]
                                                except:
                                                    pdb.set_trace()
                                                sixteenc_packs = self.sixteenc_api.list_packs_for_year(self.appState.sixteenc_year)
                                                try:
                                                    folders = ['../'] + sixteenc_packs
                                                except:
                                                    pdb.set_trace()
                                                file_list = folders
                                                full_file_list = file_list
                                                search_files_list = file_list
                                                self.sixteenc_level += 1    # from "root" to "year"
                                                self.selected_item_number = 0
                                                top_line = 0
                                                c = None

                                            elif self.sixteenc_levels[self.sixteenc_level] == "year":
                                                if file_list[self.selected_item_number] == '../':
                                                    # Navigate back down into root
                                                    self.sixteenc_level = 0    # from "year" to "root"
                                                    self.selected_item_number = 0
                                                    #self.selected_item_number = 0
                                                    self.appState.sixteenc_year = None
                                                    sixteenc_packs = None
                                                    #folders = ['../'] + self.sixteenc_years
                                                    folders = self.sixteenc_years
                                                    file_list = []
                                                    full_file_list = file_list
                                                    search_files_list = file_list
                                                    top_line = 0
                                                    c = None
                                                else:    
                                                    # Navigate from year into the pack
                                                    self.appState.sixteenc_pack = file_list[self.selected_item_number]
                                                    try:
                                                        sixteenc_files = self.sixteenc_api.list_files_for_pack(self.appState.sixteenc_pack)
                                                    except:
                                                        pdb.set_trace()
                                                    self.selected_item_number = 0
                                                    folders = ['../']
                                                    file_list = folders
                                                    file_list += sixteenc_files
                                                    full_file_list = file_list
                                                    search_files_list = file_list
                                                    #for dirname in folders:
                                                    #    file_list.append(dirname)
                                                    file_list = sorted(file_list)
                                                    self.sixteenc_level += 1    # from "year" to "pack"
                                                    top_line = 0
                                                    search_string = ""
                                            # Because 16c files are being added to the directory list, for some reason:
                                            elif self.sixteenc_levels[self.sixteenc_level] == "pack":
                                                # Picked a file, so download and load it 
                                                filename = file_list[self.selected_item_number]
                                                url = self.sixteenc_api.get_url_for_file(self.appState.sixteenc_pack, filename)
                                                self.cursorOn()
                                                return url, "remote"

                                    else:   # clicked a file, try to load it
                                        if self.appState.sixteenc_browsing:
                                            # Picked a file, so download and load it 
                                            filename = file_list[self.selected_item_number]
                                            url = self.sixteenc_api.get_url_for_file(self.appState.sixteenc_pack, filename)
                                            self.cursorOn()
                                            return url, "remote"
                                        else:
                                            full_path = f"{current_directory}/{file_list[self.selected_item_number]}"
                                            self.cursorOn()
                                            return full_path, "local"
                    if mouseLine == realmaxY - 4:    # on the button bar
                        if mouseCol in range(showall_column,showall_column+3):  # clicked [X] All
                            if self.appState.sixteenc_browsing == False:
                                if mask_all:
                                    mask_all = False
                                    masks = default_masks
                                else:
                                    mask_all = True
                                    masks = ['*.*']
                        elif self.appState.sixteenc_available and mouseCol in range(sixteen_column,sixteen_column+3):  # clicked [X] 16c
                            self.appState.sixteenc_browsing = not self.appState.sixteenc_browsing
                            folders =  ["../"]
                            #folders += glob.glob("*/", root_dir=current_directory)
                            if not self.appState.sixteenc_browsing: 
                                if mask_all:
                                    folders = ['../'] + sorted(filter(os.path.isdir, glob.glob(os.path.join(current_directory, ".*/")))) + \
                                        sorted(filter(os.path.isdir, glob.glob(os.path.join(current_directory, "*/"))))
                                else:
                                    folders = ['../'] + sorted(filter(os.path.isdir, glob.glob(os.path.join(current_directory, "*/"))))
                                # remove leading paths
                                new_folders = []
                                for path_string in folders:
                                    new_folders.append(os.path.sep.join(path_string.split(os.path.sep)[-2:]))
                                folders = new_folders


                        matched_files = []
                        file_list = []
                        file_list = self.findLocalFiles(current_directory, folders, masks)
                        # reset ui
                        self.selected_item_number = 0
                        search_string = ""
                        full_file_list = file_list
                        self.log.debug('repopulated file list', {'file_list': file_list})

                if not self.appState.hasMouseScroll:
                    curses.BUTTON5_PRESSED = 0
                    curses.BUTTON4_PRESSED = 0
                try:
                    curses.BUTTON5_PRESSED
                except:
                    curses.BUTTON5_PRESSED = 0
                try:
                    curses.BUTTON4_PRESSED
                except:
                    curses.BUTTON4_PRESSED = 0
                if mouseState & curses.BUTTON4_PRESSED:   # wheel up
                    # scroll up
                    # if the item isn't at the top of teh screen, move it up
                    current_section = 0
                    if self.selected_item_number > top_line:
                        self.selected_item_number -= 1
                    elif top_line > 0:
                        top_line -= 1
                elif mouseState & curses.BUTTON5_PRESSED:   # wheel down
                    # scroll down 
                    current_section = 0
                    if self.selected_item_number < len(file_list) - 1:
                        self.selected_item_number += 1
                        if self.selected_item_number == len(file_list) - top_line:
                            top_line += 1
                
            elif sections[current_section] == "showall":  # show all files checkbox
                # Change focus from files to other elements, ie: Show All Files checkbox
                #c = self.stdscr.getch()
                if c in [9]:       # 9 = Tab 
                    current_section += 1
                    if current_section > len(sections) - 1: # If we've tabbed through all sections,
                        current_section = 0     # circle back to 0 (main file selector)
                if c in [curses.KEY_UP, curses.KEY_DOWN]:       # 9 = Tab    
                    # Change focus away, back to file lister
                    current_section = 0
                elif c in [ord(' '), 13, curses.KEY_ENTER]:     # 13 = enter
                    # Check or uncheck Show All Files
                    mask_all = not mask_all
                    if mask_all:
                        masks = ['*.*']
                    else:
                        masks = default_masks



                    # update file list
                    matched_files = []
                    file_list = []
                    full_file_list = []
                    search_files_list = []
                    if self.appState.sixteenc_browsing: 
                        if self.sixteenc_levels[self.sixteenc_level] == "pack":
                            search_files_list = sixteenc_files
                    else:
                        search_files_list = os.listdir(current_directory)
                    for file in search_files_list:
                        for mask in masks:
                            if fnmatch.fnmatch(file.lower(), mask.lower()):
                                matched_files.append(file)
                                break
                    for dirname in folders:
                        file_list.append(dirname)
                    file_list += sorted(matched_files)
                    # reset ui
                    self.selected_item_number = 0
                    search_string = ""
                    full_file_list = file_list
                elif c in [ord('|')]:     # debug
                    pdb.set_trace()
                elif c in [27]:     # esc
                    prompting = False
                c = None

            elif sections[current_section] == "sixteenc":  # show all files checkbox
                if c in [9]:       # 9 = Tab 
                    current_section += 1
                    if current_section > len(sections) - 1: # If we've tabbed through all sections,
                        current_section = 0     # circle back to 0 (main file selector)
                if c in [curses.KEY_UP, curses.KEY_DOWN]:       # 9 = Tab    
                    current_section = 0
                elif c in [ord(' '), 13, curses.KEY_ENTER]:     # 13 = enter
                    self.appState.sixteenc_browsing = not self.appState.sixteenc_browsing

                    # set correct color mode
                    if self.appState.sixteenc_browsing:
                        if self.appState.colorMode != "16":
                            self.switchTo16ColorMode()
                    elif not self.appState.sixteenc_browsing:
                        # IF we aren't in the original mode, switch back
                        if old_color_mode != self.appState.colorMode:
                            if old_color_mode == "256":
                                self.switchTo256ColorMode()


                    # update file list
                    matched_files = []
                    file_list = []
                    full_file_list = []
                    if self.appState.sixteenc_browsing:
                        # Just turned on sixteenc browsing
                        self.sixteenc_level = 0
                        self.selected_item_number = 0

                        # If there's no 16c cache, make a new API object and cache the years
                        if self.sixteenc_api == None:
                            self.sixteenc_api = SixteenColorsAPI()
                        if self.sixteenc_years == None:
                            self.sixteenc_years = self.sixteenc_api.list_years()

                        # If we're at the root, navigate into the selected year
                        if self.sixteenc_levels[self.sixteenc_level] == "root":
                            #self.notify("Root of all 16colors evil")
                            # Update the file or directory listing
                            #if file_list[current_line_number] != '../':
                            self.appState.sixteenc_year = None
                            sixteenc_packs = None
                            #folders = ['../'] + self.sixteenc_years
                            folders = self.sixteenc_years
                            file_list = []
                            full_file_list = file_list
                            search_files_list = file_list
                        elif self.sixteenc_levels[self.sixteenc_level] == "year":
                            pass
                        elif self.sixteenc_levels[self.sixteenc_level] == "pack":
                            pass


                    else:   # update with files, not 16c

                        # update file list
                        matched_files = []
                        file_list = []
                        full_file_list = []

                        if mask_all:
                            folders = ['../'] + sorted(filter(os.path.isdir, glob.glob(os.path.join(current_directory, ".*/")))) + \
                                sorted(filter(os.path.isdir, glob.glob(os.path.join(current_directory, "*/"))))
                        else:
                            folders = ['../'] + sorted(filter(os.path.isdir, glob.glob(os.path.join(current_directory, "*/"))))
                        
                        # remove leading paths
                        new_folders = []
                        for path_string in folders:
                            new_folders.append(os.path.sep.join(path_string.split(os.path.sep)[-2:]))
                        folders = new_folders

                        matched_files = self.findLocalFiles(current_directory, folders, masks)
                        self.log.debug('found', {'matched_files': matched_files, 'folders': folders, 'current_directory': current_directory, 'masks': masks})
                        file_list += matched_files
                        # reset ui
                        self.selected_item_number = 0
                        search_string = ""
                        full_file_list = file_list

                         # file_list = folders
                        full_file_list = file_list
                        search_files_list = file_list

                if c in [27]:     # esc
                    prompting = False
                c = None



            elif sections[current_section] == "main":  # show all files checkbox
                if c == curses.KEY_LEFT:
                    pass
                elif c == curses.KEY_RIGHT:
                    pass
                elif c in [9]:  # 9 == tab key
                    current_section += 1
                    if self.appState.sixteenc_browsing: # skip hidden Show All button in 16c mode
                        if sections[current_section] == "showall":
                            current_section += 1
                    if current_section > len(sections) - 1: # If we've tabbed through all sections,
                        current_section = 0     # circle back to 0 (main file selector)

                elif c == curses.KEY_UP:
                    # move cursor up
                    if self.selected_item_number > 0:
                        if self.selected_item_number == top_line and top_line != 0:
                            top_line -= 1
                        self.selected_item_number -= 1
                    pass
                elif c == curses.KEY_DOWN:
                    if self.selected_item_number < len(file_list) - 1:
                        # move cursor down
                        self.selected_item_number += 1
                        # if we're at the bottom of the screen...
                        if self.selected_item_number - top_line == page_size and top_line < len(file_list) - page_size:
                            top_line += 1
                elif c in [339, curses.KEY_PPAGE]:  # page up
                    if self.selected_item_number - top_line > 0:  # first go to the top of the page
                        self.selected_item_number = top_line
                    else:   # if already there, go up a full page
                        self.selected_item_number -= page_size
                        top_line -= page_size 
                    # correct any overflow
                    if self.selected_item_number < 0:
                        self.selected_item_number = 0
                    if top_line < 0:
                        top_line = 0
                elif c in [338, curses.KEY_NPAGE]:  # page down
                    if self.selected_item_number - top_line < page_size - 1: # first go to bottom of the page
                        self.selected_item_number = page_size + top_line - 1
                    else:   # if already there, go down afull page
                        self.selected_item_number += page_size
                        top_line += page_size
                    # correct any overflow
                    if self.selected_item_number >= len(file_list):
                        self.selected_item_number = len(file_list) - 1
                    if top_line >= len(file_list):
                        top_line = len(file_list) - page_size
                elif c in [339, curses.KEY_HOME]:  # 339 = home
                    self.selected_item_number = 0
                    top_line = 0
                elif c in [338, curses.KEY_END]:   # 338 = end
                    self.selected_item_number = len(file_list) - 1
                    top_line = self.selected_item_number - page_size + 1
                    if top_line < 0:    # for small file lists
                        top_line = 0
                elif c in [13, curses.KEY_ENTER]:
                    # Pressed enter on a file or directory.
                    if self.appState.sixteenc_browsing:
                        # If we're at the root, navigate into the selected year
                        if self.sixteenc_levels[self.sixteenc_level] == "root":
                            # Enter into a year
                            #if file_list[current_line_number] != '../':
                            try:
                                self.appState.sixteenc_year = file_list[self.selected_item_number]
                            except:
                                pdb.set_trace()
                            sixteenc_packs = self.sixteenc_api.list_packs_for_year(self.appState.sixteenc_year)
                            try:
                                folders = ['../'] + sixteenc_packs
                            except:
                                pdb.set_trace()
                            file_list = folders
                            full_file_list = file_list
                            search_files_list = file_list
                            self.sixteenc_level += 1    # from "root" to "year"
                            self.selected_item_number = 0
                            top_line = 0
                            search_string = ""
                            # run caching thread to update file_id.diz's for the selected year
                            if self.appState.sixteenc_year not in self.appState.sixteenc_cached_years:
                                self.sixteenc_update_diz_cache_start_thread(self.appState.sixteenc_year)
                            #self.sixteenc_update_diz_cache(self.appState.sixteenc_year)
                            c = None
                        elif self.sixteenc_levels[self.sixteenc_level] == "year":
                            if file_list[self.selected_item_number] == '../':
                                # Navigate back down into root
                                self.sixteenc_level = 0    # from "year" to "root"
                                self.selected_item_number = 0
                                #self.selected_item_number = 0
                                self.appState.sixteenc_year = None
                                sixteenc_packs = None
                                #folders = ['../'] + self.sixteenc_years
                                folders = self.sixteenc_years
                                file_list = []
                                full_file_list = file_list
                                search_files_list = file_list
                                top_line = 0
                                search_string = ""
                                c = None
                            else:
                                # Navigate from year into the pack
                                self.appState.sixteenc_pack = file_list[self.selected_item_number]
                                try:
                                    sixteenc_files = self.sixteenc_api.list_files_for_pack(self.appState.sixteenc_pack)
                                except:
                                    pdb.set_trace()
                                self.selected_item_number = 0
                                folders = ['../']
                                file_list = folders
                                file_list += sixteenc_files
                                full_file_list = file_list
                                search_files_list = file_list
                                #for dirname in folders:
                                #    file_list.append(dirname)
                                file_list = sorted(file_list)
                                self.sixteenc_level += 1    # from "year" to "pack"
                                top_line = 0
                                search_string = ""
                            c = None
                        elif self.sixteenc_levels[self.sixteenc_level] == "pack":
                            if file_list[self.selected_item_number] == '../':
                                # Navigating back down from pack into year
                                self.selected_item_number = 0
                                sixteenc_packs = self.sixteenc_api.list_packs_for_year(self.appState.sixteenc_year)
                                try:
                                    folders = ['../'] + sixteenc_packs
                                except:
                                    pdb.set_trace()
                                file_list = folders
                                full_file_list = file_list
                                search_files_list = file_list
                                self.sixteenc_level = 1    # from "root" to "year"
                                top_line = 0
                                search_string = ""
                            else:
                                # Picked a file, so download and load it :)
                                filename = file_list[self.selected_item_number]
                                #pdb.set_trace()
                                url = self.sixteenc_api.get_url_for_file(self.appState.sixteenc_pack, filename)
                                self.cursorOn()
                                return url, "remote"
                            c = None


                    elif file_list[self.selected_item_number] in folders:
                        # change directories
                        if file_list[self.selected_item_number] == "../":
                            # "cd .."
                            if self.appState.sixteenc_browsing:
                                # Navigate "up" in 16c land...
                                pass
                            else:
                                current_directory = os.path.split(current_directory)[0]
                        else:
                            if not self.appState.sixteenc_browsing:
                                current_directory = f"{current_directory}/{file_list[self.selected_item_number]}"
                                if current_directory[-1] == "/":
                                    current_directory = current_directory[:-1]
                        # get file list
                        folders =  ["../"]
                        #folders += sorted(glob.glob("*/", root_dir=current_directory))
                        if self.appState.sixteenc_browsing:
                            pass
                        else:
                            if mask_all:
                                folders = ['../'] + sorted(filter(os.path.isdir, glob.glob(os.path.join(current_directory, ".*/")))) + \
                                    sorted(filter(os.path.isdir, glob.glob(os.path.join(current_directory, "*/"))))
                            else:
                                folders = ['../'] + sorted(filter(os.path.isdir, glob.glob(os.path.join(current_directory, "*/"))))
                            # remove leading paths
                        if not self.appState.sixteenc_browsing:
                            new_folders = []
                            for path_string in folders:
                                new_folders.append(os.path.sep.join(path_string.split(os.path.sep)[-2:]))
                            folders = new_folders

                        if mask_all:
                            masks = ['*.*']
                        else:
                            masks = default_masks
                        matched_files = []
                        file_list = []
                        if self.appState.sixteenc_browsing:
                            if self.appState.sixteenc_pack:
                                search_files_list = sixteenc_files
                            elif self.appState.sixteenc_year:
                                search_files_list = sixteenc_packs
                            else:
                                search_files_list = self.sixteenc_years
                        else:
                            search_files_list = os.listdir(current_directory)
                        for file in search_files_list:
                            for mask in masks:
                                if fnmatch.fnmatch(file.lower(), mask.lower()):
                                    matched_files.append(file)
                                    break
                        for dirname in folders:
                            file_list.append(dirname)
                        file_list += sorted(matched_files)
                        # reset ui
                        top_line = 0
                        self.selected_item_number = 0
                        search_string = ""
                        full_file_list = file_list

                    else:
                        # return the selected file
                        self.stdscr.clear()
                        prompting = False
                        full_path = f"{current_directory}/{file_list[self.selected_item_number]}"
                        self.appState.workingLoadDirectory = current_directory
                        self.cursorOn()
                        return full_path, "local"
                    #self.filePickerOptionsPicker()
                elif c == 21:   # ^U or ctrl-u
                    # clear the search field
                    if search_string != "":
                        search_string = ""
                elif c == 27:   # esc key
                    if search_string != "":
                        search_string = ""
                    else:
                        # switch back to old color mode
                        if old_color_mode != self.appState.colorMode:
                            if old_color_mode == "256":
                                self.switchTo256ColorMode()

                        self.stdscr.clear()
                        prompting = False
                        if self.playing:
                            self.stdscr.nodelay(1)
                        self.cursorOn()
                        return False, "local"
                elif c in [' curses.KEY_BACKSPACE', 263, 127]: # backspace
                    if search_string != "":
                        # if string is not empty, remove last character
                        search_string = search_string[:len(search_string)-1]
                elif c == None:
                    pass
                elif c == 0x019A:    # getch() gets this when resizing window, for some reason.
                    # unicode Latin Small Letter L with Bar.
                    pass
                else: # add to search string
                    try:
                        search_string += chr(c)
                    except ValueError:  # unprintable characters inserted by terminal when resizing,
                        # so don't add to search string.
                        pass
                    self.selected_item_number = 0
                    current_line_number = 0
                    top_line = 0
                    for filename in file_list:  # search list for search_string
                        if filename not in folders and filename.startswith(search_string):
                            #self.selected_item_number = file_list.index(filename)
                            break   # stop at the first match

            self.stdscr.clear()
        self.cursorOn()

        # switch back to old color mode
        if old_color_mode != self.appState.colorMode:
            if old_color_mode == "256":
                self.switchTo256ColorMode()

        return False, False
 Draw UI for selecting a file to load, return the filename 
durdraw/durdraw_ui_curses.py