Skip to content

Commit 2c315bd

Browse files
committed
Abstracted color.py
1 parent fbd1269 commit 2c315bd

14 files changed

Lines changed: 211 additions & 92 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
nc = '\x1b[0m'
2+
hex = {
3+
'br': '#ff0000', 'by': '#ffff00', 'bo': '#ffa500', 'bg': '#00ff00',
4+
'bw': '#ffffff', 'gry': '#808080', 'blk': '#000000', 'tlBG': '#008080'
5+
}
6+
7+
def hex_to_ansi(hex_color: str) -> str:
8+
r = int(hex_color[1:3], 16)
9+
g = int(hex_color[3:5], 16)
10+
b = int(hex_color[5:7], 16)
11+
return f'\x1b[38;2;{r};{g};{b}m'
12+
13+
class _Schemes:
14+
@property
15+
def default(self) -> list[str]:
16+
return [hex_to_ansi(h) for h in [
17+
'#00e5bc', '#18c8ae', '#30ac9f', '#488f91', '#607383',
18+
'#775674', '#8f3966', '#a71d57', '#bf0049', '#9a1b5e'
19+
]]
20+
@property
21+
def rainbow(self) -> list[str]:
22+
return [hex_to_ansi(h) for h in [
23+
'#e41a1c', '#ff7f00', '#ffff33', '#4daf4a', '#377eb8',
24+
'#984ea3', '#f781bf', '#999999', '#a65628', '#d95f02'
25+
]]
26+
schemes = _Schemes()
27+
28+
def __getattr__(hex_key: str) -> str: # add color.hex_key getters that return ANSI
29+
if hex_key in hex: return hex_to_ansi(hex[hex_key])
30+
raise AttributeError(f"module 'color' has no attribute '{hex_key}'")

find-project-root/utils/lib/log.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,6 @@
66
try : terminal_width = os.get_terminal_size()[0]
77
except OSError : terminal_width = 80
88

9-
colors = sn(
10-
nc='\x1b[0m', # no color
11-
br='\x1b[1;91m', # bright red
12-
by='\x1b[1;33m', # bright yellow
13-
bo='\x1b[38;5;214m', # bright orange
14-
bg='\x1b[1;92m', # bright green
15-
bc='\x1b[1;96m', # bright cyan
16-
bw='\x1b[1;97m', # bright white
17-
dg='\x1b[32m', # dark green
18-
dy='\x1b[33m', # dark yellow
19-
gry='\x1b[90m' # gray
20-
)
21-
229
def data(msg: str, *args, no_newline: bool = False, **kwargs) -> None:
2310
print(f'\n{colors.bw}{msg.format(*args, **kwargs)}{colors.nc}', end='' if no_newline else None)
2411
def dim(msg: str, *args, no_newline: bool = False, **kwargs) -> None:
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
nc = '\x1b[0m'
2+
hex = {
3+
'br': '#ff0000', 'by': '#ffff00', 'bo': '#ffa500', 'bg': '#00ff00',
4+
'bw': '#ffffff', 'gry': '#808080', 'blk': '#000000', 'tlBG': '#008080'
5+
}
6+
7+
def hex_to_ansi(hex_color: str) -> str:
8+
r = int(hex_color[1:3], 16)
9+
g = int(hex_color[3:5], 16)
10+
b = int(hex_color[5:7], 16)
11+
return f'\x1b[38;2;{r};{g};{b}m'
12+
13+
class _Schemes:
14+
@property
15+
def default(self) -> list[str]:
16+
return [hex_to_ansi(h) for h in [
17+
'#00e5bc', '#18c8ae', '#30ac9f', '#488f91', '#607383',
18+
'#775674', '#8f3966', '#a71d57', '#bf0049', '#9a1b5e'
19+
]]
20+
@property
21+
def rainbow(self) -> list[str]:
22+
return [hex_to_ansi(h) for h in [
23+
'#e41a1c', '#ff7f00', '#ffff33', '#4daf4a', '#377eb8',
24+
'#984ea3', '#f781bf', '#999999', '#a65628', '#d95f02'
25+
]]
26+
schemes = _Schemes()
27+
28+
def __getattr__(hex_key: str) -> str: # add color.hex_key getters that return ANSI
29+
if hex_key in hex: return hex_to_ansi(hex[hex_key])
30+
raise AttributeError(f"module 'color' has no attribute '{hex_key}'")

get-min-py/src/get_min_py/cli/lib/log.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Optional
55
if sys.platform == 'win32' : import colorama ; colorama.init() # enable ANSI color support
66

7-
from . import data as datalib, pkg
7+
from . import color as colors, data as datalib, pkg
88

99
try : terminal_width = os.get_terminal_size()[0]
1010
except OSError : terminal_width = 80
@@ -13,19 +13,6 @@
1313
next_maj_ver = pkg.get_next_maj_ver(current_ver)
1414
_warned_keys = { 'cli': set(), 'config': set() }
1515

16-
colors = sn(
17-
nc='\x1b[0m', # no color
18-
br='\x1b[1;91m', # bright red
19-
by='\x1b[1;33m', # bright yellow
20-
bo='\x1b[38;5;214m', # bright orange
21-
bg='\x1b[1;92m', # bright green
22-
bc='\x1b[1;96m', # bright cyan
23-
bw='\x1b[1;97m', # bright white
24-
dg='\x1b[32m', # dark green
25-
dy='\x1b[33m', # dark yellow
26-
gry='\x1b[90m' # gray
27-
)
28-
2916
def data(msg: str, *args, no_newline: bool = False, **kwargs) -> None:
3017
print(f'\n{colors.bw}{msg.format(*args, **kwargs)}{colors.nc}', end='' if no_newline else None)
3118
def dim(msg: str, *args, no_newline: bool = False, **kwargs) -> None:

latin-locales/utils/lib/color.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
nc = '\x1b[0m'
2+
hex = {
3+
'br': '#ff0000', 'by': '#ffff00', 'bo': '#ffa500', 'bg': '#00ff00',
4+
'bw': '#ffffff', 'gry': '#808080', 'blk': '#000000', 'tlBG': '#008080'
5+
}
6+
7+
def hex_to_ansi(hex_color: str) -> str:
8+
r = int(hex_color[1:3], 16)
9+
g = int(hex_color[3:5], 16)
10+
b = int(hex_color[5:7], 16)
11+
return f'\x1b[38;2;{r};{g};{b}m'
12+
13+
class _Schemes:
14+
@property
15+
def default(self) -> list[str]:
16+
return [hex_to_ansi(h) for h in [
17+
'#00e5bc', '#18c8ae', '#30ac9f', '#488f91', '#607383',
18+
'#775674', '#8f3966', '#a71d57', '#bf0049', '#9a1b5e'
19+
]]
20+
@property
21+
def rainbow(self) -> list[str]:
22+
return [hex_to_ansi(h) for h in [
23+
'#e41a1c', '#ff7f00', '#ffff33', '#4daf4a', '#377eb8',
24+
'#984ea3', '#f781bf', '#999999', '#a65628', '#d95f02'
25+
]]
26+
schemes = _Schemes()
27+
28+
def __getattr__(hex_key: str) -> str: # add color.hex_key getters that return ANSI
29+
if hex_key in hex: return hex_to_ansi(hex[hex_key])
30+
raise AttributeError(f"module 'color' has no attribute '{hex_key}'")

latin-locales/utils/lib/log.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,6 @@
66
try : terminal_width = os.get_terminal_size()[0]
77
except OSError : terminal_width = 80
88

9-
colors = sn(
10-
nc='\x1b[0m', # no color
11-
br='\x1b[1;91m', # bright red
12-
by='\x1b[1;33m', # bright yellow
13-
bo='\x1b[38;5;214m', # bright orange
14-
bg='\x1b[1;92m', # bright green
15-
bc='\x1b[1;96m', # bright cyan
16-
bw='\x1b[1;97m', # bright white
17-
dg='\x1b[32m', # dark green
18-
dy='\x1b[33m', # dark yellow
19-
gry='\x1b[90m' # gray
20-
)
21-
229
def data(msg: str, *args, no_newline: bool = False, **kwargs) -> None:
2310
print(f'\n{colors.bw}{msg.format(*args, **kwargs)}{colors.nc}', end='' if no_newline else None)
2411
def dim(msg: str, *args, no_newline: bool = False, **kwargs) -> None:
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
nc = '\x1b[0m'
2+
hex = {
3+
'br': '#ff0000', 'by': '#ffff00', 'bo': '#ffa500', 'bg': '#00ff00',
4+
'bw': '#ffffff', 'gry': '#808080', 'blk': '#000000', 'tlBG': '#008080'
5+
}
6+
7+
def hex_to_ansi(hex_color: str) -> str:
8+
r = int(hex_color[1:3], 16)
9+
g = int(hex_color[3:5], 16)
10+
b = int(hex_color[5:7], 16)
11+
return f'\x1b[38;2;{r};{g};{b}m'
12+
13+
class _Schemes:
14+
@property
15+
def default(self) -> list[str]:
16+
return [hex_to_ansi(h) for h in [
17+
'#00e5bc', '#18c8ae', '#30ac9f', '#488f91', '#607383',
18+
'#775674', '#8f3966', '#a71d57', '#bf0049', '#9a1b5e'
19+
]]
20+
@property
21+
def rainbow(self) -> list[str]:
22+
return [hex_to_ansi(h) for h in [
23+
'#e41a1c', '#ff7f00', '#ffff33', '#4daf4a', '#377eb8',
24+
'#984ea3', '#f781bf', '#999999', '#a65628', '#d95f02'
25+
]]
26+
schemes = _Schemes()
27+
28+
def __getattr__(hex_key: str) -> str: # add color.hex_key getters that return ANSI
29+
if hex_key in hex: return hex_to_ansi(hex[hex_key])
30+
raise AttributeError(f"module 'color' has no attribute '{hex_key}'")

non-latin-locales/utils/lib/log.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,6 @@
66
try : terminal_width = os.get_terminal_size()[0]
77
except OSError : terminal_width = 80
88

9-
colors = sn(
10-
nc='\x1b[0m', # no color
11-
br='\x1b[1;91m', # bright red
12-
by='\x1b[1;33m', # bright yellow
13-
bo='\x1b[38;5;214m', # bright orange
14-
bg='\x1b[1;92m', # bright green
15-
bc='\x1b[1;96m', # bright cyan
16-
bw='\x1b[1;97m', # bright white
17-
dg='\x1b[32m', # dark green
18-
dy='\x1b[33m', # dark yellow
19-
gry='\x1b[90m' # gray
20-
)
21-
229
def data(msg: str, *args, no_newline: bool = False, **kwargs) -> None:
2310
print(f'\n{colors.bw}{msg.format(*args, **kwargs)}{colors.nc}', end='' if no_newline else None)
2411
def dim(msg: str, *args, no_newline: bool = False, **kwargs) -> None:

project-markers/utils/lib/color.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
nc = '\x1b[0m'
2+
hex = {
3+
'br': '#ff0000', 'by': '#ffff00', 'bo': '#ffa500', 'bg': '#00ff00',
4+
'bw': '#ffffff', 'gry': '#808080', 'blk': '#000000', 'tlBG': '#008080'
5+
}
6+
7+
def hex_to_ansi(hex_color: str) -> str:
8+
r = int(hex_color[1:3], 16)
9+
g = int(hex_color[3:5], 16)
10+
b = int(hex_color[5:7], 16)
11+
return f'\x1b[38;2;{r};{g};{b}m'
12+
13+
class _Schemes:
14+
@property
15+
def default(self) -> list[str]:
16+
return [hex_to_ansi(h) for h in [
17+
'#00e5bc', '#18c8ae', '#30ac9f', '#488f91', '#607383',
18+
'#775674', '#8f3966', '#a71d57', '#bf0049', '#9a1b5e'
19+
]]
20+
@property
21+
def rainbow(self) -> list[str]:
22+
return [hex_to_ansi(h) for h in [
23+
'#e41a1c', '#ff7f00', '#ffff33', '#4daf4a', '#377eb8',
24+
'#984ea3', '#f781bf', '#999999', '#a65628', '#d95f02'
25+
]]
26+
schemes = _Schemes()
27+
28+
def __getattr__(hex_key: str) -> str: # add color.hex_key getters that return ANSI
29+
if hex_key in hex: return hex_to_ansi(hex[hex_key])
30+
raise AttributeError(f"module 'color' has no attribute '{hex_key}'")

project-markers/utils/lib/log.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,6 @@
66
try : terminal_width = os.get_terminal_size()[0]
77
except OSError : terminal_width = 80
88

9-
colors = sn(
10-
nc='\x1b[0m', # no color
11-
br='\x1b[1;91m', # bright red
12-
by='\x1b[1;33m', # bright yellow
13-
bo='\x1b[38;5;214m', # bright orange
14-
bg='\x1b[1;92m', # bright green
15-
bc='\x1b[1;96m', # bright cyan
16-
bw='\x1b[1;97m', # bright white
17-
dg='\x1b[32m', # dark green
18-
dy='\x1b[33m', # dark yellow
19-
gry='\x1b[90m' # gray
20-
)
21-
229
def data(msg: str, *args, no_newline: bool = False, **kwargs) -> None:
2310
print(f'\n{colors.bw}{msg.format(*args, **kwargs)}{colors.nc}', end='' if no_newline else None)
2411
def dim(msg: str, *args, no_newline: bool = False, **kwargs) -> None:

0 commit comments

Comments
 (0)