-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
68 lines (48 loc) · 1.53 KB
/
utils.py
File metadata and controls
68 lines (48 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import sys
from pathlib import Path
_ANSI_ENABLED = sys.stdout.isatty() and os.environ.get("NO_COLOR") is None
_RESET = "\033[0m"
_STYLES = {
"title": "\033[1;38;5;45m",
"muted": "\033[38;5;250m",
"dim": "\033[2;38;5;245m",
"info": "\033[1;38;5;81m",
"scan": "\033[1;38;5;39m",
"rename": "\033[1;38;5;42m",
"preview": "\033[1;38;5;220m",
"skip": "\033[1;38;5;214m",
"error": "\033[1;38;5;196m",
"filename": "\033[1;38;5;159m",
"caption": "\033[38;5;188m",
"rule": "\033[38;5;240m",
}
def style(text: str, tone: str) -> str:
if not _ANSI_ENABLED:
return text
return f"{_STYLES.get(tone, '')}{text}{_RESET}"
def status_label(name: str, tone: str) -> str:
return style(f"[{name}]", tone)
def section_title(title: str) -> str:
return style(title, "title")
def muted(text: str) -> str:
return style(text, "muted")
def dim(text: str) -> str:
return style(text, "dim")
def rule(char: str = "─", width: int = 64) -> str:
return style(char * width, "rule")
def key_value(label: str, value: str, tone: str = "muted") -> str:
return f"{style(label, tone)} {value}"
def print_banner() -> None:
lines = [
section_title("shotrename"),
muted("terminal-first screenshot renamer"),
]
print("\n".join(lines))
def human_readable_size(path: Path) -> str:
size = path.stat().st_size
for unit in ("B", "KB", "MB", "GB"):
if size < 1024:
return f"{size:.1f} {unit}"
size /= 1024
return f"{size:.1f} TB"