Skip to content

Commit

Permalink
Use ansi escape code to clear line
Browse files Browse the repository at this point in the history
  • Loading branch information
ihabunek committed May 31, 2024
1 parent 3fe1faa commit 38636e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 6 additions & 0 deletions twitchdl/output.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import sys
from itertools import islice
from typing import Any, Callable, Generator, List, Optional, TypeVar

Expand All @@ -10,6 +11,11 @@
T = TypeVar("T")


def clear_line():
sys.stdout.write("\033[1K")
sys.stdout.write("\r")


def truncate(string: str, length: int) -> str:
if len(string) > length:
return string[: length - 1] + "…"
Expand Down
7 changes: 3 additions & 4 deletions twitchdl/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import click

from twitchdl.output import blue
from twitchdl.output import blue, clear_line
from twitchdl.utils import format_size, format_time

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -127,7 +127,8 @@ def print(self):

self._recalculate()

click.echo(f"\rDownloaded {self.vod_downloaded_count}/{self.vod_count} VODs", nl=False)
clear_line()
click.echo(f"Downloaded {self.vod_downloaded_count}/{self.vod_count} VODs", nl=False)
click.secho(f" {self.progress_perc}%", fg="blue", nl=False)

if self.estimated_total is not None:
Expand All @@ -141,6 +142,4 @@ def print(self):
if self.remaining_time is not None:
click.echo(f" ETA {blue(format_time(self.remaining_time))}", nl=False)

click.echo(" ", nl=False)

self.last_printed = now

0 comments on commit 38636e2

Please sign in to comment.