![]() And beyond CSI, there are codes to select alternative fonts ( SS2 and SS3), to send 'private messages' (think passwords), to communicate with the terminal ( DCS), the OS ( OSC), or the application itself ( APC, a way for applications to piggy-back custom control codes on to the communication stream), and further codes to help define strings ( SOS, Start of String, ST String Terminator) or to reset everything back to a base state ( RIS). With CSI alone you can also control the cursor, clear lines or the whole display, or scroll (provided the terminal supports this of course). However, there is more to ANSI than just CSI SGR codes. 0 (or 00 in this example): reset, disable all attributes.So for each \x1B[.m sequence, the 3 codes that are used are: The parameters (separated by semicolons) in between those tell your terminal what graphic rendition attributes to use. The example you gave contains 4 CSI (Control Sequence Introducer) codes, as marked by the \x1B[ or ESC [ opening bytes, and each contains a SGR (Select Graphic Rendition) code, because they each end in m. ![]() ECMA-48 standard, 5th edition (especially sections 5.3 and 5.4).the ANSI escape codes overview on Wikipedia.Which can be condensed down to # 7-bit and 8-bit C1 ANSI sequencesĪnsi_escape_8bit = ansi_escape_8bit.sub(b'', somebytesvalue) Result = ansi_escape_8bit.sub(b'', somebytesvalue) (?: # either 7-bit C1, two bytes, ESC Fe (omitting # or a single 8-bit byte Fe (omitting CSI) If you do need to cover the 8-bit codes too (and are then, presumably, working with bytes values) then the regular expression becomes a bytes pattern like this: # 7-bit and 8-bit C1 ANSI sequences The latter are never used in today's UTF-8 world where the same range of bytes have a different meaning. The above regular expression covers all 7-bit ANSI C1 escape sequences, but not the 8-bit C1 escape sequence openers. Or, without the VERBOSE flag, in condensed form: ansi_escape = ansi_escape.sub('', sometext) (?: # 7-bit C1 Fe (except # or [ for CSI, followed by a control sequence Delete them with a regular expression: import re
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |