diff --git a/README.md b/README.md index 8f14ab0..87e44f7 100644 --- a/README.md +++ b/README.md @@ -30,14 +30,14 @@ If someone tries to invoke `make help` it will download `.task.mk` for them. ```make -include .task.mk -$(if $(filter help,$(MAKECMDGOALS)),$(if $(wildcard .task.mk),,.task.mk: ; curl -fsSL https://raw.githubusercontent.com/daylinmorgan/task.mk/v22.9.5/task.mk -o .task.mk)) +$(if $(filter help,$(MAKECMDGOALS)),$(if $(wildcard .task.mk),,.task.mk: ; curl -fsSL https://raw.githubusercontent.com/daylinmorgan/task.mk/v22.9.7/task.mk -o .task.mk)) ``` You might also consider making it a consistently downloaded dependency if you plan to use any of it's advanced feature set, by dropping the `$(MAKECMDGOALS)` check. ```make -include .task.mk -$(if $(wildcard .task.mk),,.task.mk: ; curl -fsSL https://raw.githubusercontent.com/daylinmorgan/task.mk/v22.9.5/task.mk -o .task.mk) +$(if $(wildcard .task.mk),,.task.mk: ; curl -fsSL https://raw.githubusercontent.com/daylinmorgan/task.mk/v22.9.7/task.mk -o .task.mk) ``` ## Usage diff --git a/task.mk b/task.mk index 7824950..393a807 100644 --- a/task.mk +++ b/task.mk @@ -1,7 +1,7 @@ # }> [github.com/daylinmorgan/task.mk] <{ # # Copyright (c) 2022 Daylin Morgan # MIT License -# v22.9.5-3-g9c67418 +# version: 22.9.7 # # task.mk should be included at the bottom of your Makefile. # See below for the standard configuration options that should be set prior to including this file. @@ -129,7 +129,7 @@ def get_help(file): print(f"""$(USAGE)""") goals = list(get_help(makefile)) -if os.getenv("SORT_HELP",False): +if os.getenv("SORT_HELP", False): goals.sort(key=lambda i: i[0]) goal_len = max(len(goal[0]) for goal in goals) @@ -174,12 +174,6 @@ def bg(byte): class Ansi: """ANSI color codes""" - def setcode(self, name, escape_code): - if not sys.stdout.isatty() or os.getenv("NO_COLOR", False): - setattr(self, name, "") - else: - setattr(self, name, escape_code) - def __init__(self): self.setcode("end", "\033[0m") for name, byte in color2byte.items(): @@ -191,6 +185,42 @@ class Ansi: for name, byte in state2byte.items(): self.setcode(name, f"\033[{byte}m") + def setcode(self, name, escape_code): + """create attr for style and escape code""" + + if not sys.stdout.isatty() or os.getenv("NO_COLOR", False): + setattr(self, name, "") + else: + setattr(self, name, escape_code) + + def custom(self, fg=None, bg=None): + """use custom color""" + + code, end = "\033[", "m" + if fg: + if isinstance(fg, int): + code += f"38;5;{fg}" + elif (isinstance(fg, list) or isinstance(fg, tuple)) and len(fg) == 1: + code += f"38;5;{fg[0]}" + elif (isinstance(fg, list) or isinstance(fg, tuple)) and len(fg) == 3: + code += f"38;2;{';'.join((str(i) for i in fg))}" + else: + print("Expected one or three values for fg as a list") + sys.exit(1) + + if bg: + if isinstance(bg, int): + code += f"{';' if fg else ''}48;5;{bg}" + elif (isinstance(bg, list) or isinstance(bg, tuple)) and len(bg) == 1: + code += f"{';' if fg else ''}48;5;{bg[0]}" + elif (isinstance(bg, list) or isinstance(bg, tuple)) and len(bg) == 3: + code += f"{';' if fg else ''}48;2;{';'.join((str(i) for i in bg))}" + else: + print("Expected one or three values for bg as a list") + sys.exit(1) + + return code + end + a = ansi = Ansi()