Skip to content

Commit 1f9d196

Browse files
committed
Added color.hex.dg
1 parent a32bd87 commit 1f9d196

8 files changed

Lines changed: 37 additions & 7 deletions

File tree

  • find-project-root/utils/lib
  • get-min-py/src/get_min_py/cli/lib
  • is-unicode-supported/src/is_unicode_supported/cli/lib
  • latin-locales/utils/lib
  • non-latin-locales/utils/lib
  • project-markers/utils/lib
  • remove-json-keys/src/remove_json_keys/cli/lib
  • translate-messages/src/translate_messages/cli/lib

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
nc = '\x1b[0m'
22
hex = {
33
'br': '#ff0000', 'by': '#ffff00', 'bo': '#ffa500', 'bg': '#00ff00',
4-
'bw': '#ffffff', 'gry': '#808080', 'blk': '#000000', 'tlBG': '#008080'
4+
'bw': '#ffffff', 'dg': '#008000', 'gry': '#808080', 'blk': '#000000', 'tlBG': '#008080'
55
}
66

77
def hex_to_ansi(hex_color: str) -> str:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
nc = '\x1b[0m'
22
hex = {
33
'br': '#ff0000', 'by': '#ffff00', 'bo': '#ffa500', 'bg': '#00ff00',
4-
'bw': '#ffffff', 'gry': '#808080', 'blk': '#000000', 'tlBG': '#008080'
4+
'bw': '#ffffff', 'dg': '#008000', 'gry': '#808080', 'blk': '#000000', 'tlBG': '#008080'
55
}
66

77
def hex_to_ansi(hex_color: str) -> str:
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', 'dg': '#008000', '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(hex) for hex 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(hex) for hex 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/color.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
nc = '\x1b[0m'
22
hex = {
33
'br': '#ff0000', 'by': '#ffff00', 'bo': '#ffa500', 'bg': '#00ff00',
4-
'bw': '#ffffff', 'gry': '#808080', 'blk': '#000000', 'tlBG': '#008080'
4+
'bw': '#ffffff', 'dg': '#008000', 'gry': '#808080', 'blk': '#000000', 'tlBG': '#008080'
55
}
66

77
def hex_to_ansi(hex_color: str) -> str:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
nc = '\x1b[0m'
22
hex = {
33
'br': '#ff0000', 'by': '#ffff00', 'bo': '#ffa500', 'bg': '#00ff00',
4-
'bw': '#ffffff', 'gry': '#808080', 'blk': '#000000', 'tlBG': '#008080'
4+
'bw': '#ffffff', 'dg': '#008000', 'gry': '#808080', 'blk': '#000000', 'tlBG': '#008080'
55
}
66

77
def hex_to_ansi(hex_color: str) -> str:

project-markers/utils/lib/color.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
nc = '\x1b[0m'
22
hex = {
33
'br': '#ff0000', 'by': '#ffff00', 'bo': '#ffa500', 'bg': '#00ff00',
4-
'bw': '#ffffff', 'gry': '#808080', 'blk': '#000000', 'tlBG': '#008080'
4+
'bw': '#ffffff', 'dg': '#008000', 'gry': '#808080', 'blk': '#000000', 'tlBG': '#008080'
55
}
66

77
def hex_to_ansi(hex_color: str) -> str:

remove-json-keys/src/remove_json_keys/cli/lib/color.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
nc = '\x1b[0m'
22
hex = {
33
'br': '#ff0000', 'by': '#ffff00', 'bo': '#ffa500', 'bg': '#00ff00',
4-
'bw': '#ffffff', 'gry': '#808080', 'blk': '#000000', 'tlBG': '#008080'
4+
'bw': '#ffffff', 'dg': '#008000', 'gry': '#808080', 'blk': '#000000', 'tlBG': '#008080'
55
}
66

77
def hex_to_ansi(hex_color: str) -> str:

translate-messages/src/translate_messages/cli/lib/color.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
nc = '\x1b[0m'
22
hex = {
33
'br': '#ff0000', 'by': '#ffff00', 'bo': '#ffa500', 'bg': '#00ff00',
4-
'bw': '#ffffff', 'gry': '#808080', 'blk': '#000000', 'tlBG': '#008080'
4+
'bw': '#ffffff', 'dg': '#008000', 'gry': '#808080', 'blk': '#000000', 'tlBG': '#008080'
55
}
66

77
def hex_to_ansi(hex_color: str) -> str:

0 commit comments

Comments
 (0)