mirror of
https://github.com/daylinmorgan/task.mk.git
synced 2024-12-22 10:00:43 -06:00
refactor: use lambda for simple functions
This commit is contained in:
parent
2e4a82a6f8
commit
fff5448b60
2 changed files with 14 additions and 22 deletions
18
src/ansi.py
18
src/ansi.py
|
@ -19,14 +19,8 @@ state2byte = dict(
|
||||||
bold=1, faint=2, italic=3, underline=4, blink=5, fast_blink=6, crossed=9
|
bold=1, faint=2, italic=3, underline=4, blink=5, fast_blink=6, crossed=9
|
||||||
)
|
)
|
||||||
|
|
||||||
|
addfg = lambda byte: byte + 30
|
||||||
def fg(byte):
|
addbg = lambda byte: byte + 40
|
||||||
return 30 + byte
|
|
||||||
|
|
||||||
|
|
||||||
def bg(byte):
|
|
||||||
return 40 + byte
|
|
||||||
|
|
||||||
|
|
||||||
class Ansi:
|
class Ansi:
|
||||||
"""ANSI color codes"""
|
"""ANSI color codes"""
|
||||||
|
@ -36,11 +30,11 @@ class Ansi:
|
||||||
self.setcode("default", "\033[38m")
|
self.setcode("default", "\033[38m")
|
||||||
self.setcode("bg_default", "\033[48m")
|
self.setcode("bg_default", "\033[48m")
|
||||||
for name, byte in color2byte.items():
|
for name, byte in color2byte.items():
|
||||||
self.setcode(name, f"\033[{fg(byte)}m")
|
self.setcode(name, f"\033[{addfg(byte)}m")
|
||||||
self.setcode(f"b_{name}", f"\033[1;{fg(byte)}m")
|
self.setcode(f"b_{name}", f"\033[1;{addfg(byte)}m")
|
||||||
self.setcode(f"d_{name}", f"\033[2;{fg(byte)}m")
|
self.setcode(f"d_{name}", f"\033[2;{addfg(byte)}m")
|
||||||
for bgname, bgbyte in color2byte.items():
|
for bgname, bgbyte in color2byte.items():
|
||||||
self.setcode(f"{name}_on_{bgname}", f"\033[{bg(bgbyte)};{fg(byte)}m")
|
self.setcode(f"{name}_on_{bgname}", f"\033[{addbg(bgbyte)};{addfg(byte)}m")
|
||||||
for name, byte in state2byte.items():
|
for name, byte in state2byte.items():
|
||||||
self.setcode(name, f"\033[{byte}m")
|
self.setcode(name, f"\033[{byte}m")
|
||||||
|
|
||||||
|
|
18
task.mk
18
task.mk
|
@ -1,7 +1,7 @@
|
||||||
# }> [github.com/daylinmorgan/task.mk] <{ #
|
# }> [github.com/daylinmorgan/task.mk] <{ #
|
||||||
# Copyright (c) 2022 Daylin Morgan
|
# Copyright (c) 2022 Daylin Morgan
|
||||||
# MIT License
|
# MIT License
|
||||||
# version: v22.9.14-8-gc3fa7cd-dev
|
# version: v22.9.14-10-g2e4a82a-dev
|
||||||
#
|
#
|
||||||
# task.mk should be included at the bottom of your Makefile with `-include .task.mk`
|
# task.mk should be included at the bottom of your Makefile with `-include .task.mk`
|
||||||
# See below for the standard configuration options that should be set prior to including this file.
|
# See below for the standard configuration options that should be set prior to including this file.
|
||||||
|
@ -165,22 +165,20 @@ color2byte = dict(
|
||||||
state2byte = dict(
|
state2byte = dict(
|
||||||
bold=1, faint=2, italic=3, underline=4, blink=5, fast_blink=6, crossed=9
|
bold=1, faint=2, italic=3, underline=4, blink=5, fast_blink=6, crossed=9
|
||||||
)
|
)
|
||||||
def fg(byte):
|
addfg = lambda byte: byte + 30
|
||||||
return 30 + byte
|
addbg = lambda byte: byte + 40
|
||||||
def bg(byte):
|
|
||||||
return 40 + byte
|
|
||||||
class Ansi:
|
class Ansi:
|
||||||
"""ANSI color codes"""
|
"""ANSI escape codes"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.setcode("end", "\033[0m")
|
self.setcode("end", "\033[0m")
|
||||||
self.setcode("default", "\033[38m")
|
self.setcode("default", "\033[38m")
|
||||||
self.setcode("bg_default", "\033[48m")
|
self.setcode("bg_default", "\033[48m")
|
||||||
for name, byte in color2byte.items():
|
for name, byte in color2byte.items():
|
||||||
self.setcode(name, f"\033[{fg(byte)}m")
|
self.setcode(name, f"\033[{addfg(byte)}m")
|
||||||
self.setcode(f"b_{name}", f"\033[1;{fg(byte)}m")
|
self.setcode(f"b_{name}", f"\033[1;{addfg(byte)}m")
|
||||||
self.setcode(f"d_{name}", f"\033[2;{fg(byte)}m")
|
self.setcode(f"d_{name}", f"\033[2;{addfg(byte)}m")
|
||||||
for bgname, bgbyte in color2byte.items():
|
for bgname, bgbyte in color2byte.items():
|
||||||
self.setcode(f"{name}_on_{bgname}", f"\033[{bg(bgbyte)};{fg(byte)}m")
|
self.setcode(f"{name}_on_{bgname}", f"\033[{addbg(bgbyte)};{addfg(byte)}m")
|
||||||
for name, byte in state2byte.items():
|
for name, byte in state2byte.items():
|
||||||
self.setcode(name, f"\033[{byte}m")
|
self.setcode(name, f"\033[{byte}m")
|
||||||
def setcode(self, name, escape_code):
|
def setcode(self, name, escape_code):
|
||||||
|
|
Loading…
Reference in a new issue