From 95e7fdb1c06c869b74f67d74da344a46175d9a2b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 2 Mar 2026 10:23:27 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Palette:=20Update=20loading=5Fba?= =?UTF-8?q?r=20to=20be=20inline=20instead=20of=20multiline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using `sys.stdout.write` and `\r`, the loading bars in `simulasyon_11.py` now run and update in a single line instead of creating new lines constantly, preventing terminal clutter. Co-authored-by: Soldiers33 <255096253+Soldiers33@users.noreply.github.com> --- .Jules/palette.md | 3 +++ simulasyon_11.py | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .Jules/palette.md diff --git a/.Jules/palette.md b/.Jules/palette.md new file mode 100644 index 00000000..7286458a --- /dev/null +++ b/.Jules/palette.md @@ -0,0 +1,3 @@ +## 2024-03-02 - Inline Terminal Loading Bars +**Learning:** Terminal output can get cluttered with successive `print()` statements for loading steps. Using `sys.stdout.write` in combination with the carriage return character (`\r`) allows for updating the same line in place. +**Action:** Use `sys.stdout.write` and `\r` for terminal progress/loading indicators to improve CLI UX. diff --git a/simulasyon_11.py b/simulasyon_11.py index 63f8da57..6ff5dea5 100644 --- a/simulasyon_11.py +++ b/simulasyon_11.py @@ -35,9 +35,11 @@ class Colors: # ============================================================================== def loading_bar(desc): - print(f"{Colors.CYAN}{desc}...{Colors.ENDC}") + sys.stdout.write(f"{Colors.CYAN}{desc}...{Colors.ENDC}") + sys.stdout.flush() time.sleep(0.01) - print(f"{Colors.GREEN}[OK]{Colors.ENDC}") + sys.stdout.write(f"\r{Colors.CYAN}{desc}...{Colors.ENDC} {Colors.GREEN}[OK]{Colors.ENDC}\n") + sys.stdout.flush() # ------------------------------------------------------------------------------