36 lines
912 B
Python
36 lines
912 B
Python
import shutil
|
|
import textwrap
|
|
from commands.login import login
|
|
from typing import Any, Callable
|
|
|
|
from config import Config
|
|
|
|
|
|
def print_wrap(text: str, indent: str = '', end: str = '\n') -> None:
|
|
w, _ = shutil.get_terminal_size((80, 20))
|
|
if w > 72:
|
|
w = 72
|
|
|
|
lines = text.split('\n')
|
|
for i, line in enumerate(lines):
|
|
_end = '\n' if i < len(lines) - 1 else end
|
|
|
|
if not line:
|
|
print(indent, end=_end)
|
|
continue
|
|
|
|
wrapped = textwrap.fill(
|
|
line, w, initial_indent=indent, subsequent_indent=indent)
|
|
print(wrapped, end=_end)
|
|
|
|
|
|
def require_login(function: Callable) -> Callable:
|
|
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
if 'api_token' not in Config['user']:
|
|
print('Not logged in. Please use the login command to log in.')
|
|
return
|
|
|
|
return function(*args, **kwargs)
|
|
|
|
return wrapper
|