sync with 1.10.0
This commit is contained in:
68
rtv/page.py
68
rtv/page.py
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import curses
|
||||
@@ -10,6 +11,8 @@ from kitchen.text.display import textual_width
|
||||
|
||||
from . import docs
|
||||
from .objects import Controller, Color, Command
|
||||
from .exceptions import TemporaryFileError
|
||||
from .__version__ import __version__
|
||||
|
||||
|
||||
def logged_in(f):
|
||||
@@ -234,16 +237,19 @@ class Page(object):
|
||||
self.term.flash()
|
||||
return
|
||||
|
||||
text = self.term.open_editor(info)
|
||||
if text == content:
|
||||
self.term.show_notification('Canceled')
|
||||
return
|
||||
with self.term.open_editor(info) as text:
|
||||
if text == content:
|
||||
self.term.show_notification('Canceled')
|
||||
return
|
||||
|
||||
with self.term.loader('Editing', delay=0):
|
||||
data['object'].edit(text)
|
||||
time.sleep(2.0)
|
||||
if self.term.loader.exception is None:
|
||||
self.refresh_content()
|
||||
with self.term.loader('Editing', delay=0):
|
||||
data['object'].edit(text)
|
||||
time.sleep(2.0)
|
||||
|
||||
if self.term.loader.exception is None:
|
||||
self.refresh_content()
|
||||
else:
|
||||
raise TemporaryFileError()
|
||||
|
||||
@PageController.register(Command('INBOX'))
|
||||
@logged_in
|
||||
@@ -291,9 +297,22 @@ class Page(object):
|
||||
ch, attr = str(' '), curses.A_REVERSE | curses.A_BOLD | Color.CYAN
|
||||
window.bkgd(ch, attr)
|
||||
|
||||
sub_name = self.content.name.replace('/r/front', 'Front Page')
|
||||
sub_name = self.content.name
|
||||
sub_name = sub_name.replace('/r/front', 'Front Page')
|
||||
sub_name = sub_name.replace('/r/me', 'My Submissions')
|
||||
self.term.add_line(window, sub_name, 0, 0)
|
||||
|
||||
# Set the terminal title
|
||||
if len(sub_name) > 50:
|
||||
title = sub_name.strip('/').rsplit('/', 1)[1].replace('_', ' ')
|
||||
else:
|
||||
title = sub_name
|
||||
|
||||
if os.getenv('DISPLAY'):
|
||||
title += ' - rtv {0}'.format(__version__)
|
||||
sys.stdout.write('\x1b]2;{0}\x07'.format(title))
|
||||
sys.stdout.flush()
|
||||
|
||||
if self.reddit.user is not None:
|
||||
# The starting position of the name depends on if we're converting
|
||||
# to ascii or not
|
||||
@@ -344,29 +363,46 @@ class Page(object):
|
||||
# If not inverted, align the first submission with the top and draw
|
||||
# downwards. If inverted, align the first submission with the bottom
|
||||
# and draw upwards.
|
||||
cancel_inverted = True
|
||||
current_row = (win_n_rows - 1) if inverted else 0
|
||||
available_rows = (win_n_rows - 1) if inverted else win_n_rows
|
||||
top_item_height = None if inverted else self.nav.top_item_height
|
||||
for data in self.content.iterate(page_index, step, win_n_cols - 2):
|
||||
subwin_n_rows = min(available_rows, data['n_rows'])
|
||||
subwin_inverted = inverted
|
||||
if top_item_height is not None:
|
||||
# Special case: draw the page as non-inverted, except for the
|
||||
# top element. This element will be drawn as inverted with a
|
||||
# restricted height
|
||||
subwin_n_rows = min(subwin_n_rows, top_item_height)
|
||||
subwin_inverted = True
|
||||
top_item_height = None
|
||||
subwin_n_cols = win_n_cols - data['offset']
|
||||
start = current_row - subwin_n_rows if inverted else current_row
|
||||
subwindow = window.derwin(
|
||||
subwin_n_rows, subwin_n_cols, start, data['offset'])
|
||||
attr = self._draw_item(subwindow, data, inverted)
|
||||
attr = self._draw_item(subwindow, data, subwin_inverted)
|
||||
self._subwindows.append((subwindow, attr))
|
||||
available_rows -= (subwin_n_rows + 1) # Add one for the blank line
|
||||
current_row += step * (subwin_n_rows + 1)
|
||||
if available_rows <= 0:
|
||||
# Indicate the page is full and we can keep the inverted screen.
|
||||
cancel_inverted = False
|
||||
break
|
||||
else:
|
||||
# If the page is not full we need to make sure that it is NOT
|
||||
|
||||
if len(self._subwindows) == 1:
|
||||
# Never draw inverted if only one subwindow. The top of the
|
||||
# subwindow should always be aligned with the top of the screen.
|
||||
cancel_inverted = True
|
||||
|
||||
if cancel_inverted and self.nav.inverted:
|
||||
# In some cases we need to make sure that the screen is NOT
|
||||
# inverted. Unfortunately, this currently means drawing the whole
|
||||
# page over again. Could not think of a better way to pre-determine
|
||||
# if the content will fill up the page, given that it is dependent
|
||||
# on the size of the terminal.
|
||||
if self.nav.inverted:
|
||||
self.nav.flip((len(self._subwindows) - 1))
|
||||
self._draw_content()
|
||||
self.nav.flip((len(self._subwindows) - 1))
|
||||
self._draw_content()
|
||||
|
||||
self._row = n_rows
|
||||
|
||||
|
||||
Reference in New Issue
Block a user