Change config
This commit is contained in:
parent
06d8956aa0
commit
19b9f8b639
25
README.md
25
README.md
|
@ -6,25 +6,24 @@
|
||||||
Inspired by `lf` and `ranger` file managers, written in python.
|
Inspired by `lf` and `ranger` file managers, written in python.
|
||||||
|
|
||||||
It is lightweight (~400 lines of code) and easy to customize.
|
It is lightweight (~400 lines of code) and easy to customize.
|
||||||
Supports keyboard navigation and mouse navigation could be enabled (set MOUSE_ENABLED=True in a line #64).
|
Supports keyboard navigation and mouse navigation could be enabled (set MOUSE_ENABLED=True in a line #68).
|
||||||
|
|
||||||
## Key bindings
|
## Key bindings
|
||||||
|
|
||||||
### For kubectl
|
### For kubectl
|
||||||
|
|
||||||
You can customize these bindings or add extra bindings in `KEY_BINDINGS` variable of `kls` in a line #11:
|
You can customize these bindings or add extra bindings in `KEY_BINDINGS` variable of `kls` in a line #15:
|
||||||
|
|
||||||
- `Ctrl+y` - get yaml of resource
|
- `Ctrl+y` - get **Y**aml of resource
|
||||||
- `Ctrl+d` - describe resource
|
- `Ctrl+d` - **D**escribe resource
|
||||||
- `Ctrl+e` - edit resource
|
- `Ctrl+e` - **E**dit resource
|
||||||
- `Ctrl+l` - logs of pod
|
- `Ctrl+l` - **L**ogs of pod
|
||||||
- `Ctrl+x` - exec into pod
|
- `Ctrl+x` - e**X**ec into pod
|
||||||
- `Ctrl+n` - network debug of pod (with nicolaka/netshoot container attached)
|
- `Ctrl+n` - **N**etwork debug of pod (with nicolaka/netshoot container attached)
|
||||||
|
- `Ctrl+a` - **A**ccess logs of istio sidecar
|
||||||
|
- `Ctrl+p` - exec into istio-**P**roxy sidecar
|
||||||
|
- `Ctrl+r` - **R**eveal base64 secret values
|
||||||
- `delete` - delete resource
|
- `delete` - delete resource
|
||||||
- `Ctrl+a` - access logs of istio sidecar
|
|
||||||
- `Ctrl+p` - exec into istio sidecar
|
|
||||||
- `Ctrl+r` - reveal base64 secret values
|
|
||||||
- `Ctrl+x` - exec into pod
|
|
||||||
|
|
||||||
### Other:
|
### Other:
|
||||||
|
|
||||||
|
@ -45,7 +44,7 @@ You can customize these bindings or add extra bindings in `KEY_BINDINGS` variabl
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Install `batcat`:
|
Install `batcat` and other dependencies:
|
||||||
|
|
||||||
```
|
```
|
||||||
sudo apt install bat lnav yq -y
|
sudo apt install bat lnav yq -y
|
||||||
|
|
34
kls
34
kls
|
@ -5,6 +5,10 @@ import curses
|
||||||
import curses.ascii
|
import curses.ascii
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
|
|
||||||
|
SCREEN: curses.window = curses.initscr()
|
||||||
|
|
||||||
|
|
||||||
# ****************************** #
|
# ****************************** #
|
||||||
# START OF CONFIGURATION SECTION #
|
# START OF CONFIGURATION SECTION #
|
||||||
# ****************************** #
|
# ****************************** #
|
||||||
|
@ -62,7 +66,17 @@ TOP_API_RESOURCES: list[str] = [
|
||||||
QUERY_API_RESOURCES: bool = False # Should we merge TOP_API_RESOURCES with all other api resources from cluster?
|
QUERY_API_RESOURCES: bool = False # Should we merge TOP_API_RESOURCES with all other api resources from cluster?
|
||||||
BATCAT_STYLE: str = " --paging always --style numbers" # style of batcat
|
BATCAT_STYLE: str = " --paging always --style numbers" # style of batcat
|
||||||
MOUSE_ENABLED: bool = False
|
MOUSE_ENABLED: bool = False
|
||||||
|
WIDTH: int = curses.COLS
|
||||||
|
WIDTH_UNIT: int = int(WIDTH / 8)
|
||||||
|
NAMESPACES_WIDTH = int(WIDTH_UNIT * 1.5)
|
||||||
|
API_RESOURCES_WIDTH = int(WIDTH_UNIT * 1.5)
|
||||||
|
RESOURCES_WIDTH = WIDTH - (API_RESOURCES_WIDTH + NAMESPACES_WIDTH)
|
||||||
|
HEADER_HEIGHT: int = 4
|
||||||
|
FOOTER_HEIGHT: int = 3
|
||||||
|
ROWS_HEIGHT: int = curses.LINES - HEADER_HEIGHT - FOOTER_HEIGHT - 3
|
||||||
|
# Generate HELP_TEXT from KEY_BINDINGS
|
||||||
|
HELP_TEXT: str = ", ".join(f"{key}: {binding['description']}" for key, binding in KEY_BINDINGS.items())
|
||||||
|
HELP_TEXT += ", /: filter mode, Esc: exit filter mode or kls, arrows/TAB/PgUp/PgDn: navigation"
|
||||||
|
|
||||||
# **************************** #
|
# **************************** #
|
||||||
# END OF CONFIGURATION SECTION #
|
# END OF CONFIGURATION SECTION #
|
||||||
|
@ -89,7 +103,7 @@ class Menu:
|
||||||
self.rows: list[str] = rows
|
self.rows: list[str] = rows
|
||||||
self.filter: str = ""
|
self.filter: str = ""
|
||||||
self.filter_mode: bool = False
|
self.filter_mode: bool = False
|
||||||
self.filtered_rows: Circularlist[str] = CircularList([x for x in self.rows if self.filter in x])
|
self.filtered_rows: CircularList = CircularList([x for x in self.rows if self.filter in x])
|
||||||
self.visible_rows: Callable[[], list[str]] = lambda: self.filtered_rows[:rows_height]
|
self.visible_rows: Callable[[], list[str]] = lambda: self.filtered_rows[:rows_height]
|
||||||
self.visible_row_index: int = 0
|
self.visible_row_index: int = 0
|
||||||
self.selected_row: Callable[[], Optional[str]] = lambda: self.visible_rows()[
|
self.selected_row: Callable[[], Optional[str]] = lambda: self.visible_rows()[
|
||||||
|
@ -100,16 +114,7 @@ class Menu:
|
||||||
self.win: curses.window = curses.newwin(curses.LINES - FOOTER_HEIGHT, self.width, 0, self.begin_x)
|
self.win: curses.window = curses.newwin(curses.LINES - FOOTER_HEIGHT, self.width, 0, self.begin_x)
|
||||||
|
|
||||||
|
|
||||||
# Generate HELP_TEXT from KEY_BINDINGS
|
|
||||||
HELP_TEXT: str = ", ".join(f"{key}: {binding['description']}" for key, binding in KEY_BINDINGS.items())
|
|
||||||
HELP_TEXT += ", /: filter mode, Esc: exit filter mode or kls, arrows/TAB/PgUp/PgDn: navigation"
|
|
||||||
|
|
||||||
# Global variables
|
# Global variables
|
||||||
SCREEN: curses.window = curses.initscr()
|
|
||||||
HEADER_HEIGHT: int = 4
|
|
||||||
FOOTER_HEIGHT: int = 3
|
|
||||||
ROWS_HEIGHT: int = curses.LINES - HEADER_HEIGHT - FOOTER_HEIGHT - 3
|
|
||||||
WIDTH: int = curses.COLS
|
|
||||||
THIRD_MENU_LOCK: asyncio.Lock = asyncio.Lock()
|
THIRD_MENU_LOCK: asyncio.Lock = asyncio.Lock()
|
||||||
THIRD_MENU_TASK: Optional[asyncio.Task] = None
|
THIRD_MENU_TASK: Optional[asyncio.Task] = None
|
||||||
menus: list[Menu] = []
|
menus: list[Menu] = []
|
||||||
|
@ -377,7 +382,6 @@ async def init_menus() -> None:
|
||||||
dict.fromkeys(TOP_API_RESOURCES + api_resources_kubectl)
|
dict.fromkeys(TOP_API_RESOURCES + api_resources_kubectl)
|
||||||
) if QUERY_API_RESOURCES else TOP_API_RESOURCES
|
) if QUERY_API_RESOURCES else TOP_API_RESOURCES
|
||||||
|
|
||||||
width_unit = WIDTH // 8
|
|
||||||
namespaces: list[str] = []
|
namespaces: list[str] = []
|
||||||
try:
|
try:
|
||||||
namespaces = await kubectl_async("config view --minify --output 'jsonpath={..namespace}'")
|
namespaces = await kubectl_async("config view --minify --output 'jsonpath={..namespace}'")
|
||||||
|
@ -396,9 +400,9 @@ async def init_menus() -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
menus = [
|
menus = [
|
||||||
Menu("Namespaces", namespaces, 0, width_unit * 1.5, ROWS_HEIGHT),
|
Menu("Namespaces", namespaces, 0, NAMESPACES_WIDTH, ROWS_HEIGHT),
|
||||||
Menu("API resources", api_resources, width_unit * 1.5, width_unit * 1.5, ROWS_HEIGHT),
|
Menu("API resources", api_resources, NAMESPACES_WIDTH, API_RESOURCES_WIDTH, ROWS_HEIGHT),
|
||||||
Menu("Resources", [], width_unit * 3, WIDTH - width_unit * 3, ROWS_HEIGHT)
|
Menu("Resources", [], NAMESPACES_WIDTH + API_RESOURCES_WIDTH, RESOURCES_WIDTH, ROWS_HEIGHT)
|
||||||
]
|
]
|
||||||
selected_menu = menus[0]
|
selected_menu = menus[0]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue