Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Jules/palette.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 4 additions & 2 deletions simulasyon_11.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


# ------------------------------------------------------------------------------
Expand Down