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

Handle colours in menu item names #45

Merged
merged 2 commits into from
Jan 8, 2022
Merged
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
7 changes: 6 additions & 1 deletion consolemenu/console_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,12 @@ def process_user_input(self):
"""
Gets the next single character and decides what to do with it
"""
user_input = self.get_input()

try:
user_input = self.get_input()
except EOFError:
self.should_exit = True
return

try:
num = int(user_input)
Expand Down
7 changes: 4 additions & 3 deletions consolemenu/menu_component.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import textwrap
import ansiwrap

from consolemenu.format import MenuStyle

Expand Down Expand Up @@ -187,11 +187,12 @@ def _alignment_char(align):
return '<'

def _format_content(self, content='', align='left'):
invisible_chars = len(content) - ansiwrap.ansilen(content)
return '{lp}{text:{al}{width}}{rp}'.format(lp=' ' * self.padding.left,
rp=' ' * self.padding.right,
text=content, al=self._alignment_char(align),
width=(self.calculate_border_width() - self.padding.left -
self.padding.right - 2))
self.padding.right - 2 + invisible_chars))


class MenuHeader(MenuComponent):
Expand Down Expand Up @@ -247,7 +248,7 @@ def generate(self):
for x in range(0, self.padding.top):
yield self.row()
if self.text is not None and self.text != '':
for line in textwrap.wrap(self.text, width=self.calculate_content_width()):
for line in ansiwrap.wrap(self.text, width=self.calculate_content_width()):
yield self.row(content=line, align=self.text_align)
for x in range(0, self.padding.bottom):
yield self.row()
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pycodestyle>=2.3.1
pytest>=2.8.7
six
mock
ansiwrap
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def read(*filenames, **kwargs):
description='A simple console menu system',
long_description=read("README.rst", "CHANGELOG.rst"),
packages=find_packages(),
install_requires=['six'],
install_requires=['six', 'ansiwrap'],
# setup_requires=['pytest-runner'],
# tests_require=['tox'],
# cmdclass={'test': Tox},
Expand Down