@@ -493,7 +493,7 @@ def get_char_limit(self, text: str) -> int:
493
493
# print(f'Char Limit: {char_limit}, Len: {len(text)}')
494
494
return char_limit
495
495
496
- def truncate_text (self , text : str ) -> int :
496
+ def truncate_text (self , text : str ) -> str :
497
497
"""Returns a truncated string for displaying, calculated with `get_char_limit()`."""
498
498
if len (text ) > self .get_char_limit (text ):
499
499
# print(f'Char Limit: {self.get_char_limit(text)}, Len: {len(text)}')
@@ -761,7 +761,7 @@ def print_columns(self, content: list[object], add_enum: False) -> None:
761
761
offset = 1 if (index >= row_count ) and (
762
762
row_number != row_count ) else 0
763
763
elif displayable % table_size != 0 :
764
- if col_num > 1 and col_num <= displayable % table_size :
764
+ if 1 < col_num <= displayable % table_size :
765
765
offset += col_num - 1
766
766
elif col_num > 1 and col_num > displayable % table_size :
767
767
offset = displayable % table_size
@@ -1022,30 +1022,31 @@ def global_commands(self, com:list[str]) -> tuple[bool,str]:
1022
1022
"""
1023
1023
was_executed :bool = False
1024
1024
message :str = ''
1025
+ com_name = com [0 ].lower ()
1025
1026
1026
1027
# Backup Library =======================================================
1027
- if ( com [ 0 ]. lower () == 'backup' ) :
1028
+ if com_name == 'backup' :
1028
1029
self .backup_library (display_message = False )
1029
1030
was_executed = True
1030
1031
message = f'{ INFO } Backed up Library to disk.'
1031
1032
# Create Collage =======================================================
1032
- elif ( com [ 0 ]. lower () == 'collage' ) :
1033
+ elif com_name == 'collage' :
1033
1034
filename = self .create_collage ()
1034
1035
if filename :
1035
1036
was_executed = True
1036
1037
message = f'{ INFO } Saved collage to \" { filename } \" .'
1037
1038
# Save Library =========================================================
1038
- elif ( com [ 0 ]. lower () == 'save' or com [ 0 ]. lower () == 'write' or com [ 0 ]. lower () == 'w' ):
1039
+ elif com_name in ( 'save' , 'write' , 'w' ):
1039
1040
self .save_library (display_message = False )
1040
1041
was_executed = True
1041
1042
message = f'{ INFO } Library saved to disk.'
1042
1043
# Toggle Debug =========================================================
1043
- elif ( com [ 0 ]. lower () == 'toggle-debug' ) :
1044
+ elif com_name == 'toggle-debug' :
1044
1045
self .args .debug = not self .args .debug
1045
1046
was_executed = True
1046
1047
message = f'{ INFO } Debug Mode Active.' if self .args .debug else f'{ INFO } Debug Mode Deactivated.'
1047
1048
# Toggle External Preview ==============================================
1048
- elif ( com [ 0 ]. lower () == 'toggle-external-preview' ) :
1049
+ elif com_name == 'toggle-external-preview' :
1049
1050
self .args .external_preview = not self .args .external_preview
1050
1051
if self .args .external_preview :
1051
1052
self .init_external_preview ()
@@ -1054,11 +1055,11 @@ def global_commands(self, com:list[str]) -> tuple[bool,str]:
1054
1055
was_executed = True
1055
1056
message = f'{ INFO } External Preview Enabled.' if self .args .external_preview else f'{ INFO } External Preview Disabled.'
1056
1057
# Quit =================================================================
1057
- elif com [ 0 ]. lower () == 'quit' or com [ 0 ]. lower () == 'q' :
1058
+ elif com_name in ( 'quit' , 'q' ) :
1058
1059
self .exit (save = True , backup = False )
1059
1060
was_executed = True
1060
1061
# Quit without Saving ==================================================
1061
- elif com [ 0 ]. lower () == 'quit!' or com [ 0 ]. lower () == 'q!' :
1062
+ elif com_name in ( 'quit!' , 'q!' ) :
1062
1063
self .exit (save = False , backup = False )
1063
1064
was_executed = True
1064
1065
@@ -1345,7 +1346,7 @@ def scr_library_home(self, clear_scr=True):
1345
1346
# self.scr_library_home(clear_scr=False)
1346
1347
# Add New Entries ==================================================
1347
1348
elif ' ' .join (com ) == 'add new' :
1348
- if self .is_new_file_count_init == False :
1349
+ if not self .is_new_file_count_init :
1349
1350
print (
1350
1351
f'{ INFO } Scanning for files in \' { self .lib .library_dir } \' (This may take a while)...' )
1351
1352
# if not self.lib.files_not_in_library:
@@ -1390,7 +1391,7 @@ def scr_library_home(self, clear_scr=True):
1390
1391
for unresolved in self .lib .missing_matches :
1391
1392
res = self .scr_choose_missing_match (
1392
1393
self .lib .get_entry_id_from_filepath (unresolved ), clear_scr = False )
1393
- if res != None and int (res ) >= 0 :
1394
+ if res is not None and int (res ) >= 0 :
1394
1395
clear ()
1395
1396
print (
1396
1397
f'{ INFO } Updated { self .lib .entries [self .lib .get_entry_id_from_filepath (unresolved )].path } -> { self .lib .missing_matches [unresolved ][res ]} ' )
@@ -2049,14 +2050,15 @@ def scr_choose_option(self, subtitle: str, choices: list, prompt: str = '', requ
2049
2050
'<#> Quit' , BRIGHT_CYAN_FG ))
2050
2051
print ('> ' , end = '' )
2051
2052
2052
- com : list [str ] = input ().lstrip (). rstrip ().split (' ' )
2053
+ com : list [str ] = input ().strip ().split (' ' )
2053
2054
gc , message = self .global_commands (com )
2054
2055
if gc :
2055
2056
if message :
2056
2057
clear ()
2057
2058
print (message )
2058
2059
clear_scr = False
2059
2060
else :
2061
+ com_name = com [0 ].lower ()
2060
2062
2061
2063
try :
2062
2064
# # Quit =========================================================
@@ -2069,13 +2071,13 @@ def scr_choose_option(self, subtitle: str, choices: list, prompt: str = '', requ
2069
2071
# # self.cleanup()
2070
2072
# sys.exit()
2071
2073
# Cancel =======================================================
2072
- if ( com [ 0 ]. lower () == 'cancel' or com [ 0 ]. lower () == 'c' or com [ 0 ] == '0' ) and required == False :
2074
+ if com_name in ( 'cancel' , 'c' , '0' ) and not required :
2073
2075
clear ()
2074
2076
return - 1
2075
2077
# Selection ====================================================
2076
- elif int ( com [ 0 ]) > 0 and int (com [ 0 ] ) <= len (choices ):
2078
+ elif com_name . isdigit () and 0 < int (com_name ) <= len (choices ):
2077
2079
clear ()
2078
- return int (com [ 0 ] ) - 1
2080
+ return int (com_name ) - 1
2079
2081
else :
2080
2082
# invalid_input = True
2081
2083
# print(self.format_h1(str='Please Enter a Valid Selection Number', color=BRIGHT_RED_FG))
@@ -2554,7 +2556,7 @@ def scr_select_field_templates(self, field_ids: list[int], allow_multiple=True,
2554
2556
f'Enter #{ plural } Cancel' , fg_color ))
2555
2557
print ('> ' , end = '' )
2556
2558
2557
- com : list [int ] = input ().split (' ' )
2559
+ com : list [str ] = input ().split (' ' )
2558
2560
selected_ids : list [int ] = []
2559
2561
try :
2560
2562
for c in com :
@@ -2625,14 +2627,14 @@ def scr_edit_entry_text(self, entry_index, field_index, allow_newlines=True, cle
2625
2627
self .lib .update_entry_field (
2626
2628
entry_index , field_index , new_content .rstrip ('\n ' ).rstrip ('\r ' ), 'replace' )
2627
2629
2628
- def scr_list_tags (self , query : str = '' , tag_ids : list [int ] = [] , clear_scr = True ) -> None :
2630
+ def scr_list_tags (self , query : str = '' , tag_ids : list [int ] = None , clear_scr = True ) -> None :
2629
2631
"""A screen for listing out and performing CRUD operations on Library Tags."""
2630
2632
# NOTE: While a screen that just displays the first 40 or so random tags on your screen
2631
2633
# isn't really that useful, this is just a temporary measure to provide a launchpad
2632
2634
# screen for necessary commands such as adding and editing tags.
2633
2635
# A more useful screen presentation might look like a list of ranked occurrences, but
2634
2636
# that can be figured out and implemented later.
2635
-
2637
+ tag_ids = tag_ids or []
2636
2638
title = f'{ self .base_title } - Library \' { self .lib .library_dir } \' '
2637
2639
2638
2640
@@ -2673,17 +2675,17 @@ def scr_list_tags(self, query: str = '', tag_ids: list[int] = [], clear_scr=True
2673
2675
'Create Edit <#> Delete <#> Search <Query> Close/Done' , BRIGHT_MAGENTA_FG ))
2674
2676
print ('> ' , end = '' )
2675
2677
2676
- com : list [str ] = input ().lstrip (). rstrip ().split (' ' )
2678
+ com : list [str ] = input ().strip ().split (' ' )
2677
2679
gc , message = self .global_commands (com )
2678
2680
if gc :
2679
2681
if message :
2680
2682
clear ()
2681
2683
print (message )
2682
2684
clear_scr = False
2683
2685
else :
2684
-
2686
+ com_name = com [ 0 ]. lower ()
2685
2687
# Search Tags ==========================================================
2686
- if ( com [ 0 ]. lower () == 'search' or com [ 0 ]. lower () == 's' ):
2688
+ if com_name in ( 'search' , 's' ):
2687
2689
if len (com ) > 1 :
2688
2690
new_query : str = ' ' .join (com [1 :])
2689
2691
# self.scr_list_tags(prev_scr, query=new_query,
@@ -2696,7 +2698,7 @@ def scr_list_tags(self, query: str = '', tag_ids: list[int] = [], clear_scr=True
2696
2698
tag_ids = self .lib .search_tags ('' )
2697
2699
# return
2698
2700
# Edit Tag ===========================================================
2699
- elif com [ 0 ]. lower () == 'edit' or com [ 0 ]. lower () == 'e' :
2701
+ elif com_name in ( 'edit' , 'e' ) :
2700
2702
if len (com ) > 1 :
2701
2703
try :
2702
2704
index = int (com [1 ]) - 1
@@ -2720,7 +2722,7 @@ def scr_list_tags(self, query: str = '', tag_ids: list[int] = [], clear_scr=True
2720
2722
# return
2721
2723
2722
2724
# Create Tag ============================================================
2723
- elif com [ 0 ]. lower () == 'create' or com [ 0 ]. lower () == 'mk' :
2725
+ elif com_name in ( 'create' , 'mk' ) :
2724
2726
tag = Tag (id = 0 , name = 'New Tag' , shorthand = '' ,
2725
2727
aliases = [], subtags_ids = [], color = '' )
2726
2728
self .scr_manage_tag (
@@ -2731,7 +2733,7 @@ def scr_list_tags(self, query: str = '', tag_ids: list[int] = [], clear_scr=True
2731
2733
# self.scr_list_tags(prev_scr, query=query, tag_ids=tag_ids)
2732
2734
# return
2733
2735
# Delete Tag ===========================================================
2734
- elif com [ 0 ]. lower () == 'delete' or com [ 0 ]. lower () == 'del' :
2736
+ elif com_name in ( 'delete' , 'del' ) :
2735
2737
if len (com ) > 1 :
2736
2738
if len (com ) > 1 :
2737
2739
try :
@@ -2757,7 +2759,7 @@ def scr_list_tags(self, query: str = '', tag_ids: list[int] = [], clear_scr=True
2757
2759
# tag_ids=tag_ids, clear_scr=False)
2758
2760
# return
2759
2761
# Close View ===========================================================
2760
- elif ( com [ 0 ]. lower () == 'close' or com [ 0 ]. lower () == 'c' or com [ 0 ]. lower () == 'done' ):
2762
+ elif com_name in ( 'close' , 'c' , 'done' ):
2761
2763
# prev_scr()
2762
2764
return
2763
2765
# # Quit =================================================================
@@ -3192,7 +3194,7 @@ def scr_tag_color_dropdown(self, fallback: str, colors: list[str], clear_scr=Tru
3192
3194
3193
3195
selected : str = input ()
3194
3196
try :
3195
- if int ( selected ) > 0 and int (selected ) <= len (colors ):
3197
+ if selected . isdigit () and 0 < int (selected ) <= len (colors ):
3196
3198
selected = colors [int (selected )- 1 ]
3197
3199
return selected
3198
3200
# except SystemExit:
0 commit comments