fix sonarlint alerts
This commit is contained in:
parent
7a11ca5fa5
commit
494bfcf654
|
@ -2,8 +2,8 @@
|
|||
|
||||
## Description
|
||||
`kls` is a cli tool based on `kubectl` for managing kubernetes cluster resources.
|
||||
Inspired by `lf` and `ranger` file managers.
|
||||
It is lightweight (~200 lines of code) and easy to customize. Supports mouse navigation as well as keyboard navigation.
|
||||
Inspired by `lf` and `ranger` file managers, written in python.
|
||||
It is lightweight (~250 lines of code) and easy to customize. Supports mouse navigation as well as keyboard navigation.
|
||||
|
||||
## Key bindings
|
||||
For kubectl (You can customize these bindings or add extra bindings in `KEY_BINDINGS` variable of `kls` in a row #4):
|
||||
|
|
34
kls
34
kls
|
@ -159,6 +159,22 @@ def handle_mouse(mouse_info: tuple, menu: Menu):
|
|||
MENUS[2].visible_row_index = 0 # reset the selected row index of third menu before redrawing
|
||||
|
||||
|
||||
def handle_vertical_arrows(key, menu):
|
||||
if key == "KEY_DOWN" and len(menu.visible_rows()) > 1:
|
||||
if (menu.visible_row_index + 1) == ROWS_HEIGHT and len(menu.filtered_rows) > ROWS_HEIGHT:
|
||||
menu.filtered_rows.forward(1)
|
||||
else:
|
||||
menu.visible_row_index = (menu.visible_row_index + 1) % len(menu.filtered_rows) # index of the selected visible row
|
||||
elif key == "KEY_UP" and len(menu.visible_rows()) > 1:
|
||||
if menu.visible_row_index == 0 and len(menu.filtered_rows) > ROWS_HEIGHT:
|
||||
menu.filtered_rows.backward(1)
|
||||
else:
|
||||
menu.visible_row_index = (menu.visible_row_index - 1) % len(menu.filtered_rows) # index of the selected visible row
|
||||
draw_rows(menu) # this will change selected row in menu
|
||||
if menu != MENUS[2]:
|
||||
MENUS[2].visible_row_index = 0
|
||||
|
||||
|
||||
def catch_input(menu: Menu):
|
||||
while True: # refresh third menu until key pressed
|
||||
try:
|
||||
|
@ -173,22 +189,8 @@ def catch_input(menu: Menu):
|
|||
draw_row(menu.win, menu.title, 1, 2, selected=False) # remove selection from the current menu title
|
||||
draw_row(next_menu.win, next_menu.title, 1, 2, selected=True) # and select the new menu title
|
||||
globals().update(SELECTED_MENU=next_menu)
|
||||
elif key == "KEY_DOWN" and len(menu.visible_rows()) > 1:
|
||||
if (menu.visible_row_index + 1) == ROWS_HEIGHT and len(menu.filtered_rows) > ROWS_HEIGHT:
|
||||
menu.filtered_rows.forward(1)
|
||||
else:
|
||||
menu.visible_row_index = (menu.visible_row_index + 1) % len(menu.filtered_rows) # index of the selected visible row
|
||||
draw_rows(menu) # this will change selected row in menu
|
||||
if menu != MENUS[2]:
|
||||
MENUS[2].visible_row_index = 0
|
||||
elif key == "KEY_UP" and len(menu.visible_rows()) > 1:
|
||||
if menu.visible_row_index == 0 and len(menu.filtered_rows) > ROWS_HEIGHT:
|
||||
menu.filtered_rows.backward(1)
|
||||
else:
|
||||
menu.visible_row_index = (menu.visible_row_index - 1) % len(menu.filtered_rows) # index of the selected visible row
|
||||
draw_rows(menu) # this will change selected row in menu
|
||||
if menu != MENUS[2]:
|
||||
MENUS[2].visible_row_index = 0
|
||||
elif key in ["KEY_UP", "KEY_DOWN"] and len(menu.visible_rows()) > 1:
|
||||
handle_vertical_arrows(key, menu)
|
||||
elif key == "KEY_MOUSE" and MOUSE_ENABLED:
|
||||
try:
|
||||
mouse_info = curses.getmouse()
|
||||
|
|
Loading…
Reference in New Issue