Skip to content

Commit 7509835

Browse files
authored
Merge pull request #140 from dbpunk-labs/133-set-the-user-octogen-for-the-container
fix: fix the display progress bug
2 parents bbfaaf9 + b81f262 commit 7509835

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

sdk/src/og_sdk/utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,19 @@ def carriage_return(buf):
4848
if "\n" in buf:
4949
for _ in range(buf[::-1].index("\n")):
5050
pop_buf.append(buf.pop())
51-
return pop_buf[::-1]
51+
return pop_buf[::-1]
52+
else:
53+
pop_buf.extend(buf)
54+
buf.clear()
55+
return pop_buf
5256

5357
last_pop_buf = []
5458
while i < len(stream):
5559
c = stream[i]
5660
if c == "\b":
5761
if buffer:
5862
buffer.pop()
63+
last_pop_buf = []
5964
elif c == "\r":
6065
last_pop_buf = carriage_return(buffer)
6166
elif c == "\n":
@@ -64,8 +69,11 @@ def carriage_return(buf):
6469
last_pop_buf = []
6570
buffer.append(c)
6671
else:
72+
last_pop_buf = []
6773
buffer.append(c)
6874
i += 1
75+
if last_pop_buf:
76+
buffer.extend(last_pop_buf)
6977
return "".join(buffer)
7078

7179

sdk/tests/utils_test.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
from og_sdk.utils import process_char_stream
1212

1313

14+
def test_process_char_stream_case2():
15+
stream1 = "\rt: 0%| | 0/518 [00:00<?, ?it/s, now=None]"
16+
output1 = process_char_stream(stream1)
17+
stream2 = "\rt: 3%|▎ | 15/518 [00:00<00:03, 137.85it/s, now=None]"
18+
output2 = process_char_stream(output1 + stream2)
19+
assert output2 == "t: 3%|▎ | 15/518 [00:00<00:03, 137.85it/s, now=None]"
20+
21+
1422
def test_process_char_stream():
1523
stream0 = " Downloading pyfiglet-1.0.2-py3-none-any.whl (1.1 MB)\r\n\x1b[?25l \x1b[38;5;237m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m \x1b[32m0.0/1.1 MB\x1b[0m \x1b[31m?\x1b[0m eta \x1b[36m-:--:--\x1b[0m"
1624
stream1 = "\r\x1b[2K \x1b[38;5;237m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m \x1b[32m0.0/1.1 MB\x1b[0m \x1b[31m?\x1b[0m eta \x1b[36m-:--:--\x1b[0m"
@@ -53,10 +61,6 @@ def test_backspace_and_carriage_return():
5361
assert process_char_stream("ab\b\r") == "a"
5462

5563

56-
def test_carriage_return_and_backspace():
57-
assert process_char_stream("ab\r\b") == "a"
58-
59-
6064
def test_mixed_escape_characters_and_regular_characters():
6165
assert process_char_stream("ab\b\r\ncde") == "a\ncde"
6266

0 commit comments

Comments
 (0)