Skip to content

Commit fbc779d

Browse files
authored
Merge pull request #20 from tmck-code/print-initial-bar
Print initial bar
2 parents e053372 + bea407f commit fbc779d

3 files changed

Lines changed: 16 additions & 15 deletions

File tree

laser_prynter/pbar.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,6 @@ def __init__(self, total: int, c1: RGB = DEFAULT_C1, c2: RGB = DEFAULT_C2):
4949
self.g = list(interp_xyz(c1, c2, self.w + 1))
5050

5151
self._iter_pbar = iter(self._pbar())
52-
# self._initial_bar()
53-
54-
def _initial_bar(self) -> None:
55-
"print initial bar in end color"
56-
print(
57-
f'\x1b[48;2;{self.c2.r};{self.c2.g};{self.c2.b}m' + ' ' * self.w + '\x1b[0m',
58-
end='',
59-
flush=True,
60-
)
61-
print('\r', end='', flush=True)
6252

6353
@staticmethod
6454
def randgrad() -> tuple[RGB, RGB]:
@@ -84,15 +74,25 @@ def __iter__(self) -> PBar:
8474
def _true_colour(rgb: RGB) -> str:
8575
return f'\x1b[48;2;{rgb.r};{rgb.g};{rgb.b}m'
8676

87-
def __next__(self) -> None:
88-
s = [f'{self._true_colour(rgb)} ' for _, rgb in next(self._iter_pbar)]
77+
def _print_bar_chars(self, s: str) -> None:
8978
_print_to_terminal(
9079
'\x1b7' # save cursor position
9180
f'\x1b[{self.h};{self.curr}H' # move to bottom line
92-
f'{"".join(s)}' # the "bar" characters
81+
f'{s}' # the "bar" characters
9382
'\x1b[0m' # reset color
9483
'\x1b8' # restore cursor position
9584
)
85+
86+
def _initial_bar(self) -> None:
87+
"print initial bar in end color"
88+
self._print_bar_chars(
89+
f'\x1b[48;2;{self.c2.r};{self.c2.g};{self.c2.b}m' + ' ' * self.w + '\x1b[0m'
90+
)
91+
92+
def __next__(self) -> None:
93+
s = [f'{self._true_colour(rgb)} ' for _, rgb in next(self._iter_pbar)]
94+
self._print_bar_chars(''.join(s))
95+
9696
self.curr += len(s)
9797
if self.curr > self.w:
9898
raise StopIteration
@@ -117,6 +117,7 @@ def __enter__(self) -> PBar:
117117
'\x1b8' # restore cursor position
118118
'\x1b[1A' # move cursor up
119119
)
120+
self._initial_bar()
120121
return self
121122

122123
def __exit__(self, _exc_type: type, _exc_val: BaseException, _exc_tb: type) -> None:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "laser-prynter"
3-
version = "0.4.3"
3+
version = "0.4.4"
44
authors = [{ name = "tmck-code", email = "tmck01@gmail.com" }]
55
description = "terminal/cli/python helpers for colour and pretty-printing"
66
readme = "README.md"

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)