Merge pull request #479 from jupart/master

Wrap text in submission page PAGER output
This commit is contained in:
Michael Lazar
2017-11-16 13:41:29 -05:00
committed by GitHub
2 changed files with 11 additions and 4 deletions

View File

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

View File

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