Skip to content

Commit

Permalink
Merge 2098c7b into 83b571f
Browse files Browse the repository at this point in the history
  • Loading branch information
AuHau committed May 24, 2019
2 parents 83b571f + 2098c7b commit 804f866
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/checkbox_long.py
Expand Up @@ -9,7 +9,7 @@
questions = [
inquirer.Checkbox('interests',
message="What are you interested in?",
choices=['Choice %s' % i for i in range(20)],
choices=['Choice %s' % i for i in range(40)],
default=['Choice 2', 'Choice 10']),
]

Expand Down
14 changes: 7 additions & 7 deletions inquirer/render/console/_checkbox.py
Expand Up @@ -35,17 +35,16 @@ def get_options(self):
else:
cchoices = choices

ending_milestone = max(len(choices) - half_options, half_options + 1)
is_in_beginning = self.current <= half_options
is_in_middle = half_options < self.current < len(choices) - half_options # noqa
is_in_end = self.current >= len(choices) - half_options
is_in_middle = half_options < self.current < ending_milestone
is_in_end = self.current >= ending_milestone

for index, choice in enumerate(cchoices):

# if index in self.selection:
if (is_in_middle and
self.current - half_options + index in self.selection) \
or (is_in_beginning and index in self.selection) \
or (is_in_end and len(choices) - MAX_OPTIONS_DISPLAYED_AT_ONCE + index in self.selection): # noqa
or (is_in_end and index + max(len(choices) - MAX_OPTIONS_DISPLAYED_AT_ONCE, 0) in self.selection): # noqa

symbol = self.theme.Checkbox.selected_icon
color = self.theme.Checkbox.selected_color
Expand All @@ -54,9 +53,10 @@ def get_options(self):
color = self.theme.Checkbox.unselected_color

selector = ' '
end_index = ending_milestone + index - half_options - 1
if (is_in_middle and index == half_options) \
or (is_in_beginning and index == self.current) \
or (is_in_end and index == half_options + self.current % MAX_OPTIONS_DISPLAYED_AT_ONCE): # noqa
or (is_in_beginning and index == self.current) \
or (is_in_end and end_index == self.current):

selector = self.theme.Checkbox.selection_icon
color = self.theme.Checkbox.selection_color
Expand Down
10 changes: 6 additions & 4 deletions inquirer/render/console/_list.py
Expand Up @@ -33,14 +33,16 @@ def get_options(self):
else:
cchoices = choices

ending_milestone = max(len(choices) - half_options, half_options + 1)
is_in_beginning = self.current <= half_options
is_in_middle = half_options < self.current < len(choices) - half_options # noqa
is_in_end = self.current >= len(choices) - half_options
is_in_middle = half_options < self.current < ending_milestone
is_in_end = self.current >= ending_milestone

for index, choice in enumerate(cchoices):
end_index = ending_milestone + index - half_options - 1
if (is_in_middle and index == half_options) \
or (is_in_beginning and index == self.current) \
or (is_in_end and index == half_options + self.current % MAX_OPTIONS_DISPLAYED_AT_ONCE): # noqa
or (is_in_beginning and index == self.current) \
or (is_in_end and end_index == self.current):

color = self.theme.List.selection_color
symbol = self.theme.List.selection_cursor
Expand Down

0 comments on commit 804f866

Please sign in to comment.