mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-16 11:48:13 +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:
|
hooks:
|
||||||
- id: isort
|
- id: isort
|
||||||
- repo: https://github.com/psf/black
|
- repo: https://github.com/psf/black
|
||||||
rev: 22.1.0
|
rev: 22.3.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
- repo: https://github.com/adrienverge/yamllint
|
- repo: https://github.com/adrienverge/yamllint
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from typing import Any, Dict, TextIO
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
from ..api import Api
|
from ..api import Api
|
||||||
from ..config import Config
|
from ..config import Config
|
||||||
@@ -14,31 +14,21 @@ class Command:
|
|||||||
def print(
|
def print(
|
||||||
self,
|
self,
|
||||||
text: str,
|
text: str,
|
||||||
file_: TextIO = sys.stdout,
|
|
||||||
end: str = "\n",
|
end: str = "\n",
|
||||||
|
color: Optional[int] = None,
|
||||||
force: bool = False,
|
force: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
if not self.quiet or force:
|
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:
|
def print_info(self, text: str) -> None:
|
||||||
if os.isatty(sys.stdout.fileno()):
|
self.print(f"asciinema: {text}", color=2)
|
||||||
self.print(f"\x1b[0;32masciinema: {text}\x1b[0m")
|
|
||||||
else:
|
|
||||||
self.print(f"asciinema: {text}")
|
|
||||||
|
|
||||||
def print_warning(self, text: str) -> None:
|
def print_warning(self, text: str) -> None:
|
||||||
if os.isatty(sys.stdout.fileno()):
|
self.print(f"asciinema: {text}", color=3)
|
||||||
self.print(f"\x1b[0;33masciinema: {text}\x1b[0m")
|
|
||||||
else:
|
|
||||||
self.print(f"asciinema: {text}")
|
|
||||||
|
|
||||||
def print_error(self, text: str) -> None:
|
def print_error(self, text: str) -> None:
|
||||||
if os.isatty(sys.stderr.fileno()):
|
self.print(f"asciinema: {text}", color=1, force=True)
|
||||||
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)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user