summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2011-10-11 21:54:55 +0200
committerhut <hut@lavabit.com>2011-10-11 21:54:55 +0200
commit138126641ff06a4528ca433328f765d9e0e6de6d (patch)
tree6ed4b8a7edaf9721d1f589ba4a524546bf6c9421
parent11c246d5e1f9be9fc7bfe429e8ce2ff2e972cb05 (diff)
downloadranger-138126641ff06a4528ca433328f765d9e0e6de6d.tar.gz
gui.ansi: simplified
-rw-r--r--ranger/gui/ansi.py25
1 files changed, 13 insertions, 12 deletions
diff --git a/ranger/gui/ansi.py b/ranger/gui/ansi.py
index 5fce557a..5f14f84d 100644
--- a/ranger/gui/ansi.py
+++ b/ranger/gui/ansi.py
@@ -106,26 +106,27 @@ def char_slice(ansi_text, start, length):
 	"""
 	chunks = []
 	last_color = ""
-	pos = 0
+	pos = old_pos = 0
 	for i, chunk in enumerate(split_ansi_from_text(ansi_text)):
 		if i % 2 == 1:
 			last_color = chunk
-		elif pos + len(chunk) < start:
-			pos += len(chunk)  #seek
-		elif pos < start and pos + len(chunk) >= start:
-			if chunk[start-pos:start-pos+length]:
+			continue
+
+		old_pos = pos
+		pos += len(chunk)
+		if pos < start:
+			pass # seek
+		elif old_pos < start and pos >= start:
+			if chunk[start-old_pos:start-old_pos+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(chunk[start-old_pos:start-old_pos+length])
+		elif pos > length + start:
+			if chunk[:start-old_pos+length]:
 				chunks.append(last_color)
-				chunks.append(chunk[:start-pos+length])
-			pos += len(chunk)
+				chunks.append(chunk[:start-old_pos+length])
 		else:
 			chunks.append(last_color)
 			chunks.append(chunk)
-			pos += len(chunk)
 		if pos - start >= length:
 			break
 	return ''.join(chunks)