summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/gui/ansi.py55
1 files changed, 45 insertions, 10 deletions
diff --git a/ranger/gui/ansi.py b/ranger/gui/ansi.py
index f328d9df..1b693c7c 100644
--- a/ranger/gui/ansi.py
+++ b/ranger/gui/ansi.py
@@ -10,12 +10,16 @@ from ranger.gui import color
 import re
 
 ansi_re = re.compile('(\x1b' + r'\[\d*(?:;\d+)*?[a-zA-Z])')
+codesplit_re = re.compile('38;5;(\d+);|48;5;(\d+);|(\d*);')
 reset = '\x1b[0m'
 
 def split_ansi_from_text(ansi_text):
 	return ansi_re.split(ansi_text)
 
+# For information on the ANSI codes see
+# githttp://en.wikipedia.org/wiki/ANSI_escape_code
 def text_with_fg_bg_attr(ansi_text):
+	fg, bg, attr = -1, -1, 0
 	for chunk in split_ansi_from_text(ansi_text):
 		if chunk and chunk[0] == '\x1b':
 			if chunk[-1] != 'm':
@@ -25,20 +29,28 @@ def text_with_fg_bg_attr(ansi_text):
 				# XXX I have no test case to determine what should happen here
 				continue
 			attr_args = match.group(1)
-			fg, bg, attr = -1, -1, 0
 
 			# Convert arguments to attributes/colors
-			for arg in attr_args.split(';'):
+			for x256fg, x256bg, arg in codesplit_re.findall(attr_args + ';'):
+				# first handle xterm256 codes
 				try:
-					n = int(arg)
-				except:
-					if arg == '':
-						n = 0
-					else:
+					if len(x256fg) > 0:           # xterm256 foreground
+						fg = int(x256fg)
 						continue
-				if n == 0:
+					elif len(x256bg) > 0:         # xterm256 background
+						bg = int(x256bg)
+						continue
+					elif len(arg) > 0:            # usual ansi code
+						n = int(arg)
+					else:                         # empty code means reset
+						n = 0
+				except:
+					continue
+
+				if n == 0:                        # reset colors and attributes
 					fg, bg, attr = -1, -1, 0
-				elif n == 1:
+
+				elif n == 1:                      # enable attribute
 					attr |= color.bold
 				elif n == 4:
 					attr |= color.underline
@@ -48,7 +60,19 @@ def text_with_fg_bg_attr(ansi_text):
 					attr |= color.reverse
 				elif n == 8:
 					attr |= color.invisible
-				elif n >= 30 and n <= 37:
+
+				elif n == 22:                     # disable attribute
+					attr &= not color.bold
+				elif n == 24:
+					attr &= not color.underline
+				elif n == 25:
+					attr &= not color.blink
+				elif n == 27:
+					attr &= not color.reverse
+				elif n == 28:
+					attr &= not color.invisible
+
+				elif n >= 30 and n <= 37:         # 8 ansi foreground and background colors
 					fg = n - 30
 				elif n == 39:
 					fg = -1
@@ -56,7 +80,18 @@ def text_with_fg_bg_attr(ansi_text):
 					bg = n - 40
 				elif n == 49:
 					bg = -1
+
+				elif n >= 90 and n <= 97:         # 8 aixterm high intensity colors (light but not bold)
+					fg = n - 90 + 8
+				elif n == 99:
+					fg = -1
+				elif n >= 100 and n <= 107:
+					bg = n - 100 + 8
+				elif n == 109:
+					bg = -1
+
 			yield (fg, bg, attr)
+
 		else:
 			yield chunk
 
. Agaram <vc@akkartik.com> 2015-09-30 02:01:59 -0700 committer Kartik K. Agaram <vc@akkartik.com> 2015-09-30 02:01:59 -0700 2222' href='/akkartik/mu/commit/021check_instruction.cc?h=main&id=e236973be09620daec70d83f7a5846e8f6fff680'>e236973b ^
a0fc38c9 ^
ba1fb981 ^
2b250717 ^
a0fc38c9 ^

3c31b721 ^
bb7142db ^
e0659ab3 ^
a0fc38c9 ^




e236973b ^
a0fc38c9 ^
e236973b ^

a0fc38c9 ^






5f98a10c ^
1ead3562 ^
3c31b721 ^
a0fc38c9 ^
3c31b721 ^
a0fc38c9 ^

5f98a10c ^
1ead3562 ^
192d59d3 ^
a0fc38c9 ^
192d59d3 ^
a0fc38c9 ^

5f98a10c ^
1ead3562 ^
192d59d3 ^
a0fc38c9 ^
192d59d3 ^
a0fc38c9 ^

5f98a10c ^
1ead3562 ^
377b00b0 ^
a0fc38c9 ^
377b00b0 ^
a0fc38c9 ^
9e32e473 ^


377b00b0 ^

9e32e473 ^
377b00b0 ^
9e32e473 ^
1193171f ^






a0fc38c9 ^
691b529e ^
23d3a022 ^


1193171f ^
93d4cc93 ^
016599f1 ^


23d3a022 ^
dfdbcbab ^

4d238fd7 ^



4d238fd7 ^
23d3a022 ^
92a3d082 ^
4d238fd7 ^
016599f1 ^
23d3a022 ^





7f193a0e ^

49620728 ^
23d3a022 ^
b5f2a629 ^
1fb0cf9e ^
7136ddd5 ^

4d238fd7 ^
dfdbcbab ^
4d238fd7 ^


c6034af3 ^
23d3a022 ^




c6034af3 ^
3473c63a ^
af023b32 ^
93d4cc93 ^
af023b32 ^
93d4cc93 ^
af023b32 ^
af023b32 ^


f8b0b04d ^





a0fc38c9 ^

d785efe5 ^











f8b0b04d ^







86c715d7 ^

f8b0b04d ^

58a9f7c3 ^

7136ddd5 ^



3473c63a ^

af023b32 ^

af023b32 ^



4ecab182 ^



1fb0cf9e ^
a0fc38c9 ^

3473c63a ^

3bfd75fc ^

af023b32 ^
1fb0cf9e ^
3bfd75fc ^

3473c63a ^
9e32e473 ^




3473c63a ^
c6034af3 ^
af023b32 ^
67f969b9 ^
c4e143d6 ^
65c905fe ^
67f969b9 ^
1fb0cf9e ^
4e49b29e ^

db69ad7a ^

af023b32 ^





1fb0cf9e ^
db69ad7a ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232