Lines Matching +full:min +full:- +full:y

3 # Copyright (c) 2018-2019, Nordic Semiconductor ASA and Ulf Magnusson
4 # SPDX-License-Identifier: ISC
10 A curses-based Python 2/3 menuconfig implementation. The interface should feel
19 Ctrl-D/U: Page Down/Page Up
27 character in it in the current menu isn't supported. A jump-to feature for
33 F: Toggle show-help mode, which shows the help text of the currently selected
37 C: Toggle show-name mode, which shows the symbol name before each symbol menu
40 A: Toggle show-all mode, which shows all items, including currently invisible
52 When run in standalone mode, the top-level Kconfig file to load can be passed
53 as a command-line argument. With no argument, it defaults to "Kconfig".
69 alternative, less yellow, more 'make menuconfig'-like color scheme, contributed
72 This is the current list of built-in styles:
73 - default classic Kconfiglib theme with a yellow accent
74 - monochrome colorless theme (uses only bold and standout) attributes,
76 - aquatic blue-tinted style loosely resembling the lxdialog theme
81 - path Top row in the main display, with the menu path
82 - separator Separator lines between windows. Also used for the top line
84 - list List of items, e.g. the main display
85 - selection Style for the selected item
86 - inv-list Like list, but for invisible items. Used in show-all mode.
87 - inv-selection Like selection, but for invisible items. Used in show-all
89 - help Help text windows at the bottom of various fullscreen
91 - show-help Window showing the help text in show-help mode
92 - frame Frame around dialog boxes
93 - body Body of dialog boxes
94 - edit Edit box in pop-up dialogs
95 - jump-edit Edit box in jump-to dialog
96 - text Symbol information text
100 - fg:COLOR Set the foreground/background colors. COLOR can be one of
102 - bg:COLOR magenta, cyan, white and brighter versions, for example,
106 Colors outside the range -1..curses.COLORS-1 (which is
107 terminal-dependent) are ignored (with a warning). The COLOR
114 specified, it defaults to -1, representing the default
119 - bold Use bold text
120 - underline Use underline text
121 - standout Standout text attribute (reverse color)
129 is looked up in the built-in styles list and the style definition is expanded
130 in-place. With this, built-in styles can be used as basis for new styles.
154 - Seamless terminal resizing
156 - No dependencies on *nix, as the 'curses' module is in the Python standard
159 - Unicode text entry
161 - Improved information screen compared to mconf:
163 * Expressions are split up by their top-level &&/|| operands to improve
182 pip install windows-curses
184 See the https://github.com/zephyrproject-rtos/windows-curses repository.
200 installing a package like windows-curses
201 (https://github.com/zephyrproject-rtos/windows-curses) by running this command
204 pip install windows-curses
206 Starting with Kconfiglib 13.0.0, windows-curses is no longer automatically
231 # If True, try to change LC_CTYPE to a UTF-8 locale if it is set to the C
235 # Related PEP: https://www.python.org/dev/peps/pep-0538/
246 # Height of the help window in show-help mode
264 [F] Toggle show-help mode [C] Toggle show-name mode [A] Toggle show-all mode
266 """[1:-1].split("\n")
271 """[1:-1].split("\n")
277 selected symbol. [ESC] aborts the search. Type multiple space-separated
278 strings/regexes to find entries that match all of them. Type Ctrl-F to
280 """[1:-1].split("\n")
292 inv-list=fg:red,bg:white
293 inv-selection=fg:red,bg:blue
295 show-help=list
299 jump-edit=edit
309 inv-list=bold
310 inv-selection=bold,standout
312 show-help=
316 jump-edit=
320 # Blue-tinted style loosely resembling lxdialog
359 # Converts an 888 RGB color to a 3-tuple (nice in that it's hashable)
360 # representing the closest xterm 256-color 6x6x6 color cube color.
362 # The xterm 256-color extension uses a RGB color palette with components in
363 # the range 0-5 (a 6x6x6 cube). The catch is that the mapping is nonlinear.
371 return tuple(0 if x < 48 else int(round(max(1, (x - 55)/40))) for x in rgb)
381 # Converts an 888 RGB color to the index of an xterm 256-color grayscale
385 # https://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color
387 # https://www.w3.org/TR/AERT/#color-contrast
392 index = int(round((luma - 8)/10))
394 # Clamp the index to 0-23, corresponding to 232-255
395 return max(0, min(index, 23))
401 return 3*(10*index + 8,) # Returns a 3-tuple
411 # ncurses is palette-based, so we need to overwrite palette entries to make
414 # The colors from 0 to 15 are user-defined, and there's no way to query
430 # Map each RGB component from the range 0-255 to the range 0-1000, which is
440 # 256-color palette (but that might not be 'num', if we're redefining
443 # - _alloc_rgb() won't touch the first 16 colors or any (hypothetical)
444 # colors above 255, so we can always return them as-is
446 # - If the terminal doesn't support changing color definitions, or if
448 # can be returned as-is
453 # _alloc_rgb() might redefine colors, so emulate the xterm 256-color
458 num -= 16
461 return _alloc_rgb(_gray_to_rgb(num - 232))
470 def dist(r1, r2): return sum((x - y)**2 for x, y in zip(r1, r2))
473 # Assume we're dealing with xterm's 256-color extension
476 # Best case -- the terminal supports changing palette entries via
481 # Second best case -- pick between the xterm 256-color extension colors
483 # Closest 6-cube "color" color
490 # color number from the 6-cube index triplet.
496 # Terminal not in xterm 256-color mode. This is probably the best we can
499 best = -1
513 # containing '=' is assumed to be a reference to a built-in style, which is
526 # run _style_to_curses() for non-existing keys as well, so that we
529 _warn("Ignoring non-existent style", key)
543 _warn("Ignoring non-existent style template", sline)
558 if re.match("#[A-Fa-f0-9]{6}", color_def):
572 return -1
574 if not -1 <= color_num < curses.COLORS:
576 "-1..curses.COLORS-1 (-1..{})"
577 .format(color_def, curses.COLORS - 1))
578 return -1
582 fg_color = -1
583 bg_color = -1
593 # A_BOLD tends to produce faint and hard-to-read text on the
596 … # https://blogs.msdn.microsoft.com/commandline/2017/08/02/updating-the-windows-console-colors/
616 # https://github.com/msys2/MINGW-packages/issues/5823, though there
620 # Use the 'default' theme as the base, and add any user-defined style
693 # Nothing visible. Start in show-all mode and try again.
698 print("Empty configuration -- nothing to configure.\n"
731 # curses has been de-initialized.
750 # Returns True if a just-loaded .config file is outdated (would get
785 # show-all mode, this list contains all items in _cur_menu. Otherwise, it
810 # showing the save-and-quit dialog.
846 elif c in (curses.KEY_NPAGE, "\x04"): # Page Down/Ctrl-D
852 elif c in (curses.KEY_PPAGE, "\x15"): # Page Up/Ctrl-U
880 elif c in ("y", "Y"):
911 # The terminal might have been resized while the fullscreen jump-to
923 _set_style(_help_win, "show-help" if _show_help else "help")
947 "(Y)es (N)o (C)ancel",
953 if c == "y":
990 # erasechar() returns a one-byte bytes object on Python 3. This sets
993 _ERASE_CHAR = _ERASE_CHAR.decode("utf-8", "ignore")
1015 # Help window with keys at the bottom. Shows help texts in show-help mode.
1049 menu_win_height = screen_height - help_win_height - 3
1072 if _sel_node_i - _menu_scroll >= menu_win_height:
1073 _menu_scroll = _sel_node_i - menu_win_height + 1
1110 _parent_screen_rows.append(_sel_node_i - _menu_scroll)
1124 # Puts the cursor on the currently selected (y-valued) choice symbol, if
1125 # any. Does nothing if if the choice has no selection (is not visible/in y
1159 # If we're jumping to a non-empty choice or menu, jump to the first entry
1169 # The node wouldn't be shown. Turn on show-all to show it.
1177 # show-all because the first entry wasn't visible, try turning it off.
1179 # nodes, and is a no-op otherwise.
1184 # If we're jumping to a non-empty choice, jump to the selected symbol, if
1213 screen_row = min(_parent_screen_rows.pop(), _height(_menu_win) - 1)
1214 _menu_scroll = max(_sel_node_i - screen_row, 0)
1228 if _sel_node_i < len(_shown) - 1:
1234 # gives nice and non-jumpy behavior even when
1236 if _sel_node_i >= _menu_scroll + _height(_menu_win) - _SCROLL_OFFSET \
1251 _sel_node_i -= 1
1255 _menu_scroll = max(_menu_scroll - 1, 0)
1264 _sel_node_i = len(_shown) - 1
1278 # Toggles show-all mode on/off. If turning it off would give no visible
1288 old_row = _sel_node_i - _menu_scroll
1294 # Find a good node to select. The selected node might disappear if show-all
1299 for node in _shown[_sel_node_i::-1]:
1311 # No visible nodes at all, meaning show-all was turned off inside
1321 _menu_scroll = max(_sel_node_i - old_row, 0)
1329 _menu_scroll = min(max(_sel_node_i - _height(_menu_win)//2, 0),
1355 0, max((term_width - len(_kconf.mainmenu_text))//2, 0),
1371 min(_menu_scroll + _height(_menu_win), len(_shown))):
1376 # outside show-all mode, which could look confusing/broken. Invisible
1377 # symbols show up outside show-all mode if an invisible symbol has
1382 style = _style["inv-selection" if i == _sel_node_i else "inv-list"]
1384 _safe_addstr(_menu_win, i - _menu_scroll, 0, _node_str(node), style)
1398 # Indicate when show-name/show-help/show-all mode is enabled
1401 enabled_modes.append("show-help (toggle with [F])")
1403 enabled_modes.append("show-name")
1405 enabled_modes.append("show-all")
1408 _safe_addstr(_bot_sep_win, 0, max(term_width - len(s) - 2, 0), s)
1422 for i in range(min(_height(_help_win), len(help_lines))):
1436 # annoying jumpiness in gnome-terminal when reducing the height of the
1443 # Draw the menu path ("(Top) -> Menu -> Submenu -> ...")
1449 # Promptless choices can be entered in show-all mode. Use
1465 menu_path_str = menu_path_str[len(menu_path_str) - term_width:]
1506 # can happen for an m/y-valued symbol with an optional prompt
1529 # Choices can contain non-symbol items (people do all sorts of weird
1560 # Returns True if the node should appear in the menu (outside show-all
1604 # Handles choice symbols for choices in y mode, which are a special
1634 # This will hit for invisible symbols, which appear in show-all mode and
1686 old_row = _sel_node_i - _menu_scroll
1698 _menu_scroll = max(_sel_node_i - old_row, 0)
1731 return _width(win) - 4
1734 hscroll = max(i - edit_width() + 1, 0)
1775 win_height = min(win_height, screen_height)
1780 win_width = min(win_width, screen_width)
1783 win.mvwin((screen_height - win_height)//2,
1784 (screen_width - win_width)//2)
1788 edit_width = _width(win) - 4
1794 _safe_addstr(win, 2, 2, visible_s + " "*(edit_width - len(visible_s)),
1803 _safe_move(win, 2, 2 + i - hscroll)
1839 # Turn on show-all mode if the selected node is not visible after
1975 win_height = min(len(lines) + 4, screen_height)
1976 win_width = min(max(len(line) for line in lines) + 4, screen_width)
1979 win.mvwin((screen_height - win_height)//2,
1980 (screen_width - win_width)//2)
2004 _safe_hline(win, win_height - 1, 0, " ", win_width)
2008 _safe_vline(win, 0, win_width - 1, " ", win_height)
2011 _safe_addstr(win, 0, max((win_width - len(title))//2, 0), title)
2017 # Implements the jump-to dialog, where symbols can be looked up via
2032 edit_box = _styled_win("jump-edit")
2055 if sel_node_i == len(matches) - 1:
2058 if sel_node_i + 1 >= scroll + _height(matches_win) - _SCROLL_OFFSET \
2069 if sel_node_i - 1 < scroll + _SCROLL_OFFSET:
2070 return sel_node_i - 1, max(scroll - 1, 0)
2072 return sel_node_i - 1, scroll
2168 elif c == "\x06": # \x06 = Ctrl-F
2184 elif c in (curses.KEY_NPAGE, "\x04"): # Page Down/Ctrl-D
2190 # Page Up (no Ctrl-U, as it's already used by the edit box)
2196 sel_node_i = len(matches) - 1
2207 _width(edit_box) - 2)
2221 # += is in-place for lists
2252 # Resizes the jump-to dialog to fill the terminal.
2262 matches_win_height = screen_height - help_win_height - 4
2286 if sel_node_i - scroll >= matches_win_height:
2287 return sel_node_i - matches_win_height + 1
2295 edit_width = _width(edit_box) - 2
2305 min(scroll + _height(matches_win), len(matches))):
2318 _safe_addstr(matches_win, i - scroll, 0, node_str,
2368 _safe_move(edit_box, 1, 1 + s_i - hscroll)
2377 # within the jump-to-dialog. In this case, we make '/' from within the
2379 # of the jump-to-dialog.
2419 elif c in (curses.KEY_NPAGE, "\x04"): # Page Down/Ctrl-D
2420 scroll = min(scroll + _PG_JUMP, _max_scroll(lines, text_win))
2422 elif c in (curses.KEY_PPAGE, "\x15"): # Page Up/Ctrl-U
2423 scroll = max(scroll - _PG_JUMP, 0)
2433 scroll -= 1
2444 # Stay in the information dialog if the jump-to dialog was
2446 # fullscreen jump-to dialog was open.
2465 text_win_height = screen_height - help_win_height - 2
2541 _safe_addstr(top_line_win, 0, max((text_win_width - len(title))//2, 0),
2622 s += " - " + sym.name
2650 return "" if sc.direct_dep is _kconf.y else \
2668 s += " - "
2685 if cond is not _kconf.y:
2694 # Returns a string with 'expr' split into its top-level && or || operands,
2728 # value they select/imply 'sym' to (n/m/y).
2738 res += " - {}\n".format(split_expr(si, AND)[0].name)
2745 "Symbols currently y-selecting this symbol:\n")
2747 "Symbols currently m-selecting this symbol:\n")
2749 "Symbols currently n-selecting this symbol (no effect):\n")
2753 "Symbols currently y-implying this symbol:\n")
2755 "Symbols currently m-implying this symbol:\n")
2757 "Symbols currently n-implying this symbol (no effect):\n")
2770 s += (len(s) - 1)*"="
2788 # In the top-level Kconfig file
2792 " -> ".join("{}:{}".format(filename, linenr)
2807 path = " -> " + (node.prompt[0] if node.prompt else
2823 # Show the values of non-constant (non-quoted) symbols that don't look like
2864 return max(0, len(lst) - _height(win))
2893 i -= 1
2899 elif c in (curses.KEY_HOME, "\x01"): # \x01 = CTRL-A
2902 elif c in (curses.KEY_END, "\x05"): # \x05 = CTRL-E
2907 s = s[:i-1] + s[i:]
2908 i -= 1
2913 elif c == "\x17": # \x17 = CTRL-W
2919 elif c == "\x0B": # \x0B = CTRL-K
2922 elif c == "\x15": # \x15 = CTRL-U
2935 hscroll = max(i - _SCROLL_OFFSET, 0)
2936 elif i >= hscroll + width - _SCROLL_OFFSET:
2937 max_scroll = max(len(s) - width + 1, 0)
2938 hscroll = min(i - width + _SCROLL_OFFSET + 1, max_scroll)
2997 # .config), but skip it for choice symbols in choices in y mode,
3006 # choices in y mode
3023 # Print "--->" next to nodes that have menus that can potentially be
3024 # entered. Print "----" if the menu is empty. We don't allow those to be
3027 s += " --->" if _shown_nodes(node) else " ----"
3036 # The 'not node.prompt' case only hits in show-all mode, for promptless
3066 return "" if isinstance(item, Choice) else "-{}-".format(tri_val_str)
3080 # in y mode
3085 # Returns True if the string 's' is a well-formed value for 'sym'.
3089 return True # Anything goes for non-int/hex symbols
3105 _error("{} is outside the range {}-{}"
3121 return "Range: {}-{}".format(low.str_value, high.str_value)
3205 y, x = win.getyx()
3210 y, x, s = args[:3] # pylint: disable=unbalanced-tuple-unpacking
3214 maxlen = _width(win) - x
3222 win.addnstr(y, x, s, maxlen)
3224 win.addnstr(y, x, s, maxlen, attr)
3262 # changing the locale on it. None of the UTF-8 locales below were
3277 for loc in "C.UTF-8", "C.utf8", "UTF-8":