Wrap text in submission page PAGER output

This commit is contained in:
jupart
2017-11-13 09:46:31 -05:00
parent 1cb2ee16ec
commit a30fdbd1b3
2 changed files with 14 additions and 4 deletions

View File

@@ -155,13 +155,15 @@ class SubmissionPage(Page):
Open the selected item with the system's pager Open the selected item with the system's pager
""" """
n_rows, n_cols = self.term.stdscr.getmaxyx()
data = self.get_selected_item() data = self.get_selected_item()
if data['type'] == 'Submission': if data['type'] == 'Submission':
text = '\n\n'.join((data['permalink'], data['text'])) text = '\n\n'.join((data['permalink'], data['text']))
self.term.open_pager(text) self.term.open_pager(text, wrap=n_cols)
elif data['type'] == 'Comment': elif data['type'] == 'Comment':
text = '\n\n'.join((data['permalink'], data['body'])) text = '\n\n'.join((data['permalink'], data['body']))
self.term.open_pager(text) self.term.open_pager(text, wrap=n_cols)
else: else:
self.term.flash() self.term.flash()

View File

@@ -20,7 +20,7 @@ from tempfile import NamedTemporaryFile
import six import six
from kitchen.text.display import textual_width_chop from kitchen.text.display import textual_width_chop
from . import exceptions, mime_parsers from . import exceptions, mime_parsers, content
from .theme import Theme from .theme import Theme
from .objects import LoadScreen from .objects import LoadScreen
@@ -552,7 +552,7 @@ class Terminal(object):
with self.suspend(): with self.suspend():
webbrowser.open_new_tab(url) webbrowser.open_new_tab(url)
def open_pager(self, data): def open_pager(self, data, wrap=False):
""" """
View a long block of text using the system's default pager. View a long block of text using the system's default pager.
@@ -561,6 +561,14 @@ class Terminal(object):
pager = os.getenv('PAGER') or 'less' pager = os.getenv('PAGER') or 'less'
command = shlex.split(pager) command = shlex.split(pager)
if wrap:
data_lines = content.Content.wrap_text(data, wrap)
data = ''
for line in data_lines:
data += line + '\n'
try: try:
with self.suspend(): with self.suspend():
_logger.debug('Running command: %s', command) _logger.debug('Running command: %s', command)