about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/gui/ansi.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/ranger/gui/ansi.py b/ranger/gui/ansi.py
index 802df04d..5fce557a 100644
--- a/ranger/gui/ansi.py
+++ b/ranger/gui/ansi.py
@@ -101,6 +101,8 @@ def char_slice(ansi_text, start, length):
 	'\\x1b[0mnormal'
 	>>> char_slice(test_string, 9, 100)
 	'\\x1b[31mar\\x1b[0mnormal'
+	>>> char_slice(test_string, 9, 4)
+	'\\x1b[31mar\\x1b[0mno'
 	"""
 	chunks = []
 	last_color = ""
@@ -115,6 +117,11 @@ def char_slice(ansi_text, start, length):
 				chunks.append(last_color)
 				chunks.append(chunk[start-pos:start-pos+length])
 			pos += len(chunk)
+		elif pos + len(chunk) - start > length:
+			if chunk[:start-pos+length]:
+				chunks.append(last_color)
+				chunks.append(chunk[:start-pos+length])
+			pos += len(chunk)
 		else:
 			chunks.append(last_color)
 			chunks.append(chunk)