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)
200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
fn read-cell in: (addr gap-buffer), out: (addr handle cell), trace: (addr trace) {
  # eagerly tokenize everything so that the phases are easier to see in the trace
  var tokens-storage: (stream token 0x10000)
  var tokens/edx: (addr stream token) <- address tokens-storage
  tokenize in, tokens, trace
  var error?/eax: boolean <- has-errors? trace
  compare error?, 0/false
  {
    break-if-=
    return
  }
  # insert more parens based on indentation
  var parenthesized-tokens-storage: (stream token 0x10000)
  var parenthesized-tokens/ecx: (addr stream token) <- address parenthesized-tokens-storage
  parenthesize tokens, parenthesized-tokens, trace
  var error?/eax: boolean <- has-errors? trace
  compare error?, 0/false
  {
    break-if-=
    return
  }
  parse-input parenthesized-tokens, out, trace
  transform-infix out, trace
}