Use style helpers for color style
MODIFY
plex_trakt_sync/commands/plex_login.py
plex_trakt_sync/commands/plex_login.py
from urllib3.exceptions import ConnectTimeoutError
from plex_trakt_sync.config import CONFIG
+from plex_trakt_sync.style import prompt, error, success, title, comment
-PROMPT_PLEX_PASSWORD = click.style("Please enter your Plex password", fg="yellow")
-PROMPT_PLEX_USERNAME = click.style("Please enter your Plex username", fg="yellow")
-PROMPT_PLEX_RELOGIN = click.style("You already logged in to Plex, do you want to log in again?", fg="yellow")
-PROMPT_MANAGED_USER = click.style("Do you want to use managed user instead of main account?", fg="yellow")
+PROMPT_PLEX_PASSWORD = prompt("Please enter your Plex password")
+PROMPT_PLEX_USERNAME = prompt("Please enter your Plex username")
+PROMPT_PLEX_RELOGIN = prompt("You already have Plex Access Token, do you want to log in again?")
+PROMPT_MANAGED_USER = prompt("Do you want to use managed user instead of main account?")
def myplex_login(username, password):
@@ -23,7 +24,7 @@ def myplex_login(username, password):
try:
return MyPlexAccount(username, password)
except Unauthorized as e:
- click.secho(f"Logging failed: {e} Try again.", fg="red")
+ click.echo(error(f"Log in to Plex failed: {e}, Try again."))
def choose_managed_user(account: MyPlexAccount):
@@ -31,7 +32,7 @@ def choose_managed_user(account: MyPlexAccount):
if not users:
return None
- click.secho("Managed user(s) found:", fg="green")
+ click.echo(success("Managed user(s) found:"))
users = sorted(users)
for user in users:
click.echo(f"- {user}")
@@ -41,7 +42,7 @@ def choose_managed_user(account: MyPlexAccount):
# choice = prompt_choice(users)
user = click.prompt(
- click.style("Please select:", fg="yellow"),
+ title("Please select:"),
type=Choice(users),
show_default=True,
)
@@ -56,25 +57,26 @@ def choose_managed_user(account: MyPlexAccount):
def prompt_server(servers: List[MyPlexResource]):
def fmt_server(s):
- return f"- {s.name}: [Last seen: {s.lastSeenAt}, {s.product}/{s.productVersion} on {s.device}: {s.platform}/{s.platformVersion}]"
+ details = comment(f"{s.product}/{s.productVersion} on {s.device}: {s.platform}/{s.platformVersion}")
+ return f"- {s.name}: [Last seen: {comment(str(s.lastSeenAt))}, Server: {details}]"
owned_servers = [s for s in servers if s.owned]
unowned_servers = [s for s in servers if not s.owned]
server_names = []
if owned_servers:
- click.secho(f"{len(owned_servers)} owned servers found:", fg="green")
+ click.echo(success(f"{len(owned_servers)} owned servers found:"))
for s in owned_servers:
click.echo(fmt_server(s))
server_names.append(s.name)
if unowned_servers:
- click.secho(f"{len(owned_servers)} unowned servers found:", fg="green")
+ click.echo(success(f"{len(owned_servers)} unowned servers found:"))
for s in unowned_servers:
click.echo(fmt_server(s))
server_names.append(s.name)
return click.prompt(
- click.style("Select default server:", fg="yellow"),
+ title("Select default server:"),
type=Choice(server_names),
show_default=True,
)
@@ -103,7 +105,7 @@ def choose_server(account: MyPlexAccount):
try:
server = pick_server(account)
# Connect to obtain baseUrl
- click.secho(f"Attempting to connect to {server.name}. This may take time and emit some errors.", fg="yellow")
+ click.echo(title(f"Attempting to connect to {server.name}. This may take time and print some errors."))
plex = server.connect()
# Validate connection again, the way we connect
plex = PlexServer(token=server.accessToken, baseurl=plex._baseurl)
@@ -125,10 +127,10 @@ def plex_login(username, password):
return
account = myplex_login(username, password)
- click.secho("Login to MyPlex success!", fg="green")
+ click.echo(success("Login to MyPlex was successful!"))
[server, plex] = choose_server(account)
- click.secho(f"Connection to {plex.friendlyName} established successfully!", fg="green")
+ click.echo(success(f"Connection to {plex.friendlyName} established successfully!"))
token = server.accessToken
user = username

Use style helpers for color style