summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/actions.py1
-rw-r--r--ranger/colorschemes/default.py17
-rw-r--r--ranger/gui/colorscheme.py6
-rw-r--r--ranger/gui/widgets/pager.py48
-rw-r--r--ranger/help/index.py6
5 files changed, 69 insertions, 9 deletions
diff --git a/ranger/actions.py b/ranger/actions.py
index bf9a557e..7269abc4 100644
--- a/ranger/actions.py
+++ b/ranger/actions.py
@@ -198,6 +198,7 @@ class Actions(EnvironmentAware, SettingsAware):
 			help_text = get_help(topic)
 
 		pager = self.ui.open_pager()
+		pager.markup = 'help'
 		lines = help_text.split('\n')
 		pager.set_source(lines)
 
diff --git a/ranger/colorschemes/default.py b/ranger/colorschemes/default.py
index 4da2d105..aa5299b9 100644
--- a/ranger/colorschemes/default.py
+++ b/ranger/colorschemes/default.py
@@ -80,6 +80,23 @@ class Default(ColorScheme):
 					attr |= bold
 					fg = red
 
+		if context.in_pager or context.help_markup:
+			if context.seperator:
+				fg = red
+			elif context.link:
+				fg = cyan
+			elif context.bars:
+				fg = black
+				attr |= bold
+			elif context.quotes or context.text:
+				fg = magenta
+			elif context.key:
+				fg = green
+			elif context.special:
+				fg = cyan
+			elif context.title:
+				attr |= bold
+
 		if context.text:
 			if context.highlight:
 				attr |= reverse
diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py
index 54d9571e..967a4fdd 100644
--- a/ranger/gui/colorscheme.py
+++ b/ranger/gui/colorscheme.py
@@ -1,6 +1,6 @@
 CONTEXT_KEYS = [ 'reset', 'error',
 		'in_browser', 'in_statusbar', 'in_titlebar', 'in_console',
-		'in_notify', 'in_taskview',
+		'in_pager', 'in_taskview',
 		'directory', 'file', 'hostname',
 		'executable', 'media', 'link',
 		'video', 'audio', 'image', 'media', 'document', 'container',
@@ -9,7 +9,9 @@ CONTEXT_KEYS = [ 'reset', 'error',
 		'space', 'permissions', 'owner', 'group', 'mtime', 'nlink',
 		'scroll', 'all', 'bot', 'top', 'percentage',
 		'marked', 'tagged', 'tag_marker',
-		'title', 'text', 'highlight',
+		'help_markup',
+		'seperator', 'key', 'special',
+		'title', 'text', 'highlight', 'bars', 'quotes',
 		'keybuffer']
 
 # colorscheme specification:
diff --git a/ranger/gui/widgets/pager.py b/ranger/gui/widgets/pager.py
index 48492573..9886f65a 100644
--- a/ranger/gui/widgets/pager.py
+++ b/ranger/gui/widgets/pager.py
@@ -1,9 +1,16 @@
 """
 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.move import move_between
+from ranger import log
+
+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
@@ -17,6 +24,7 @@ class Pager(Widget):
 		self.embedded = embedded
 		self.scroll_begin = 0
 		self.startx = 0
+		self.markup = None
 		self.lines = []
 
 		self.commandlist = CommandList()
@@ -30,6 +38,7 @@ class Pager(Widget):
 	
 	def open(self):
 		self.scroll_begin = 0
+		self.markup = None
 		self.startx = 0
 		self.need_redraw = True
 	
@@ -54,12 +63,43 @@ class Pager(Widget):
 					starty=self.scroll_begin, startx=self.startx)
 
 			for line, i in zip(line_gen, range(self.hei)):
-				try:
-					self.addstr(i, 0, line)
-				except TypeError:
-					pass
+				self._draw_line(i, line)
 			self.need_redraw = False
 	
+	def _draw_line(self, i, line):
+		if self.markup is None:
+			self.addstr(i, 0, line)
+		elif self.markup is 'help':
+			self.addstr(i, 0, line)
+
+			baseclr = ('in_pager', 'help_markup')
+
+			if line.startswith('===='):
+				self.color_at(i, 0, len(line), 'seperator', *baseclr)
+				return
+
+			if line.startswith('        ') and \
+				len(line) >= 16 and line[15] == ' ':
+				self.color_at(i, 0, 16, 'key', *baseclr)
+
+			for m in BAR_REGEXP.finditer(line):
+				start, length = m.start(), m.end() - m.start()
+				self.color_at(i, start, length, 'bars', *baseclr)
+				self.color_at(i, start + 1, length - 2, 'link', *baseclr)
+
+			for m in QUOTES_REGEXP.finditer(line):
+				start, length = m.start(), m.end() - m.start()
+				self.color_at(i, start, length, 'quotes', *baseclr)
+				self.color_at(i, start + 1, length - 2, 'text', *baseclr)
+
+			for m in SPECIAL_CHARS_REGEXP.finditer(line):
+				start, length = m.start(), m.end() - m.start()
+				self.color_at(i, start, length, 'special', *baseclr)
+
+			if TITLE_REGEXP.match(line):
+				self.color_at(i, 0, -1, 'title', *baseclr)
+
+	
 	def move(self, relative=0, absolute=None, pages=None, narg=None):
 		i = self.scroll_begin
 		if isinstance(absolute, int):
diff --git a/ranger/help/index.py b/ranger/help/index.py
index 6f2850a9..3fc35a3f 100644
--- a/ranger/help/index.py
+++ b/ranger/help/index.py
@@ -5,7 +5,7 @@
                   "j" to go down, "k" to go up, "l" to go right.     j
    Close Ranger:  Use ":q<Enter>" or "Q".
 
-  Specific help:  Type the help key "?" prepended with a number, as in "4?"
+  Specific help:  Type the help key "?" prepended with a number:
 
 	|0?|	This index
 	|1?|	Basic movement and browsing
@@ -17,8 +17,8 @@
 0.1. General information
 
 Whenever you see an annotation like |3?| you can translate it to:
-"This is explained in more detail in chapter 3. Type "3?" to view it."
-
+"This is explained in more detail in chapter 3. Type 3? to view it."
 
+==============================================================================
 """
 # vim:tw=78:sw=4:sts=8:ts=8:ft=help