From 4131bf0a6aa3da6c8c73ee04e1cd9391dba37915 Mon Sep 17 00:00:00 2001 From: Digital Studium Date: Thu, 11 Apr 2024 23:57:07 +0300 Subject: [PATCH] Fix shell --- .gitignore | 1 + .idea/kls.iml | 2 +- .idea/misc.xml | 2 +- a.out | Bin 0 -> 16416 bytes c_kls.c | 20 ++++++++++++++ kls | 73 ++++++++++++++++++++++++++----------------------- 6 files changed, 62 insertions(+), 36 deletions(-) create mode 100755 a.out create mode 100644 c_kls.c diff --git a/.gitignore b/.gitignore index 485dee6..e04276f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea +venv diff --git a/.idea/kls.iml b/.idea/kls.iml index d0876a7..17a1594 100644 --- a/.idea/kls.iml +++ b/.idea/kls.iml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index a6218fe..092c1db 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/a.out b/a.out new file mode 100755 index 0000000000000000000000000000000000000000..3e2a6d9de37acbefb52eef7991a62de2b2ce4609 GIT binary patch literal 16416 zcmeHOeQXrR6`woX;Diqw3aNnvFEmId;Kk;{HHi%8PtGkiE;bEmOP958&pzcooV_)+ zQQEp8Bp^T{ibOw@R#3bA+3wb-AsLb;&#o**2S_ZvJdDj`tu%|trhNHzs&A4c^H4?J6!E5r$5OCANscGR z1dm3Fr(bGd!=%Zx5Psf%;`wD8`Lo12F!jFc#6C=YJ;d9n$zsG^Qo&*)Nv`iRz{9xw zw~24_UaGIyedwV$vZUK7HYF4N4O=%QW3|addStA2tg)fCVXL0a=$mB|uw7UO_NiUn z`$Tv`Od-a6%rAoj!;1C?o;iBtm4#yJnGG!`Kdrylkusk@!(|``eK4Uv-(u7;zYq@e zQP=;~keE;yK;rs_lMi0AuB0$uD7^^a(gFr7Pb+|*1gwz%fg*Tc5&TO<@P`1`;P9s; z0EO!9D1u}E(BSZ=E&vL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Z|7*l= zp#u3m!j*(0A31*hcL2kfaQW`VN{oKdr`5sH0=X;a?`hN*Vtb*^K(8!zQdQw^V`Io@p zaOE15{r&wta$-%os&Kl1T8ZVbNz8CYm5`zB(%KaKaJ`u$mFIRl&u51-#ZF4SUa zbNx+eb2{^HfdTs-J+|EU0^VQDfyMEIiFtery{^AHtSP95$cK=J*6+t1G*93R|vNu<;8R+agkuW+uHeerdm5P#<< Ml?U&eWPd;ZKUQ_Q(EtDd literal 0 HcmV?d00001 diff --git a/c_kls.c b/c_kls.c new file mode 100644 index 0000000..c7dec08 --- /dev/null +++ b/c_kls.c @@ -0,0 +1,20 @@ +#include + +int main() +{ + initscr(); /* Start curses mode */ + printw("Hello World !!!\n"); /* Print Hello World */ + refresh(); /* Print it on to the real screen */ + def_shell_mode(); /* Save the tty modes */ + endwin(); /* End curses mode temporarily */ + system("vim"); /* Do whatever you like in cooked mode */ + reset_shell_mode(); /* Return to the previous tty mode*/ + /* stored by def_prog_mode() */ + refresh(); /* Do refresh() to restore the */ + /* Screen contents */ + printw("Another String\n"); /* Back to curses use the full */ + refresh(); /* capabilities of curses */ + endwin(); /* End curses mode */ + + return 0; +} diff --git a/kls b/kls index 5bbd9c1..16ea5a5 100755 --- a/kls +++ b/kls @@ -2,8 +2,9 @@ import curses import subprocess -stdscr = None -curses.set_escdelay(1) # в curses зачем-то сделали задержку на срабатывание Escape, уменьшаем её до 1 милисекунды (до 0 нельзя) +screen = None +# в curses зачем-то сделали задержку на срабатывание Escape, уменьшаем её до 1 милисекунды (до 0 нельзя) +curses.set_escdelay(1) running = True # состояния меню @@ -15,12 +16,12 @@ NOT_SELECTED_WITH_SEARCH = 4 # я не знаю, что делается в этой функции. def init_screen(): - global stdscr - stdscr = curses.initscr() - stdscr.refresh() + global screen + screen = curses.initscr() + screen.refresh() curses.noecho() curses.cbreak() - stdscr.keypad(True) + screen.keypad(True) curses.curs_set(0) @@ -66,24 +67,8 @@ menu3 = Menu("Resources", pods, 0 + curses.COLS // 3 * 2, NOT_SELECTED_WITHOUT_S menus = [menu1, menu2, menu3] -# def run_command(command, menu, rows=None): -# namespace = menu1.rows[menu1.row] -# api_resource = menu2.rows[menu2.row] -# resource = menu3.rows[menu3.row] -# subprocess.call(eval(command), shell=True) -# init_screen() -# for menu in menus: -# menu.win.clear() -# menu.win.box() -# menu.win.addstr(1, 2, menu.name) -# menu.win.addstr(curses.LINES - 2, 2, menu.filter) -# if rows and menu.name == "Resources": -# menu.rows = rows -# menu.row = 0 -# for index, row in enumerate(menu.rows): -# menu.win.addstr(index + 3, 2, row) -# menu.win.addstr(menu.row + 3, 2, menu.rows[menu.row], curses.A_REVERSE | curses.A_ITALIC) -# menu.win.addstr(1, 2, menu.name, curses.A_REVERSE | curses.A_ITALIC) +def run_command(command): + subprocess.call(eval(command), shell=True) def update_menu3(): @@ -108,6 +93,7 @@ def draw_menu(menu): draw_rows(menu) # рисуем строки меню draw_search_box(menu) # рисуем строку поиска + def draw_header(menu): if menu.state in [1, 2]: menu.win.addstr(1, 2, menu.name, curses.A_REVERSE | curses.A_ITALIC) @@ -140,7 +126,7 @@ def draw_search_box(menu): def catch_input(menu): global running - key_pressed = stdscr.getkey() + key_pressed = screen.getkey() match key_pressed: case "/": menu.state = SELECTED_WITH_SEARCH @@ -173,6 +159,25 @@ def catch_input(menu): navigate_vertically("down", menu) case "KEY_UP": navigate_vertically("up", menu) + case 'g': + if menu3.state in [1, 2]: + # update_menu3() + if menu3.rows: + if not menu3.rows[menu3.row].startswith("No resources"): + curses.def_shell_mode() + curses.endwin() + command = "f'kubectl -n {menu1.rows[menu1.row]} get {menu2.rows[menu2.row]} {menu3.rows[menu3.row]} -o yaml | batcat -l yaml --paging always --style numbers'" + run_command(command) + curses.reset_shell_mode() + # case 'd': + # if current_menu == 2 and not menus[2].rows[menus[2].row].startswith("No resources"): + # run_command("f'kubectl -n {namespace} describe {api_resource} {resource} | batcat -l yaml --paging always --style numbers'", current_menu) + # case 'l': + # if current_menu == 2 and not menus[2].rows[menus[2].row].startswith("No resources") and menus[1].rows[menus[1].row] == "pods": + # run_command("f'kubectl -n {namespace} logs {resource} | batcat -l log --paging always --style numbers'", current_menu) + # case 'e': + # if current_menu == 2 and not menus[2].rows[menus[2].row].startswith("No resources"): + # run_command("f'kubectl edit {api_resource} -n {namespace} {resource}'", current_menu) case _: if menu.state == SELECTED_WITH_SEARCH and key_pressed.isalpha() or key_pressed == "-": # объекты в кубе не могут иметь иных символов кроме a-z и - menu.filter += key_pressed @@ -213,9 +218,9 @@ def navigate_vertically(direction, menu): menu.win.addstr(menu.row + 3, 2, filtered_rows[menu.row], curses.A_REVERSE | curses.A_ITALIC) # и выделяем её -def main(stdscr): +def main(screen): global running - stdscr.refresh() + screen.refresh() # начальный экран for menu in menus: draw_menu(menu) @@ -407,12 +412,12 @@ def main(stdscr): # navigate_vertically("down", current_menu) # case "KEY_UP": # navigate_vertically("up", current_menu) -# main(stdscr) -curses.wrapper(main) +main(screen) +# curses.wrapper(main) -# curses.nocbreak() -# stdscr.keypad(False) -# curses.echo() -# curses.endwin() -# subprocess.call(["clear"]) +curses.nocbreak() +screen.keypad(False) +curses.echo() +curses.endwin() +subprocess.call(["clear"]) #