From 11c246d5e1f9be9fc7bfe429e8ce2ff2e972cb05 Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 11 Oct 2011 21:29:48 +0200 Subject: gui.ansi: Added another test case --- ranger/gui/ansi.py | 7 +++++++ 1 file changed, 7 insertions(+) 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) -- cgit 1.4.1-2-gfad0