# Copyright (C) 2009, 2010 Roman Zimbelmann <romanz@lavabit.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
The pager displays text and allows you to scroll inside it.
"""
import re
from . import Widget
from ranger.container.commandlist import CommandList
from ranger.ext.direction import Direction
BAR_REGEXP = re.compile(r'\|\d+\?\|')
QUOTES_REGEXP = re.compile(r'"[^"]+?"')
SPECIAL_CHARS_REGEXP = re.compile(r'<\w+>|\^[A-Z]')
TITLE_REGEXP = re.compile(r'^\d+\.')
class Pager(Widget):
source = None
source_is_stream = False
old_source = None
old_scroll_begin = 0
old_startx = 0
def __init__(self, win, embedded=False):
Widget.__init__(self, win)
self.embedded = embedded
self.scroll_begin = 0
self.startx = 0
self.markup = None
self.lines = []
self.commandlist = CommandList()
if embedded:
keyfnc = self.settings.keys.initialize_embedded_pager_commands
else:
keyfnc = self.settings.keys.initialize_pager_commands
keyfnc(self.commandlist)
def open(self):
self.scroll_begin = 0
self.markup = None
self.startx = 0
self.need_redraw = True
def close(self):
if self.source and self.source_is_stream:
self.source.close()
def finalize(self):
self.fm.ui.win.move(self.y, self.x)
def draw(self):
if self.old_source != self.source:
self.old_source = self.source
self.need_redraw = True
if self.old_scroll_begin != self.scroll_begin or \
self.old_startx != self.startx:
self.old_startx = self.startx
self.old_scroll_begin = self.