From 06b2ebacd175d43b5c21f7e7c22aa0a42913431a Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Thu, 15 Jun 2023 00:52:34 +0300 Subject: [PATCH] Fix menus when exit ESC or CTRL+C So... After a long time i did fix for some menus Reduce errors hell in terminal --- funkwhale_cli.py | 15 ++++++++++++--- src/fw_albums.py | 7 ++++++- src/fw_artists.py | 8 ++++++-- src/fw_channels.py | 7 ++++++- src/fw_libraries.py | 7 ++++++- src/fw_playlists.py | 7 ++++++- src/fw_radios.py | 7 ++++++- src/fw_recents.py | 3 +++ src/fw_tracks.py | 6 +++++- src/mpv_control.py | 7 ++++++- 10 files changed, 62 insertions(+), 12 deletions(-) diff --git a/funkwhale_cli.py b/funkwhale_cli.py index a176bde..0c551d5 100755 --- a/funkwhale_cli.py +++ b/funkwhale_cli.py @@ -62,9 +62,13 @@ def main(): menu.append('Donate') if src.mpv_control.player.playlist_playing_pos != -1: menu.insert(0, 'Player') - ids = fzf.prompt(menu, f"--header={main_menu_header}") + selected = fzf.prompt(menu, f"--header={main_menu_header}") + if selected == []: + print('bye-bye :3') + break + else: + selected = selected[0] - selected = ids[0] if selected == 'Radios': list_radios() if selected == 'Artists': @@ -90,7 +94,12 @@ def main(): 'public_list_instances') + public_server_list_instances settings.set_config('public_list_instances', list_instances) instance = fzf.prompt(list_instances, - '--header='+quote(f'Select instance\nServer instances: +{new_ins_count}'))[0] + '--header='+quote(f'Select instance\nServer instances: +{new_ins_count}')) + if instance == []: + continue + else: + instance = instance[0] + current_instance.select_instance(instance) if selected == 'Sign in': print(f''' diff --git a/src/fw_albums.py b/src/fw_albums.py index b7f8e01..6611f5d 100644 --- a/src/fw_albums.py +++ b/src/fw_albums.py @@ -44,7 +44,12 @@ def list_albums(albums=None, pg=None, search=None, artist=None, library=None, in artist_name = artist_name.get('name') option_str += f' | {artist_name}' view.append(f'{option_str}') - select = fzf.prompt(view, '--header=\'map: album | tracks count | opt. artist\'')[0].split('.', 1)[0] + select = fzf.prompt(view, '--header=\'map: album | tracks count | opt. artist\'') + if select == []: + return + else: + select = select[0].split('.', 1)[0] + if select == 'Next page': list_albums(pg=albums_next) elif select == 'Prev page': diff --git a/src/fw_artists.py b/src/fw_artists.py index ff024ac..8b28667 100644 --- a/src/fw_artists.py +++ b/src/fw_artists.py @@ -26,7 +26,12 @@ def list_artists(pg=None, search=None, library=None, scope=None): artist_name = i.get('name') artist_tracks_count = i.get('tracks_count') view.append(f'{index}.{artist_name} | {artist_tracks_count}') - select = fzf.prompt(view, '--header=\'map: artist | tracks count\'')[0].split('.', 1)[0] + select = fzf.prompt(view, '--header=\'map: artist | tracks count\'') + if select == []: + return + else: + select = select[0].split('.', 1)[0] + if select == 'Next page': list_artists(pg=artists_next) elif select == 'Prev page': @@ -49,7 +54,6 @@ def list_artists(pg=None, search=None, library=None, scope=None): play_artist(artists_results[int(select)]['id']) - def play_artist(artist_id): tracks = get_tracks(artist=artist_id, include_channels=True, pg=None) tracks_next = tracks.get('next') diff --git a/src/fw_channels.py b/src/fw_channels.py index 9ee9571..fc61f40 100644 --- a/src/fw_channels.py +++ b/src/fw_channels.py @@ -22,7 +22,12 @@ def list_channels(pg=None, search=None): index = channels_results.index(i) channel_name = i.get('artist').get('name') view.append(f'{index}.{channel_name}') - select = fzf.prompt(view)[0].split('.', 1)[0] + select = fzf.prompt(view)[0].split('.', 1) + if select == []: + return + else: + select = select[0] + if select == 'Next page': list_channels(pg=channels_next) elif select == 'Prev page': diff --git a/src/fw_libraries.py b/src/fw_libraries.py index 8dd9ce8..9a9e5b4 100644 --- a/src/fw_libraries.py +++ b/src/fw_libraries.py @@ -29,7 +29,12 @@ def libraries(pg=None, radio=False): libraries_listing.append(f'{index}.{lib_name} | {lib_by} | {lib_tracks_count}') lib_select = fzf.prompt( libraries_listing, - f'--header=\'found {libs_count} libraries\nmap: library name | owner | tracks count\'')[0].split('.', 1) + f'--header=\'found {libs_count} libraries\nmap: library name | owner | tracks count\'') + if lib_select == []: + return + else: + lib_select = lib_select[0].split('.', 1) + if lib_select[0] == 'Next': return libraries(pg=libs_next) elif lib_select[0] == 'Prev': diff --git a/src/fw_playlists.py b/src/fw_playlists.py index bb3824a..dc25c85 100644 --- a/src/fw_playlists.py +++ b/src/fw_playlists.py @@ -22,7 +22,12 @@ def list_playlists(pg=None, search=None): index = playlists_results.index(i) playlist_name = i.get('name') view.append(f'{index}.{playlist_name}') - select = fzf.prompt(view)[0].split('.', 1)[0] + select = fzf.prompt(view) + if select == []: + return + else: + select = select[0].split('.', 1) + if select == 'Next page': list_playlists(pg=playlists_next) elif select == 'Prev page': diff --git a/src/fw_radios.py b/src/fw_radios.py index 631edfb..d44fd82 100644 --- a/src/fw_radios.py +++ b/src/fw_radios.py @@ -40,7 +40,12 @@ def list_radios(error_given=None): header += f'\n{error_given}' header = quote(header) selected = fzf.prompt( - view, f'--header {header} --read0', delimiter="\0")[0].split('.', 1) + view, f'--header {header} --read0', delimiter="\0") + if selected == []: + return + else: + selected = selected[0].split('.', 1) + if 'Favourites' in selected: radio_load(id_radio, 'favorites', name='your favorites tracks') elif 'Tag' in selected: diff --git a/src/fw_recents.py b/src/fw_recents.py index 348abf4..4e75b9b 100644 --- a/src/fw_recents.py +++ b/src/fw_recents.py @@ -30,6 +30,9 @@ def list_fav_or_history(pg=None, search=None, scope=None, is_history_view=False) who_user = i['user'].get('username') view.append(f'{index}.{track_name} | {who_user}') select = fzf.prompt(view, f'--multi --header=\'map: track title | who {action}\'') + if select == []: + return + if 'Next page' in select: list_fav_or_history(pg=tracks_next, is_history_view=is_history_view) elif 'Prev page' in select: diff --git a/src/fw_tracks.py b/src/fw_tracks.py index 27aab52..71d4ae8 100644 --- a/src/fw_tracks.py +++ b/src/fw_tracks.py @@ -24,7 +24,11 @@ def list_tracks(pg=None, search=None, tag=None, library=None): index = tracks_results.index(i) track_name = i.get('title') view.append(f'{index}.{track_name}') - select = fzf.prompt(view)[0].split('.', 1)[0] + select = fzf.prompt(view) + if select == []: + return + else: + select = select[0].split('.', 1)[0] if select == 'Next page': list_tracks(pg=tracks_next) elif select == 'Prev page': diff --git a/src/mpv_control.py b/src/mpv_control.py index d57acf1..5b24bdb 100644 --- a/src/mpv_control.py +++ b/src/mpv_control.py @@ -138,7 +138,12 @@ def player_menu(header='', storage={}): player_items_menu.append('Like') player_items_menu.extend(['Hide artist', 'Exit']) - select = fzf.prompt(player_items_menu, quote(f"--header=\'{header}\'"))[0] + select = fzf.prompt(player_items_menu, quote(f"--header=\'{header}\'")) + if select == []: + break + else: + select = select[0] + if select == 'Next': try: player.playlist_next()