Skip to content

Commit

Permalink
Merge pull request #181 from asdil12/rev
Browse files Browse the repository at this point in the history
Add config option to reverse option order
  • Loading branch information
asdil12 committed Jun 11, 2024
2 parents a4f0726 + 3442c7d commit 61e5459
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions opi.default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
backend = zypp
use_releasever_var = true
new_repo_auto_refresh = true
list_in_reverse = false
4 changes: 3 additions & 1 deletion opi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,8 @@ def ask_for_option(options, question='Pick a number (0 to quit):', option_filter
numbered_option = ' ' * len(number) + numbered_option[terminal_width:]
numbered_options.append(numbered_option)
i += 1
if config.get_key_from_config('list_in_reverse'):
numbered_options.reverse()
text = '\n'.join(numbered_options)
if global_state.arg_non_interactive:
input_string = '1' # default to first option in the list
Expand All @@ -655,7 +657,7 @@ def ask_for_option(options, question='Pick a number (0 to quit):', option_filter
print(text)
input_string = input(question + ' ')
else:
input_string = pager.ask_number_with_pager(text, question)
input_string = pager.ask_number_with_pager(text, question, start_at_bottom=config.get_key_from_config('list_in_reverse'))

input_string = input_string.strip() or '0'
num = int(input_string) if input_string.isdecimal() else -1
Expand Down
2 changes: 2 additions & 0 deletions opi/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'backend': 'zypp',
'use_releasever_var': True,
'new_repo_auto_refresh': True,
'list_in_reverse': False,
}

class ConfigError(Exception):
Expand All @@ -24,5 +25,6 @@ def get_key_from_config(key: str):
'backend': ocfg.get('backend'),
'use_releasever_var': ocfg.getboolean('use_releasever_var'),
'new_repo_auto_refresh': ocfg.getboolean('new_repo_auto_refresh'),
'list_in_reverse': ocfg.getboolean('list_in_reverse'),
})
return config_cache[key]
4 changes: 2 additions & 2 deletions opi/pager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import curses

def ask_number_with_pager(text, question='Pick a number (0 to quit):'):
def ask_number_with_pager(text, question='Pick a number (0 to quit):', start_at_bottom=False):
try:
stdscr = curses.initscr()
curses.noecho()
Expand All @@ -12,7 +12,7 @@ def ask_number_with_pager(text, question='Pick a number (0 to quit):'):
max_top_line = text_len_lines - (curses.LINES - 2)
scrollarea = curses.newpad(text_len_lines, curses.COLS)
scrollarea.addstr(0, 0, text)
scrollarea_topline_ptr = 0
scrollarea_topline_ptr = max_top_line if start_at_bottom else 0
def ensure_scrollarea_bounds(scrollarea_topline_ptr):
scrollarea_topline_ptr = max(scrollarea_topline_ptr, 0)
scrollarea_topline_ptr = min(scrollarea_topline_ptr, max_top_line)
Expand Down

0 comments on commit 61e5459

Please sign in to comment.