Skip to content

Commit

Permalink
Merge pull request #241 from rsalmei/fix-ansi-escapes
Browse files Browse the repository at this point in the history
Fix CSI ANSI Escape Codes not being printed
  • Loading branch information
rsalmei committed May 9, 2023
2 parents bec00fe + 5b68494 commit 1204c12
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Changelog


## 3.1.2 - May 08, 2023
- fix some ANSI Escape Codes not being printed, by including support for terminal [OSC](https://en.wikipedia.org/wiki/ANSI_escape_code#OSC)


## 3.1.1 - Apr 08, 2023
- print hook support for ANSI Escape Codes (which avoid sending newlines when not needed)
- typing support in `alive_it`, so the collection type is correctly identified.
- typing support in `alive_it`, so the collection type is correctly identified


## 3.1.0 - Mar 23, 2023
Expand Down
2 changes: 1 addition & 1 deletion alive_progress/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .core.configuration import config_handler
from .core.progress import alive_bar, alive_it

VERSION = (3, 1, 1)
VERSION = (3, 1, 2)

__author__ = 'Rogério Sampaio de Almeida'
__email__ = 'rsalmei@gmail.com'
Expand Down
15 changes: 12 additions & 3 deletions alive_progress/core/hook_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,18 @@ def write(stream, part):

buffer = buffers[stream]
if part != '\n':
if part.startswith('\x1b'): # if the part starts with ESC, just send it.
stream.write(part)
return
osc = part.find('\x1b]') # https://en.wikipedia.org/wiki/ANSI_escape_code
if osc >= 0:
end, s = part.find('\x07', osc + 2), 1 # 1 -> len('\x07')
if end < 0:
end, s = part.find('\x1b\\', osc + 2), 2 # 2 -> len('\x1b\\')
if end < 0:
end, s = len(part), 0
stream.write(part[osc:end + s])
stream.flush()
part = part[:osc] + part[end + s:]
if not part:
return
# this will generate a sequence of lines interspersed with None, which will later
# be rendered as the indent filler to align additional lines under the same header.
gen = chain.from_iterable(zip(repeat(None), part.splitlines(True)))
Expand Down

0 comments on commit 1204c12

Please sign in to comment.