-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from j9ac9k/make-console-friendly-again
Replace problematic utf-8 characters with ASCII
- Loading branch information
Showing
12 changed files
with
461 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from typing import Any | ||
|
||
|
||
class DummyConsole: | ||
""" | ||
Class that acts as a drop in replacement for rich's Console, in case | ||
rich is not present on the system, or we are not wanting rich output | ||
""" | ||
|
||
def __init__(self, *args: Any, **kwargs: Any) -> None: | ||
self.level = float("-inf") | ||
|
||
def print(self, *args: Any, **kwargs: Any) -> None: | ||
print(*args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import json | ||
from contextlib import ContextDecorator | ||
from typing import Any | ||
from typing import Dict | ||
|
||
|
||
try: | ||
import websocket | ||
except ImportError: | ||
pass | ||
else: | ||
|
||
class WebSocketProgress(ContextDecorator): | ||
def __init__(self, url: str) -> None: | ||
super().__init__() | ||
self.ws = websocket.WebSocket() | ||
self.tasks: Dict[str, int] = {} | ||
self.current: Dict[str, int] = {} | ||
self.url = url | ||
|
||
def __enter__(self) -> Any: | ||
self.ws.connect(f"ws://{self.url}/websocket") | ||
return self | ||
|
||
def __exit__(self, *args: Any, **kwargs: Any) -> None: | ||
self.ws.close() | ||
return None | ||
|
||
def advance(self, name: str, value: int) -> None: | ||
self.current[name] += value | ||
new_value = self.current[name] | ||
self.ws.send(json.dumps({"advance": new_value, "type": "progress"})) | ||
return None | ||
|
||
def add_task(self, title: str, total: int) -> str: | ||
self.tasks[title] = total | ||
self.current[title] = 0 | ||
return title |
Oops, something went wrong.