Merge pull request #479 from jupart/master
Wrap text in submission page PAGER output
This commit is contained in:
@@ -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()
|
||||||
|
|
||||||
|
|||||||
@@ -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=None):
|
||||||
"""
|
"""
|
||||||
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,11 @@ 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 = '\n'.join(data_lines)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with self.suspend():
|
with self.suspend():
|
||||||
_logger.debug('Running command: %s', command)
|
_logger.debug('Running command: %s', command)
|
||||||
|
|||||||
Reference in New Issue
Block a user