1
1
# cspell:ignore KEY_NPAGE, KEY_PPAGE
2
+ # pylint: disable=too-many-lines
2
3
"""The main UI renderer."""
3
4
4
5
from __future__ import annotations
@@ -485,8 +486,11 @@ def _display(
485
486
line_index_str = str (line_index ).rjust (index_width )
486
487
prefix = f"{ line_index_str } \u2502 "
487
488
# 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
+ ):
490
494
# Rebuild the line with reverse-video decoration added
491
495
highlighted_parts = tuple (
492
496
CursesLinePart (
@@ -947,8 +951,10 @@ def _show_menu(
947
951
# Determine which row to highlight, if enabled
948
952
self ._highlight_line_offset = None
949
953
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
+ )
952
958
selected_global_index = self ._menu_indices [self ._menu_cursor_pos ]
953
959
try :
954
960
self ._highlight_line_offset = showing_indices .index (selected_global_index )
@@ -970,17 +976,23 @@ def _show_menu(
970
976
971
977
# Handle arrow navigation for menus when enabled
972
978
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 :
974
980
# Move the cursor position
975
981
if entry == "KEY_DOWN" and self ._menu_cursor_pos < len (self ._menu_indices ) - 1 :
976
982
self ._menu_cursor_pos += 1
977
983
# 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
+ ):
980
988
# Mimic _display scroll down
981
989
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
+ )
984
996
elif entry == "KEY_UP" and self ._menu_cursor_pos > 0 :
985
997
self ._menu_cursor_pos -= 1
986
998
# If moved before the first visible item, scroll up one
@@ -993,10 +1005,14 @@ def _show_menu(
993
1005
continue
994
1006
995
1007
# 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
+ )
1000
1016
index_to_select = self ._menu_indices [self ._menu_cursor_pos ]
1001
1017
entry = str (index_to_select )
1002
1018
self ._logger .debug ("Changed entry to: '%s'" , entry )
0 commit comments