build: bump task.mk version

This commit is contained in:
Daylin Morgan 2023-01-19 13:46:41 -06:00
parent 2b201ce570
commit a433539ba9
2 changed files with 57 additions and 13 deletions

View file

@ -1,7 +1,7 @@
# }> [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.28-dev # version: 23.1.1
# #
# 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.
@ -27,7 +27,7 @@ ifeq (help,$(firstword $(MAKECMDGOALS)))
endif endif
## h, help | show this help ## h, help | show this help
h help: h help:
$(call py,help_py) || { echo "exiting early!"; exit 1; } $(call py,help_py)
_help: export SHOW_HIDDEN=true _help: export SHOW_HIDDEN=true
_help: help _help: help
ifdef PRINT_VARS ifdef PRINT_VARS
@ -64,7 +64,7 @@ _escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1))
_escape_printf = $(subst \,\\,$(subst %,%%,$1)) _escape_printf = $(subst \,\\,$(subst %,%%,$1))
_create_string = $(subst $(_newline),\n,$(call _escape_shellstring,$(call _escape_printf,$1))) _create_string = $(subst $(_newline),\n,$(call _escape_shellstring,$(call _escape_printf,$1)))
_printline = printf -- "<----------------------------------->\n" _printline = printf -- "<----------------------------------->\n"
ifdef DEBUG ifdef TASKMK_DEBUG
define _debug_runner define _debug_runner
@printf "$(1) Script:\n";$(_printline); @printf "$(1) Script:\n";$(_printline);
@printf "$(call _create_string,$(3))\n" | cat -n @printf "$(call _create_string,$(3))\n" | cat -n
@ -88,9 +88,31 @@ import subprocess
import sys import sys
from textwrap import wrap from textwrap import wrap
$(utils_py) $(utils_py)
a = ansi = Ansi(target="stdout")
MaxLens = namedtuple("MaxLens", "goal msg") MaxLens = namedtuple("MaxLens", "goal msg")
pattern = re.compile( pattern = re.compile(
r"^## (?P<goal>.*?) \| (?P<msg>.*?)(?:\s?\| args: (?P<msgargs>.*?))?$$|^### (?P<rawmsg>.*?)?(?:\s?\| args: (?P<rawargs>.*?))?$$" r"""
^\#\#\
(?P<goal>.*?)\s?\|\s?(?P<msg>.*?)
\s?
(?:
(?:\|\s?args:\s?|\|>)
\s?
(?P<msgargs>.*?)
)?
$$
|
^\#\#\#\
(?P<rawmsg>.*?)
\s?
(?:
(?:\|\s?args:|\|\>)
\s?
(?P<rawargs>.*?)
)?
$$
""",
re.X,
) )
goal_pattern = re.compile(r"""^(?!#|\t)(.*):.*\n\t""", re.MULTILINE) goal_pattern = re.compile(r"""^(?!#|\t)(.*):.*\n\t""", re.MULTILINE)
def parseargs(argstring): def parseargs(argstring):
@ -228,12 +250,12 @@ def print_help():
def print_arg_help(help_args): def print_arg_help(help_args):
print(f"{ansi.style('task.mk recipe help','header')}\n") print(f"{ansi.style('task.mk recipe help','header')}\n")
for arg in help_args.split(): for arg in help_args.split():
print("\n".join(parse_goal(gen_makefile(), arg))) print("\n".join((*parse_goal(gen_makefile(), arg), "\n")))
print()
def main(): def main():
help_args = os.getenv("HELP_ARGS") help_args = os.getenv("HELP_ARGS")
if help_args: if help_args:
print_arg_help(help_args) print_arg_help(help_args)
print(f"{ansi.faint}exiting task.mk{ansi.end}")
sys.exit(1) sys.exit(1)
else: else:
print_help() print_help()
@ -246,14 +268,30 @@ sys.stderr.write(f"""$(2)\n""")
endef endef
define print_ansi_py define print_ansi_py
$(utils_py) $(utils_py)
sep = f"$(HELP_SEP)" import sys
codes_names = {getattr(ansi, attr): attr for attr in ansi.__dict__} codes_names = {
getattr(ansi, attr): attr
for attr in ansi.__dict__
if attr
not in [
"target",
"header",
"accent",
"params",
"goal",
"msg",
"div_style",
]
}
for code in sorted(codes_names.keys(), key=lambda item: (len(item), item)): for code in sorted(codes_names.keys(), key=lambda item: (len(item), item)):
print(f"{codes_names[code]:>20} {sep} {code+'*****'+ansi.end} {sep} {repr(code)}") sys.stderr.write(
f"{codes_names[code]:>20} {cfg.sep} {code+'*****'+ansi.end} {cfg.sep} {repr(code)}\n"
)
endef endef
define vars_py define vars_py
import os import os
$(utils_py) $(utils_py)
ansi = Ansi(target="stdout")
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}vars{ansi.end}:\n") print(f"{ansi.header}vars{ansi.end}:\n")
@ -272,7 +310,8 @@ def confirm():
""" """
answer = "" answer = ""
while answer not in ["y", "n"]: while answer not in ["y", "n"]:
answer = input(f"""$(2) {a.b_red}[Y/n]{a.end} """).lower() sys.stderr.write(f"""$(2) {a.b_red}[Y/n]{a.end} \n""")
answer = input().lower()
return answer == "y" return answer == "y"
if confirm(): if confirm():
sys.exit() sys.exit()
@ -307,7 +346,8 @@ addfg = lambda byte: byte + 30
addbg = lambda byte: byte + 40 addbg = lambda byte: byte + 40
class Ansi: class Ansi:
"""ANSI escape codes""" """ANSI escape codes"""
def __init__(self): def __init__(self, target="stdout"):
self.target = target
self.setcode("end", "\033[0m") self.setcode("end", "\033[0m")
self.setcode("default", "\033[38m") self.setcode("default", "\033[38m")
self.setcode("bg_default", "\033[48m") self.setcode("bg_default", "\033[48m")
@ -324,7 +364,11 @@ class Ansi:
self.add_cfg() self.add_cfg()
def setcode(self, name, escape_code): def setcode(self, name, escape_code):
"""create attr for style and escape code""" """create attr for style and escape code"""
if not sys.stdout.isatty() or os.getenv("NO_COLOR", False): if os.getenv("NO_COLOR", False):
setattr(self, name, "")
elif (self.target == "stderr" and not sys.stderr.isatty()) or (
self.target == "stdout" and not sys.stdout.isatty()
):
setattr(self, name, "") setattr(self, name, "")
else: else:
setattr(self, name, escape_code) setattr(self, name, escape_code)

View file

@ -4,7 +4,7 @@ ARGS ?= -c
NF_SRC := $(shell ./bin/get-font-files src) NF_SRC := $(shell ./bin/get-font-files src)
FONT_FLAGS := $(shell ./bin/get-font-files MonoLisa 'otf,ttf,woff,woff2') FONT_FLAGS := $(shell ./bin/get-font-files MonoLisa 'otf,ttf,woff,woff2')
## patch | apply nerd fonts patch ## patch | apply nerd fonts patch |> -gs b_magenta -ms bold
patch: ./bin/font-patcher patch: ./bin/font-patcher
@./bin/patch-monolisa \ @./bin/patch-monolisa \
$(FONT_FLAGS) \ $(FONT_FLAGS) \