refactor: change colors -> color

This commit is contained in:
Daylin Morgan 2022-09-05 13:03:53 -05:00
parent 1a894dd5ff
commit 988d6120f7
6 changed files with 33 additions and 6 deletions

View file

@ -1 +1,28 @@
# task.mk
GNU make is the task runner we love to hate, but can't escape. So let's improve the UX for users.
So I give you `task.mk`, a standalone makefile you can deploy alongside your own
`Makefile`'s to add some QOL improvements for your users and fellow maintainers.
Current Features:
- ANSI Color Support
- Formatted Help Screen
- Custom print function
Depends on `GNU Make`, obviously and `Python >=3.7`.
Wait python?!, I'm not `pip` installing some package just to parse my makefile.
I agree, so I've hacked together a file containing the bits of python we need with some tricks to run it.
## Usage
You can include this as an optional dependency on your project by adding the below lines the end of your make file.
When your users first your `make help` it will download `task.mk`.
If you intend to use any of the other features like `tprint` (see below),
I'd recommend committing `.task.mk` into version control so behavior is consistent.
```make
-include .task.mk
$(if $(filter help,$(MAKECMDGOALS)),.task.mk: ; curl -fsSL https://raw.githubusercontent.com/daylinmorgan/task.mk/22.9.5/task.mk -o .task.mk)
```

View file

@ -49,5 +49,5 @@ class Colors:
self.setcolor(name, f"\033[{byte}m")
c = colors = Colors()
c = color = Colors()
#% endblock %#

View file

@ -9,7 +9,7 @@ EPILOG ?=
# python f-string literal
define USAGE ?=
{colors.$(HEADER_COLOR)}usage{colors.end}:
{color.$(HEADER_COLOR)}usage{color.end}:
make <recipe>
endef

View file

@ -31,7 +31,7 @@ goal_len = max(len(goal[0]) for goal in goals)
for goal, msg in goals:
print(
f"{colors.$(GOAL_COLOR)}{goal:>{goal_len}}{colors.end} $(HELP_SEP) {colors.$(MSG_COLOR)}{msg}{colors.end}"
f"{color.$(GOAL_COLOR)}{goal:>{goal_len}}{color.end} $(HELP_SEP) {color.$(MSG_COLOR)}{msg}{color.end}"
)
print(f"""$(EPILOG)""")

View file

@ -9,6 +9,6 @@ codes_names = {
if attr[0:1] != "_" and attr != "end" and attr != "setcolor"
}
for code in sorted(codes_names.keys(), key=lambda item: (len(item), item)):
print("{:>20} {}".format(codes_names[code], code + "******" + colors.end))
print("{:>20} {}".format(codes_names[code], code + "******" + color.end))
#% endblock %#

View file

@ -9,10 +9,10 @@ import os
vars = "$2".split()
length = max((len(v) for v in vars))
print(f"{colors.$(HEADER_COLOR)}vars:{colors.end}\n")
print(f"{color.$(HEADER_COLOR)}vars:{color.end}\n")
for v in vars:
print(f" {colors.b_magenta}{v:<{length}}{colors.end} = {os.getenv(v)}")
print(f" {color.b_magenta}{v:<{length}}{color.end} = {os.getenv(v)}")
print()
#% endblock %#