11# cspell:ignore KEY_NPAGE, KEY_PPAGE
2+ # pylint: disable=too-many-lines
23"""The main UI renderer."""
34
45from __future__ import annotations
@@ -485,8 +486,11 @@ def _display(
485486 line_index_str = str (line_index ).rjust (index_width )
486487 prefix = f"{ line_index_str } \u2502 "
487488 # Apply highlight decoration when this is the selected row
488- if (indent_heading and self ._highlight_line_offset is not None and
489- idx == self ._highlight_line_offset ):
489+ if (
490+ indent_heading
491+ and self ._highlight_line_offset is not None
492+ and idx == self ._highlight_line_offset
493+ ):
490494 # Rebuild the line with reverse-video decoration added
491495 highlighted_parts = tuple (
492496 CursesLinePart (
@@ -947,8 +951,10 @@ def _show_menu(
947951 # Determine which row to highlight, if enabled
948952 self ._highlight_line_offset = None
949953 if self ._menu_indices :
950- self ._menu_cursor_pos = max (0 , min (self ._menu_cursor_pos ,
951- len (self ._menu_indices ) - 1 ))
954+ self ._menu_cursor_pos = max (
955+ 0 ,
956+ min (self ._menu_cursor_pos , len (self ._menu_indices ) - 1 ),
957+ )
952958 selected_global_index = self ._menu_indices [self ._menu_cursor_pos ]
953959 try :
954960 self ._highlight_line_offset = showing_indices .index (selected_global_index )
@@ -970,17 +976,23 @@ def _show_menu(
970976
971977 # Handle arrow navigation for menus when enabled
972978 if entry in ["KEY_RESIZE" , "KEY_DOWN" , "KEY_UP" , "KEY_NPAGE" , "KEY_PPAGE" , "^F" , "^B" ]:
973- if ( entry in ["KEY_DOWN" , "KEY_UP" ] and self ._menu_indices ) :
979+ if entry in ["KEY_DOWN" , "KEY_UP" ] and self ._menu_indices :
974980 # Move the cursor position
975981 if entry == "KEY_DOWN" and self ._menu_cursor_pos < len (self ._menu_indices ) - 1 :
976982 self ._menu_cursor_pos += 1
977983 # If moved past the last visible item, scroll down one
978- if (self ._highlight_line_offset is None or
979- self ._highlight_line_offset >= len (showing_indices ) - 1 ):
984+ if (
985+ self ._highlight_line_offset is None
986+ or self ._highlight_line_offset >= len (showing_indices ) - 1
987+ ):
980988 # Mimic _display scroll down
981989 viewport_height = self ._screen_height - len (menu_heading ) - 1
982- self .scroll (max (min (self .scroll () + 1 , len (self ._menu_indices )),
983- viewport_height ))
990+ self .scroll (
991+ max (
992+ min (self .scroll () + 1 , len (self ._menu_indices )),
993+ viewport_height ,
994+ ),
995+ )
984996 elif entry == "KEY_UP" and self ._menu_cursor_pos > 0 :
985997 self ._menu_cursor_pos -= 1
986998 # If moved before the first visible item, scroll up one
@@ -993,10 +1005,14 @@ def _show_menu(
9931005 continue
9941006
9951007 # Enter key should select the highlighted item when cursor nav is enabled
996- if ((entry == "CURSOR_ENTER" or entry in ["^J" , "^M" , "KEY_ENTER" , "KEY_RETURN" ]) and
997- self ._menu_indices ):
998- self ._logger .debug ("Enter key selection triggered! Entry: '%s', Selecting index %s" ,
999- entry , self ._menu_cursor_pos )
1008+ if (
1009+ entry == "CURSOR_ENTER" or entry in ["^J" , "^M" , "KEY_ENTER" , "KEY_RETURN" ]
1010+ ) and self ._menu_indices :
1011+ self ._logger .debug (
1012+ "Enter key selection triggered! Entry: '%s', Selecting index %s" ,
1013+ entry ,
1014+ self ._menu_cursor_pos ,
1015+ )
10001016 index_to_select = self ._menu_indices [self ._menu_cursor_pos ]
10011017 entry = str (index_to_select )
10021018 self ._logger .debug ("Changed entry to: '%s'" , entry )
0 commit comments