ipython_view: Handle more color-related ANSI escape codes
requested to merge michaelweghorn/accerciser:michaelweghorn/ipython_view_add_more_ansi_color_codes into master
Add handling for more ANSI escape codes related to colors, see
commit 68e4f4bbec0dff3a83f11770c936635d76ce9af9
Author: Michael Weghorn <m.weghorn@posteo.de>
Date: Sat Feb 18 17:42:48 2023 +0100
ipython_view: Handle ANSI escape codes related to bg color
for reasoning and more details.
The newly added codes were all encountered when trying to query character extents with the GTK 4 based LibreOffice variant not yet implementing the new GTK API to provide that [1].
Without this commit in place, trying to query that in the IPython console would trigger exceptions like
In [17]: acc.queryText().getCharacterExtents(1, pyatspi.XY_WINDOW)
---------------------------------------------------------------------------
Error Traceback (most recent call last)
Cell In[17], line 1
----> 1 acc.queryText().getCharacterExtents(1, pyatspi.XY_WINDOW)
File /usr/lib/python3/dist-packages/pyatspi/text.py:289, in Text.getCharacterExtents(self, offset, coordType)
268
Traceback (most recent call last):
File "/home/michi/temp/accerciser/share/accerciser/plugins/ipython_view.py", line 539, in _showReturned
self._write('\n'+text)
File "/home/michi/temp/accerciser/share/accerciser/plugins/ipython_view.py", line 471, in _write
self.text_buffer.insert_with_tags_by_name(self.text_buffer.get_end_iter(),
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 773, in insert_with_tags_by_name
raise ValueError('unknown text tag: %s' % tag)
ValueError: unknown text tag: 38;5;28;01
Cell In[18], line 2
---------------------------------------------------------------------------
^
SyntaxError: invalid syntax
With this commit in place, a more helpful error is shown now in the colorful output:
In [1]: acc.queryText().getCharacterExtents(1, pyatspi.XY_WINDOW)
---------------------------------------------------------------------------
Error Traceback (most recent call last)
Cell In[1], line 1
----> 1 acc.queryText().getCharacterExtents(1, pyatspi.XY_WINDOW)
File /usr/lib/python3/dist-packages/pyatspi/text.py:289, in Text.getCharacterExtents(self, offset, coordType)
268 def getCharacterExtents(self, offset, coordType):
269 """
270 Obtain a the bounding box, as x, y, width, and height, of the
271 character or glyph at a particular character offset in this object's
(...)
287 down.
288 """
--> 289 ret = Atspi.Text.get_character_extents(self.obj, offset, coordType)
290 return rectToList(ret)
Error: atspi_error: (1)