mirror of
https://github.com/daylinmorgan/task.mk.git
synced 2024-12-22 01:50:44 -06:00
feat: use "style" not color
This commit is contained in:
parent
fff5448b60
commit
5a95a14547
7 changed files with 35 additions and 35 deletions
2
Makefile
2
Makefile
|
@ -105,7 +105,7 @@ task.mk: $(TEMPLATES) generate.py
|
||||||
./generate.py $(VERSION) > task.mk
|
./generate.py $(VERSION) > task.mk
|
||||||
|
|
||||||
define USAGE
|
define USAGE
|
||||||
{a.$(HEADER_COLOR)}usage:{a.end}
|
{a.$(HEADER_STYLE)}usage:{a.end}
|
||||||
make <recipe>
|
make <recipe>
|
||||||
|
|
||||||
Turn your {a.style('`Makefile`','b_magenta')} into
|
Turn your {a.style('`Makefile`','b_magenta')} into
|
||||||
|
|
16
README.md
16
README.md
|
@ -101,19 +101,19 @@ You can quickly customize some of the default behavior of `task.mk` by overridin
|
||||||
|
|
||||||
```make
|
```make
|
||||||
# ---- CONFIG ---- #
|
# ---- CONFIG ---- #
|
||||||
HEADER_COLOR ?= b_cyan
|
HEADER_STYLE ?= b_cyan
|
||||||
PARAMS_COLOR ?= b_magenta
|
PARAMS_STYLE ?= b_magenta
|
||||||
ACCENT_COLOR ?= b_yellow
|
ACCENT_STYLE ?= b_yellow
|
||||||
GOAL_COLOR ?= $(ACCENT_COLOR)
|
GOAL_STYLE ?= $(ACCENT_STYLE)
|
||||||
MSG_COLOR ?= faint
|
MSG_STYLE ?= faint
|
||||||
DIVIDER_COLOR ?= default
|
DIVIDER_STYLE ?= default
|
||||||
DIVIDER ?= ─
|
DIVIDER ?= ─
|
||||||
HELP_SEP ?= │
|
HELP_SEP ?= │
|
||||||
|
|
||||||
# python f-string literals
|
# python f-string literals
|
||||||
EPILOG ?=
|
EPILOG ?=
|
||||||
define USAGE ?=
|
define USAGE ?=
|
||||||
{ansi.$(HEADER_COLOR)}usage{ansi.end}:
|
{ansi.$(HEADER_STYLE)}usage{ansi.end}:
|
||||||
make <recipe>
|
make <recipe>
|
||||||
|
|
||||||
endef
|
endef
|
||||||
|
@ -122,7 +122,7 @@ endef
|
||||||
To use a custom color for one of the predefined configuration variables specify only the custom method.
|
To use a custom color for one of the predefined configuration variables specify only the custom method.
|
||||||
|
|
||||||
```make
|
```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`.
|
**NOTE**: `HELP_SEP` does not change the argument definitions syntax only the format of `make help`.
|
||||||
|
|
|
@ -23,7 +23,7 @@ addfg = lambda byte: byte + 30
|
||||||
addbg = lambda byte: byte + 40
|
addbg = lambda byte: byte + 40
|
||||||
|
|
||||||
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")
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
# ---- [config] ---- #
|
# ---- [config] ---- #
|
||||||
HEADER_COLOR ?= b_cyan
|
HEADER_STYLE ?= b_cyan
|
||||||
PARAMS_COLOR ?= b_magenta
|
ACCENT_STYLE ?= b_yellow
|
||||||
ACCENT_COLOR ?= b_yellow
|
PARAMS_STYLE ?= $(ACCENT_STYLE)
|
||||||
GOAL_COLOR ?= $(ACCENT_COLOR)
|
GOAL_STYLE ?= $(ACCENT_STYLE)
|
||||||
MSG_COLOR ?= faint
|
MSG_STYLE ?= faint
|
||||||
DIVIDER_COLOR ?= default
|
DIVIDER_STYLE ?= default
|
||||||
DIVIDER ?= ─
|
DIVIDER ?= ─
|
||||||
HELP_SEP ?= │
|
HELP_SEP ?= │
|
||||||
# python f-string literals
|
# python f-string literals
|
||||||
EPILOG ?=
|
EPILOG ?=
|
||||||
USAGE ?={ansi.$(HEADER_COLOR)}usage{ansi.end}:\n make <recipe>
|
USAGE ?={ansi.$(HEADER_STYLE)}usage{ansi.end}:\n make <recipe>
|
||||||
|
|
|
@ -51,15 +51,15 @@ def parse_make(file):
|
||||||
|
|
||||||
def print_goal(goal, msg, max_goal_len):
|
def print_goal(goal, msg, max_goal_len):
|
||||||
print(
|
print(
|
||||||
ansi.style(f" {goal:>{max_goal_len}}", "$(GOAL_COLOR)")
|
ansi.style(f" {goal:>{max_goal_len}}", "$(GOAL_STYLE)")
|
||||||
+ " $(HELP_SEP) "
|
+ " $(HELP_SEP) "
|
||||||
+ ansi.style(msg, "$(MSG_COLOR)")
|
+ ansi.style(msg, "$(MSG_STYLE)")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def print_rawmsg(msg, argstr, maxlens):
|
def print_rawmsg(msg, argstr, maxlens):
|
||||||
args = rawargs(argstr)
|
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:
|
if not os.getenv("SHOW_HIDDEN") and args.hidden:
|
||||||
return
|
return
|
||||||
if msg:
|
if msg:
|
||||||
|
@ -75,7 +75,7 @@ def print_rawmsg(msg, argstr, maxlens):
|
||||||
print(
|
print(
|
||||||
ansi.style(
|
ansi.style(
|
||||||
f" {'$(DIVIDER)'*(len('$(HELP_SEP)')+sum(maxlens)+2)}",
|
f" {'$(DIVIDER)'*(len('$(HELP_SEP)')+sum(maxlens)+2)}",
|
||||||
"$(DIVIDER_COLOR)",
|
"$(DIVIDER_STYLE)",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if args.whitespace:
|
if args.whitespace:
|
||||||
|
|
|
@ -8,7 +8,7 @@ import os
|
||||||
vars = "$2".split()
|
vars = "$2".split()
|
||||||
length = max((len(v) for v in vars))
|
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:
|
for v in vars:
|
||||||
print(f" {ansi.b_magenta}{v:<{length}}{ansi.end} = {os.getenv(v)}")
|
print(f" {ansi.b_magenta}{v:<{length}}{ansi.end} = {os.getenv(v)}")
|
||||||
|
|
26
task.mk
26
task.mk
|
@ -1,23 +1,23 @@
|
||||||
# }> [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-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`
|
# 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.
|
||||||
# You can update your .task.mk with `make _update-task.mk`
|
# You can update your .task.mk with `make _update-task.mk`
|
||||||
# ---- [config] ---- #
|
# ---- [config] ---- #
|
||||||
HEADER_COLOR ?= b_cyan
|
HEADER_STYLE ?= b_cyan
|
||||||
PARAMS_COLOR ?= b_magenta
|
ACCENT_STYLE ?= b_yellow
|
||||||
ACCENT_COLOR ?= b_yellow
|
PARAMS_STYLE ?= $(ACCENT_STYLE)
|
||||||
GOAL_COLOR ?= $(ACCENT_COLOR)
|
GOAL_STYLE ?= $(ACCENT_STYLE)
|
||||||
MSG_COLOR ?= faint
|
MSG_STYLE ?= faint
|
||||||
DIVIDER_COLOR ?= default
|
DIVIDER_STYLE ?= default
|
||||||
DIVIDER ?= ─
|
DIVIDER ?= ─
|
||||||
HELP_SEP ?= │
|
HELP_SEP ?= │
|
||||||
# python f-string literals
|
# python f-string literals
|
||||||
EPILOG ?=
|
EPILOG ?=
|
||||||
USAGE ?={ansi.$(HEADER_COLOR)}usage{ansi.end}:\n make <recipe>
|
USAGE ?={ansi.$(HEADER_STYLE)}usage{ansi.end}:\n make <recipe>
|
||||||
# ---- [buitlin recipes] ---- #
|
# ---- [buitlin recipes] ---- #
|
||||||
## h, help | show this help
|
## h, help | show this help
|
||||||
.PHONY: help h
|
.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}
|
yield {k: v for k, v in match.groupdict().items() if v is not None}
|
||||||
def print_goal(goal, msg, max_goal_len):
|
def print_goal(goal, msg, max_goal_len):
|
||||||
print(
|
print(
|
||||||
ansi.style(f" {goal:>{max_goal_len}}", "$(GOAL_COLOR)")
|
ansi.style(f" {goal:>{max_goal_len}}", "$(GOAL_STYLE)")
|
||||||
+ " $(HELP_SEP) "
|
+ " $(HELP_SEP) "
|
||||||
+ ansi.style(msg, "$(MSG_COLOR)")
|
+ ansi.style(msg, "$(MSG_STYLE)")
|
||||||
)
|
)
|
||||||
def print_rawmsg(msg, argstr, maxlens):
|
def print_rawmsg(msg, argstr, maxlens):
|
||||||
args = rawargs(argstr)
|
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:
|
if not os.getenv("SHOW_HIDDEN") and args.hidden:
|
||||||
return
|
return
|
||||||
if msg:
|
if msg:
|
||||||
|
@ -130,7 +130,7 @@ def print_rawmsg(msg, argstr, maxlens):
|
||||||
print(
|
print(
|
||||||
ansi.style(
|
ansi.style(
|
||||||
f" {'$(DIVIDER)'*(len('$(HELP_SEP)')+sum(maxlens)+2)}",
|
f" {'$(DIVIDER)'*(len('$(HELP_SEP)')+sum(maxlens)+2)}",
|
||||||
"$(DIVIDER_COLOR)",
|
"$(DIVIDER_STYLE)",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if args.whitespace:
|
if args.whitespace:
|
||||||
|
@ -238,7 +238,7 @@ import os
|
||||||
$(ansi_py)
|
$(ansi_py)
|
||||||
vars = "$2".split()
|
vars = "$2".split()
|
||||||
length = max((len(v) for v in vars))
|
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:
|
for v in vars:
|
||||||
print(f" {ansi.b_magenta}{v:<{length}}{ansi.end} = {os.getenv(v)}")
|
print(f" {ansi.b_magenta}{v:<{length}}{ansi.end} = {os.getenv(v)}")
|
||||||
print()
|
print()
|
||||||
|
|
Loading…
Reference in a new issue