From 5a95a14547b9d5d11bcc1964dd30ceb45a783aa3 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Fri, 16 Sep 2022 13:26:31 -0500 Subject: [PATCH] feat: use "style" not color --- Makefile | 2 +- README.md | 16 ++++++++-------- src/ansi.py | 2 +- src/config.mk | 14 +++++++------- src/help.py | 8 ++++---- src/vars.py | 2 +- task.mk | 26 +++++++++++++------------- 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index 32a4e6b..5bac402 100644 --- a/Makefile +++ b/Makefile @@ -105,7 +105,7 @@ task.mk: $(TEMPLATES) generate.py ./generate.py $(VERSION) > task.mk define USAGE -{a.$(HEADER_COLOR)}usage:{a.end} +{a.$(HEADER_STYLE)}usage:{a.end} make Turn your {a.style('`Makefile`','b_magenta')} into diff --git a/README.md b/README.md index 2382833..be03a46 100644 --- a/README.md +++ b/README.md @@ -101,19 +101,19 @@ You can quickly customize some of the default behavior of `task.mk` by overridin ```make # ---- CONFIG ---- # -HEADER_COLOR ?= b_cyan -PARAMS_COLOR ?= b_magenta -ACCENT_COLOR ?= b_yellow -GOAL_COLOR ?= $(ACCENT_COLOR) -MSG_COLOR ?= faint -DIVIDER_COLOR ?= default +HEADER_STYLE ?= b_cyan +PARAMS_STYLE ?= b_magenta +ACCENT_STYLE ?= b_yellow +GOAL_STYLE ?= $(ACCENT_STYLE) +MSG_STYLE ?= faint +DIVIDER_STYLE ?= default DIVIDER ?= ─ HELP_SEP ?= │ # python f-string literals EPILOG ?= define USAGE ?= -{ansi.$(HEADER_COLOR)}usage{ansi.end}: +{ansi.$(HEADER_STYLE)}usage{ansi.end}: make endef @@ -122,7 +122,7 @@ endef To use a custom color for one of the predefined configuration variables specify only the custom method. ```make -HEADER_COLOR = custom(fg=171,bg=227) +HEADER_STYLE = custom(fg=171,bg=227) ``` **NOTE**: `HELP_SEP` does not change the argument definitions syntax only the format of `make help`. diff --git a/src/ansi.py b/src/ansi.py index 079e908..c6ae771 100644 --- a/src/ansi.py +++ b/src/ansi.py @@ -23,7 +23,7 @@ addfg = lambda byte: byte + 30 addbg = lambda byte: byte + 40 class Ansi: - """ANSI color codes""" + """ANSI escape codes""" def __init__(self): self.setcode("end", "\033[0m") diff --git a/src/config.mk b/src/config.mk index 8667777..7018f76 100644 --- a/src/config.mk +++ b/src/config.mk @@ -1,12 +1,12 @@ # ---- [config] ---- # -HEADER_COLOR ?= b_cyan -PARAMS_COLOR ?= b_magenta -ACCENT_COLOR ?= b_yellow -GOAL_COLOR ?= $(ACCENT_COLOR) -MSG_COLOR ?= faint -DIVIDER_COLOR ?= default +HEADER_STYLE ?= b_cyan +ACCENT_STYLE ?= b_yellow +PARAMS_STYLE ?= $(ACCENT_STYLE) +GOAL_STYLE ?= $(ACCENT_STYLE) +MSG_STYLE ?= faint +DIVIDER_STYLE ?= default DIVIDER ?= ─ HELP_SEP ?= │ # python f-string literals EPILOG ?= -USAGE ?={ansi.$(HEADER_COLOR)}usage{ansi.end}:\n make +USAGE ?={ansi.$(HEADER_STYLE)}usage{ansi.end}:\n make diff --git a/src/help.py b/src/help.py index 6a96094..4617415 100644 --- a/src/help.py +++ b/src/help.py @@ -51,15 +51,15 @@ def parse_make(file): def print_goal(goal, msg, max_goal_len): print( - ansi.style(f" {goal:>{max_goal_len}}", "$(GOAL_COLOR)") + ansi.style(f" {goal:>{max_goal_len}}", "$(GOAL_STYLE)") + " $(HELP_SEP) " - + ansi.style(msg, "$(MSG_COLOR)") + + ansi.style(msg, "$(MSG_STYLE)") ) def print_rawmsg(msg, argstr, maxlens): args = rawargs(argstr) - msg_style = args.msg_style if args.msg_style else "$(MSG_COLOR)" + msg_style = args.msg_style if args.msg_style else "$(MSG_STYLE)" if not os.getenv("SHOW_HIDDEN") and args.hidden: return if msg: @@ -75,7 +75,7 @@ def print_rawmsg(msg, argstr, maxlens): print( ansi.style( f" {'$(DIVIDER)'*(len('$(HELP_SEP)')+sum(maxlens)+2)}", - "$(DIVIDER_COLOR)", + "$(DIVIDER_STYLE)", ) ) if args.whitespace: diff --git a/src/vars.py b/src/vars.py index 00222a5..9585981 100644 --- a/src/vars.py +++ b/src/vars.py @@ -8,7 +8,7 @@ import os vars = "$2".split() length = max((len(v) for v in vars)) -print(f"{ansi.$(HEADER_COLOR)}vars:{ansi.end}\n") +print(f"{ansi.$(HEADER_STYLE)}vars:{ansi.end}\n") for v in vars: print(f" {ansi.b_magenta}{v:<{length}}{ansi.end} = {os.getenv(v)}") diff --git a/task.mk b/task.mk index 5257b18..54ca9ff 100644 --- a/task.mk +++ b/task.mk @@ -1,23 +1,23 @@ # }> [github.com/daylinmorgan/task.mk] <{ # # Copyright (c) 2022 Daylin Morgan # MIT License -# version: v22.9.14-10-g2e4a82a-dev +# version: v22.9.14-11-gfff5448-dev # # 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. # You can update your .task.mk with `make _update-task.mk` # ---- [config] ---- # -HEADER_COLOR ?= b_cyan -PARAMS_COLOR ?= b_magenta -ACCENT_COLOR ?= b_yellow -GOAL_COLOR ?= $(ACCENT_COLOR) -MSG_COLOR ?= faint -DIVIDER_COLOR ?= default +HEADER_STYLE ?= b_cyan +ACCENT_STYLE ?= b_yellow +PARAMS_STYLE ?= $(ACCENT_STYLE) +GOAL_STYLE ?= $(ACCENT_STYLE) +MSG_STYLE ?= faint +DIVIDER_STYLE ?= default DIVIDER ?= ─ HELP_SEP ?= │ # python f-string literals EPILOG ?= -USAGE ?={ansi.$(HEADER_COLOR)}usage{ansi.end}:\n make +USAGE ?={ansi.$(HEADER_STYLE)}usage{ansi.end}:\n make # ---- [buitlin recipes] ---- # ## h, help | show this help .PHONY: help h @@ -108,13 +108,13 @@ def parse_make(file): yield {k: v for k, v in match.groupdict().items() if v is not None} def print_goal(goal, msg, max_goal_len): print( - ansi.style(f" {goal:>{max_goal_len}}", "$(GOAL_COLOR)") + ansi.style(f" {goal:>{max_goal_len}}", "$(GOAL_STYLE)") + " $(HELP_SEP) " - + ansi.style(msg, "$(MSG_COLOR)") + + ansi.style(msg, "$(MSG_STYLE)") ) def print_rawmsg(msg, argstr, maxlens): args = rawargs(argstr) - msg_style = args.msg_style if args.msg_style else "$(MSG_COLOR)" + msg_style = args.msg_style if args.msg_style else "$(MSG_STYLE)" if not os.getenv("SHOW_HIDDEN") and args.hidden: return if msg: @@ -130,7 +130,7 @@ def print_rawmsg(msg, argstr, maxlens): print( ansi.style( f" {'$(DIVIDER)'*(len('$(HELP_SEP)')+sum(maxlens)+2)}", - "$(DIVIDER_COLOR)", + "$(DIVIDER_STYLE)", ) ) if args.whitespace: @@ -238,7 +238,7 @@ import os $(ansi_py) vars = "$2".split() length = max((len(v) for v in vars)) -print(f"{ansi.$(HEADER_COLOR)}vars:{ansi.end}\n") +print(f"{ansi.$(HEADER_STYLE)}vars:{ansi.end}\n") for v in vars: print(f" {ansi.b_magenta}{v:<{length}}{ansi.end} = {os.getenv(v)}") print()