Skip to content

Commit 8ee8e31

Browse files
daniel-chang-wncjserv
authored andcommitted
Add preview in menuconfig for user.
1 parent cb0d41f commit 8ee8e31

File tree

1 file changed

+80
-1
lines changed

1 file changed

+80
-1
lines changed

menuconfig.py

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@
262262
[Space/Enter] Toggle/enter [ESC] Leave menu [S] Save
263263
[O] Load [?] Symbol info [/] Jump to symbol
264264
[F] Toggle show-help mode [C] Toggle show-name mode [A] Toggle show-all mode
265-
[Q] Quit (prompts for save) [D] Save minimal config (advanced)
265+
[P] Preview
266+
[Q] Quit (prompts for save) [D] Save minimal config (advanced)
266267
"""[1:-1].split("\n")
267268

268269
# Lines of help text shown at the bottom of the information dialog
@@ -934,6 +935,9 @@ def _menuconfig(stdscr):
934935
elif c in ("a", "A"):
935936
_toggle_show_all()
936937

938+
elif c in ("p","P"):
939+
_preview_dialog(None, _kconf.write_config_to_string(), False)
940+
937941
elif c in ("q", "Q"):
938942
res = _quit_dialog()
939943
if res:
@@ -2381,6 +2385,81 @@ def _draw_jump_to_dialog(edit_box, matches_win, bot_sep_win, help_win,
23812385

23822386
edit_box.noutrefresh()
23832387

2388+
def _preview_dialog(node, string, from_jump_to_dialog):
2389+
2390+
top_line_win = _styled_win("separator")
2391+
2392+
# Text display
2393+
text_win = _styled_win("text")
2394+
text_win.keypad(True)
2395+
2396+
# Bottom separator, with arrows pointing down
2397+
bot_sep_win = _styled_win("separator")
2398+
2399+
# Help window with keys at the bottom
2400+
help_win = _styled_win("help")
2401+
2402+
# Give windows their initial size
2403+
_resize_info_dialog(top_line_win, text_win, bot_sep_win, help_win)
2404+
2405+
2406+
# Get lines of help text
2407+
lines = string.split("\n")
2408+
2409+
2410+
# Index of first row in 'lines' to show
2411+
scroll = 0
2412+
2413+
while True:
2414+
_draw_info_dialog(node, lines, scroll, top_line_win, text_win,
2415+
bot_sep_win, help_win)
2416+
curses.doupdate()
2417+
2418+
2419+
c = _getch_compat(text_win)
2420+
2421+
if c == curses.KEY_RESIZE:
2422+
_resize_info_dialog(top_line_win, text_win, bot_sep_win, help_win)
2423+
2424+
elif c in (curses.KEY_DOWN, "j", "J"):
2425+
if scroll < _max_scroll(lines, text_win):
2426+
scroll += 1
2427+
2428+
elif c in (curses.KEY_NPAGE, "\x04"): # Page Down/Ctrl-D
2429+
scroll = min(scroll + _PG_JUMP, _max_scroll(lines, text_win))
2430+
2431+
elif c in (curses.KEY_PPAGE, "\x15"): # Page Up/Ctrl-U
2432+
scroll = max(scroll - _PG_JUMP, 0)
2433+
2434+
elif c in (curses.KEY_END, "G"):
2435+
scroll = _max_scroll(lines, text_win)
2436+
2437+
elif c in (curses.KEY_HOME, "g"):
2438+
scroll = 0
2439+
2440+
elif c in (curses.KEY_UP, "k", "K"):
2441+
if scroll > 0:
2442+
scroll -= 1
2443+
2444+
elif c == "/":
2445+
# Support starting a search from within the information dialog
2446+
2447+
if from_jump_to_dialog:
2448+
return # Avoid recursion
2449+
2450+
if _jump_to_dialog():
2451+
return # Jumped to a symbol. Cancel the information dialog.
2452+
2453+
# Stay in the information dialog if the jump-to dialog was
2454+
# canceled. Resize it in case the terminal was resized while the
2455+
# fullscreen jump-to dialog was open.
2456+
_resize_info_dialog(top_line_win, text_win, bot_sep_win, help_win)
2457+
2458+
elif c in (curses.KEY_LEFT, curses.KEY_BACKSPACE, _ERASE_CHAR,
2459+
"\x1B", # \x1B = ESC
2460+
"q", "Q", "h", "H"):
2461+
2462+
return
23842463

23852464
def _info_dialog(node, from_jump_to_dialog):
23862465
# Shows a fullscreen window with information about 'node'.

0 commit comments

Comments
 (0)