Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Config representation and preview #127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions kconfiglib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,15 @@ def write_config(self, filename=None, header=None, save_old=True,

return "Configuration saved to '{}'".format(filename)

def write_config_to_string(self, header=None, verbose=None):

if verbose is not None:
_warn_verbose_deprecated("write_string")

contents = self._config_contents(header)

return contents

def _config_contents(self, header):
# write_config() helper. Returns the contents to write as a string,
# with 'header' or KCONFIG_CONFIG_HEADER at the beginning.
Expand Down
81 changes: 80 additions & 1 deletion menuconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@
[Space/Enter] Toggle/enter [ESC] Leave menu [S] Save
[O] Load [?] Symbol info [/] Jump to symbol
[F] Toggle show-help mode [C] Toggle show-name mode [A] Toggle show-all mode
[Q] Quit (prompts for save) [D] Save minimal config (advanced)
[P] Preview
[Q] Quit (prompts for save) [D] Save minimal config (advanced)
"""[1:-1].split("\n")

# Lines of help text shown at the bottom of the information dialog
Expand Down Expand Up @@ -929,6 +930,9 @@ def _menuconfig(stdscr):
elif c in ("a", "A"):
_toggle_show_all()

elif c in ("p","P"):
_preview_dialog(None, _kconf.write_config_to_string(), False)

elif c in ("q", "Q"):
res = _quit_dialog()
if res:
Expand Down Expand Up @@ -2363,6 +2367,81 @@ def _draw_jump_to_dialog(edit_box, matches_win, bot_sep_win, help_win,

edit_box.noutrefresh()

def _preview_dialog(node, string, from_jump_to_dialog):

top_line_win = _styled_win("separator")

# Text display
text_win = _styled_win("text")
text_win.keypad(True)

# Bottom separator, with arrows pointing down
bot_sep_win = _styled_win("separator")

# Help window with keys at the bottom
help_win = _styled_win("help")

# Give windows their initial size
_resize_info_dialog(top_line_win, text_win, bot_sep_win, help_win)


# Get lines of help text
lines = string.split("\n")


# Index of first row in 'lines' to show
scroll = 0

while True:
_draw_info_dialog(node, lines, scroll, top_line_win, text_win,
bot_sep_win, help_win)
curses.doupdate()


c = _getch_compat(text_win)

if c == curses.KEY_RESIZE:
_resize_info_dialog(top_line_win, text_win, bot_sep_win, help_win)

elif c in (curses.KEY_DOWN, "j", "J"):
if scroll < _max_scroll(lines, text_win):
scroll += 1

elif c in (curses.KEY_NPAGE, "\x04"): # Page Down/Ctrl-D
scroll = min(scroll + _PG_JUMP, _max_scroll(lines, text_win))

elif c in (curses.KEY_PPAGE, "\x15"): # Page Up/Ctrl-U
scroll = max(scroll - _PG_JUMP, 0)

elif c in (curses.KEY_END, "G"):
scroll = _max_scroll(lines, text_win)

elif c in (curses.KEY_HOME, "g"):
scroll = 0

elif c in (curses.KEY_UP, "k", "K"):
if scroll > 0:
scroll -= 1

elif c == "/":
# Support starting a search from within the information dialog

if from_jump_to_dialog:
return # Avoid recursion

if _jump_to_dialog():
return # Jumped to a symbol. Cancel the information dialog.

# Stay in the information dialog if the jump-to dialog was
# canceled. Resize it in case the terminal was resized while the
# fullscreen jump-to dialog was open.
_resize_info_dialog(top_line_win, text_win, bot_sep_win, help_win)

elif c in (curses.KEY_LEFT, curses.KEY_BACKSPACE, _ERASE_CHAR,
"\x1B", # \x1B = ESC
"q", "Q", "h", "H"):

return

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