From 988d6120f7f2b2c3a07791e13ee76833f7d0e954 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Mon, 5 Sep 2022 13:03:53 -0500 Subject: [PATCH] refactor: change colors -> color --- README.md | 27 +++++++++++++++++++++++++++ src/color.py | 2 +- src/config.mk | 2 +- src/help.py | 2 +- src/print-colors.py | 2 +- src/vars.py | 4 ++-- 6 files changed, 33 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8c7a00d..e19851f 100644 --- a/README.md +++ b/README.md @@ -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) +``` diff --git a/src/color.py b/src/color.py index 5b5d53d..d11f289 100644 --- a/src/color.py +++ b/src/color.py @@ -49,5 +49,5 @@ class Colors: self.setcolor(name, f"\033[{byte}m") -c = colors = Colors() +c = color = Colors() #% endblock %# diff --git a/src/config.mk b/src/config.mk index 0ea3c21..baa9150 100644 --- a/src/config.mk +++ b/src/config.mk @@ -9,7 +9,7 @@ EPILOG ?= # python f-string literal define USAGE ?= -{colors.$(HEADER_COLOR)}usage{colors.end}: +{color.$(HEADER_COLOR)}usage{color.end}: make endef diff --git a/src/help.py b/src/help.py index 99e41af..4d1d91b 100644 --- a/src/help.py +++ b/src/help.py @@ -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)""") diff --git a/src/print-colors.py b/src/print-colors.py index c8c0c39..a9099ea 100644 --- a/src/print-colors.py +++ b/src/print-colors.py @@ -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 %# diff --git a/src/vars.py b/src/vars.py index 33ab0fb..630a0e4 100644 --- a/src/vars.py +++ b/src/vars.py @@ -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 %#