mirror of
https://github.com/caelestia-dots/cli.git
synced 2026-06-16 05:49:59 -05:00
refactor: rename logging -> io + add more funcs
This commit is contained in:
@@ -7,7 +7,7 @@ from pathlib import Path
|
|||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
from caelestia.utils import hypr
|
from caelestia.utils import hypr
|
||||||
from caelestia.utils.logging import log_message
|
from caelestia.utils.io import log_message
|
||||||
from caelestia.utils.paths import user_config_path
|
from caelestia.utils.paths import user_config_path
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import sys
|
||||||
|
from time import strftime
|
||||||
|
|
||||||
|
|
||||||
|
def log_message(message: str) -> None:
|
||||||
|
timestamp = strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
print(f"[{timestamp}] {message}")
|
||||||
|
|
||||||
|
|
||||||
|
def log_exception(func):
|
||||||
|
"""Log exceptions to stdout instead of raising
|
||||||
|
|
||||||
|
Used by the `apply_()` functions so that an exception, when applying
|
||||||
|
a theme, does not prevent the other themes from being applied.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
try:
|
||||||
|
func(*args, **kwargs)
|
||||||
|
except Exception as e:
|
||||||
|
log_message(f'Error during execution of "{func.__name__}()": {str(e)}')
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
def _format_msg(colour: int, msg: str) -> str:
|
||||||
|
return f"\033[{colour}m:: {msg}\033[0m"
|
||||||
|
|
||||||
|
|
||||||
|
def log(msg: str) -> None:
|
||||||
|
print(_format_msg(2, msg))
|
||||||
|
|
||||||
|
|
||||||
|
def info(msg: str) -> None:
|
||||||
|
print(_format_msg(0, msg))
|
||||||
|
|
||||||
|
|
||||||
|
def warn(msg: str) -> None:
|
||||||
|
print(_format_msg(33, f"Warning: {msg}"))
|
||||||
|
|
||||||
|
|
||||||
|
def error(msg: str) -> None:
|
||||||
|
print(_format_msg(31, f"Error: {msg}"), file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
|
def fatal(msg: str) -> None:
|
||||||
|
print(_format_msg(31, f"Fatal: {msg}"), file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def prompt(msg: str) -> str:
|
||||||
|
return input(_format_msg(36, msg) + " ")
|
||||||
|
|
||||||
|
|
||||||
|
def pause() -> None:
|
||||||
|
input("\033[2m\033[3m(Ctrl+C to exit, enter to continue)\033[0m")
|
||||||
|
print("\033[1A\r\033[2K", end="") # Clear pause prompt
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
from time import strftime
|
|
||||||
|
|
||||||
|
|
||||||
def log_message(message: str) -> None:
|
|
||||||
timestamp = strftime("%Y-%m-%d %H:%M:%S")
|
|
||||||
print(f"[{timestamp}] {message}")
|
|
||||||
|
|
||||||
|
|
||||||
def log_exception(func):
|
|
||||||
"""Log exceptions to stdout instead of raising
|
|
||||||
|
|
||||||
Used by the `apply_()` functions so that an exception, when applying
|
|
||||||
a theme, does not prevent the other themes from being applied.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def wrapper(*args, **kwargs):
|
|
||||||
try:
|
|
||||||
func(*args, **kwargs)
|
|
||||||
except Exception as e:
|
|
||||||
log_message(f'Error during execution of "{func.__name__}()": {str(e)}')
|
|
||||||
|
|
||||||
return wrapper
|
|
||||||
@@ -8,7 +8,8 @@ import tempfile
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from caelestia.utils.colour import get_dynamic_colours
|
from caelestia.utils.colour import get_dynamic_colours
|
||||||
from caelestia.utils.logging import log_exception
|
from caelestia.utils.hypr import is_lua_config
|
||||||
|
from caelestia.utils.io import log_exception
|
||||||
from caelestia.utils.paths import (
|
from caelestia.utils.paths import (
|
||||||
c_state_dir,
|
c_state_dir,
|
||||||
config_dir,
|
config_dir,
|
||||||
@@ -19,7 +20,6 @@ from caelestia.utils.paths import (
|
|||||||
user_templates_dir,
|
user_templates_dir,
|
||||||
)
|
)
|
||||||
from caelestia.utils.scheme import get_scheme
|
from caelestia.utils.scheme import get_scheme
|
||||||
from caelestia.utils.hypr import is_lua_config
|
|
||||||
|
|
||||||
|
|
||||||
def gen_conf(colours: dict[str, str]) -> str:
|
def gen_conf(colours: dict[str, str]) -> str:
|
||||||
@@ -28,6 +28,7 @@ def gen_conf(colours: dict[str, str]) -> str:
|
|||||||
conf += f"${name} = {colour}\n"
|
conf += f"${name} = {colour}\n"
|
||||||
return conf
|
return conf
|
||||||
|
|
||||||
|
|
||||||
def gen_lua(colours: dict[str, str]) -> str:
|
def gen_lua(colours: dict[str, str]) -> str:
|
||||||
lua = "return {\n"
|
lua = "return {\n"
|
||||||
for name, colour in colours.items():
|
for name, colour in colours.items():
|
||||||
@@ -35,6 +36,7 @@ def gen_lua(colours: dict[str, str]) -> str:
|
|||||||
lua += "}"
|
lua += "}"
|
||||||
return lua
|
return lua
|
||||||
|
|
||||||
|
|
||||||
def gen_scss(colours: dict[str, str]) -> str:
|
def gen_scss(colours: dict[str, str]) -> str:
|
||||||
scss = ""
|
scss = ""
|
||||||
for name, colour in colours.items():
|
for name, colour in colours.items():
|
||||||
|
|||||||
Reference in New Issue
Block a user