mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-16 19:58:03 +01:00
Merge pull request #487 from asciinema/log-on-stderr
Print all user/diagnostic messages to stderr
This commit is contained in:
@@ -15,7 +15,7 @@ repos:
|
||||
hooks:
|
||||
- id: isort
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 22.1.0
|
||||
rev: 22.3.0
|
||||
hooks:
|
||||
- id: black
|
||||
- repo: https://github.com/adrienverge/yamllint
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
import sys
|
||||
from typing import Any, Dict, TextIO
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from ..api import Api
|
||||
from ..config import Config
|
||||
@@ -14,31 +14,21 @@ class Command:
|
||||
def print(
|
||||
self,
|
||||
text: str,
|
||||
file_: TextIO = sys.stdout,
|
||||
end: str = "\n",
|
||||
color: Optional[int] = None,
|
||||
force: bool = False,
|
||||
) -> None:
|
||||
if not self.quiet or force:
|
||||
print(text, file=file_, end=end)
|
||||
if color is not None and os.isatty(sys.stderr.fileno()):
|
||||
text = f"\x1b[0;3{color}m{text}\x1b[0m"
|
||||
|
||||
print(text, file=sys.stderr, end=end)
|
||||
|
||||
def print_info(self, text: str) -> None:
|
||||
if os.isatty(sys.stdout.fileno()):
|
||||
self.print(f"\x1b[0;32masciinema: {text}\x1b[0m")
|
||||
else:
|
||||
self.print(f"asciinema: {text}")
|
||||
self.print(f"asciinema: {text}", color=2)
|
||||
|
||||
def print_warning(self, text: str) -> None:
|
||||
if os.isatty(sys.stdout.fileno()):
|
||||
self.print(f"\x1b[0;33masciinema: {text}\x1b[0m")
|
||||
else:
|
||||
self.print(f"asciinema: {text}")
|
||||
self.print(f"asciinema: {text}", color=3)
|
||||
|
||||
def print_error(self, text: str) -> None:
|
||||
if os.isatty(sys.stderr.fileno()):
|
||||
self.print(
|
||||
f"\x1b[0;31masciinema: {text}\x1b[0m",
|
||||
file_=sys.stderr,
|
||||
force=True,
|
||||
)
|
||||
else:
|
||||
self.print(f"asciinema: {text}", file_=sys.stderr, force=True)
|
||||
self.print(f"asciinema: {text}", color=1, force=True)
|
||||
|
||||
Reference in New Issue
Block a user