mirror of
https://github.com/daylinmorgan/task.mk.git
synced 2024-11-09 19:13:14 -06:00
Compare commits
No commits in common. "18ff88b714ebeb581abb239e52f40c74ad7c26a0" and "c3fa7cd8fc4b85135948bf34ef7680a695e142aa" have entirely different histories.
18ff88b714
...
c3fa7cd8fc
13 changed files with 239 additions and 146 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_STYLE)}usage:{a.end}
|
{a.$(HEADER_COLOR)}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_STYLE ?= b_cyan
|
HEADER_COLOR ?= b_cyan
|
||||||
PARAMS_STYLE ?= b_magenta
|
PARAMS_COLOR ?= b_magenta
|
||||||
ACCENT_STYLE ?= b_yellow
|
ACCENT_COLOR ?= b_yellow
|
||||||
GOAL_STYLE ?= $(ACCENT_STYLE)
|
GOAL_COLOR ?= $(ACCENT_COLOR)
|
||||||
MSG_STYLE ?= faint
|
MSG_COLOR ?= faint
|
||||||
DIVIDER_STYLE ?= default
|
DIVIDER_COLOR ?= default
|
||||||
DIVIDER ?= ─
|
DIVIDER ?= ─
|
||||||
HELP_SEP ?= │
|
HELP_SEP ?= │
|
||||||
|
|
||||||
# python f-string literals
|
# python f-string literals
|
||||||
EPILOG ?=
|
EPILOG ?=
|
||||||
define USAGE ?=
|
define USAGE ?=
|
||||||
{ansi.$(HEADER_STYLE)}usage{ansi.end}:
|
{ansi.$(HEADER_COLOR)}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_STYLE = custom(fg=171,bg=227)
|
HEADER_COLOR = 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`.
|
||||||
|
|
12
generate.py
12
generate.py
|
@ -5,7 +5,7 @@ from pathlib import Path
|
||||||
|
|
||||||
import jinja2
|
import jinja2
|
||||||
|
|
||||||
py_script_names = ["help", "ansi", "info", "print-ansi", "vars", "confirm"]
|
py_script_names = ["help", "ansi", "info", "print-ansi", "vars","confirm"]
|
||||||
|
|
||||||
|
|
||||||
def get_jinja_env():
|
def get_jinja_env():
|
||||||
|
@ -16,8 +16,6 @@ def get_jinja_env():
|
||||||
block_end_string="%#",
|
block_end_string="%#",
|
||||||
variable_start_string="##-",
|
variable_start_string="##-",
|
||||||
variable_end_string="-##",
|
variable_end_string="-##",
|
||||||
comment_start_string="###-",
|
|
||||||
comment_end_string="-###",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,10 +24,6 @@ def render(env, template, **kwargs):
|
||||||
return template.render(**kwargs)
|
return template.render(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
def dropnewlines(text):
|
|
||||||
return "\n".join([line for line in text.splitlines() if line])
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) == 2:
|
if len(sys.argv) == 2:
|
||||||
version = sys.argv[1]
|
version = sys.argv[1]
|
||||||
|
@ -37,7 +31,9 @@ def main():
|
||||||
version = "dev"
|
version = "dev"
|
||||||
|
|
||||||
env = get_jinja_env()
|
env = get_jinja_env()
|
||||||
py_scripts = [dropnewlines(render(env, f"{name}.py")) for name in py_script_names]
|
|
||||||
|
py_scripts = [render(env, f"{name}.py") for name in py_script_names]
|
||||||
|
|
||||||
print(render(env, "task.mk", py_scripts=py_scripts, version=version))
|
print(render(env, "task.mk", py_scripts=py_scripts, version=version))
|
||||||
|
|
||||||
|
|
||||||
|
|
23
src/ansi.py
23
src/ansi.py
|
@ -19,25 +19,28 @@ state2byte = dict(
|
||||||
bold=1, faint=2, italic=3, underline=4, blink=5, fast_blink=6, crossed=9
|
bold=1, faint=2, italic=3, underline=4, blink=5, fast_blink=6, crossed=9
|
||||||
)
|
)
|
||||||
|
|
||||||
addfg = lambda byte: byte + 30
|
|
||||||
addbg = lambda byte: byte + 40
|
def fg(byte):
|
||||||
|
return 30 + byte
|
||||||
|
|
||||||
|
|
||||||
|
def bg(byte):
|
||||||
|
return 40 + byte
|
||||||
|
|
||||||
|
|
||||||
class Ansi:
|
class Ansi:
|
||||||
"""ANSI escape codes"""
|
"""ANSI color codes"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
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")
|
||||||
for name, byte in color2byte.items():
|
for name, byte in color2byte.items():
|
||||||
self.setcode(name, f"\033[{addfg(byte)}m")
|
self.setcode(name, f"\033[{fg(byte)}m")
|
||||||
self.setcode(f"b_{name}", f"\033[1;{addfg(byte)}m")
|
self.setcode(f"b_{name}", f"\033[1;{fg(byte)}m")
|
||||||
self.setcode(f"d_{name}", f"\033[2;{addfg(byte)}m")
|
self.setcode(f"d_{name}", f"\033[2;{fg(byte)}m")
|
||||||
for bgname, bgbyte in color2byte.items():
|
for bgname, bgbyte in color2byte.items():
|
||||||
self.setcode(
|
self.setcode(f"{name}_on_{bgname}", f"\033[{bg(bgbyte)};{fg(byte)}m")
|
||||||
f"{name}_on_{bgname}", f"\033[{addbg(bgbyte)};{addfg(byte)}m"
|
|
||||||
)
|
|
||||||
for name, byte in state2byte.items():
|
for name, byte in state2byte.items():
|
||||||
self.setcode(name, f"\033[{byte}m")
|
self.setcode(name, f"\033[{byte}m")
|
||||||
|
|
||||||
|
@ -79,7 +82,7 @@ class Ansi:
|
||||||
|
|
||||||
def style(self, text, style):
|
def style(self, text, style):
|
||||||
if style not in self.__dict__:
|
if style not in self.__dict__:
|
||||||
print(f"unknown style: {style}")
|
print(f"unknown style {style}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
return f"{self.__dict__[style]}{text}{self.__dict__['end']}"
|
return f"{self.__dict__[style]}{text}{self.__dict__['end']}"
|
||||||
|
|
|
@ -1,29 +1,40 @@
|
||||||
# ---- [buitlin recipes] ---- #
|
# ---- [buitlin recipes] ---- #
|
||||||
|
|
||||||
## h, help | show this help
|
## h, help | show this help
|
||||||
.PHONY: help h
|
.PHONY: help h
|
||||||
help h:
|
help h:
|
||||||
$(call py,help_py)
|
$(call py,help_py)
|
||||||
|
|
||||||
.PHONY: _help
|
.PHONY: _help
|
||||||
_help: export SHOW_HIDDEN=true
|
_help: export SHOW_HIDDEN=true
|
||||||
_help: help
|
_help: help
|
||||||
|
|
||||||
ifdef PRINT_VARS
|
ifdef PRINT_VARS
|
||||||
|
|
||||||
$(foreach v,$(PRINT_VARS),$(eval export $(v)))
|
$(foreach v,$(PRINT_VARS),$(eval export $(v)))
|
||||||
|
|
||||||
.PHONY: vars v
|
.PHONY: vars v
|
||||||
vars v:
|
vars v:
|
||||||
$(call py,vars_py,$(PRINT_VARS))
|
$(call py,vars_py,$(PRINT_VARS))
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### | args: -ws --hidden
|
### | args: -ws --hidden
|
||||||
### task.mk builtins: | args: -d --hidden
|
### task.mk builtins: | args: -d --hidden
|
||||||
## _print-ansi | show all possible ansi color code combinations
|
## _print-ansi | show all possible ansi color code combinations
|
||||||
.PHONY:
|
.PHONY:
|
||||||
_print-ansi:
|
_print-ansi:
|
||||||
$(call py,print_ansi_py)
|
$(call py,print_ansi_py)
|
||||||
|
|
||||||
# functions to take f-string literals and pass to python print
|
# functions to take f-string literals and pass to python print
|
||||||
tprint = $(call py,info_py,$(1))
|
tprint = $(call py,info_py,$(1))
|
||||||
tprint-sh = $(call pysh,info_py,$(1))
|
tprint-sh = $(call pysh,info_py,$(1))
|
||||||
|
|
||||||
tconfirm = $(call py,confirm_py,$(1))
|
tconfirm = $(call py,confirm_py,$(1))
|
||||||
|
|
||||||
## _update-task.mk | downloads latest development version of task.mk
|
## _update-task.mk | downloads latest development version of task.mk
|
||||||
_update-task.mk:
|
_update-task.mk:
|
||||||
$(call tprint,{a.b_cyan}Updating task.mk{a.end})
|
$(call tprint,{a.b_cyan}Updating task.mk{a.end})
|
||||||
curl https://raw.githubusercontent.com/daylinmorgan/task.mk/main/task.mk -o .task.mk
|
curl https://raw.githubusercontent.com/daylinmorgan/task.mk/main/task.mk -o .task.mk
|
||||||
|
|
||||||
export MAKEFILE_LIST
|
export MAKEFILE_LIST
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
# ---- [config] ---- #
|
# ---- CONFIG ---- #
|
||||||
HEADER_STYLE ?= b_cyan
|
HEADER_COLOR ?= b_cyan
|
||||||
ACCENT_STYLE ?= b_yellow
|
PARAMS_COLOR ?= b_magenta
|
||||||
PARAMS_STYLE ?= $(ACCENT_STYLE)
|
ACCENT_COLOR ?= b_yellow
|
||||||
GOAL_STYLE ?= $(ACCENT_STYLE)
|
GOAL_COLOR ?= $(ACCENT_COLOR)
|
||||||
MSG_STYLE ?= faint
|
MSG_COLOR ?= faint
|
||||||
DIVIDER_STYLE ?= default
|
DIVIDER_COLOR ?= default
|
||||||
DIVIDER ?= ─
|
DIVIDER ?= ─
|
||||||
HELP_SEP ?= │
|
HELP_SEP ?= │
|
||||||
|
|
||||||
# python f-string literals
|
# python f-string literals
|
||||||
EPILOG ?=
|
EPILOG ?=
|
||||||
USAGE ?={ansi.$(HEADER_STYLE)}usage{ansi.end}:\n make <recipe>
|
define USAGE ?=
|
||||||
|
{ansi.$(HEADER_COLOR)}usage{ansi.end}:
|
||||||
|
make <recipe>
|
||||||
|
|
||||||
|
endef
|
||||||
|
|
|
@ -3,10 +3,8 @@
|
||||||
#% block script %#
|
#% block script %#
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
##- '$(ansi_py)' -##
|
##- '$(ansi_py)' -##
|
||||||
|
|
||||||
|
|
||||||
def confirm():
|
def confirm():
|
||||||
"""
|
"""
|
||||||
Ask user to enter Y or N (case-insensitive).
|
Ask user to enter Y or N (case-insensitive).
|
||||||
|
@ -18,7 +16,6 @@ def confirm():
|
||||||
answer = input(f"""$(2) {a.b_red}[Y/n]{a.end} """).lower()
|
answer = input(f"""$(2) {a.b_red}[Y/n]{a.end} """).lower()
|
||||||
return answer == "y"
|
return answer == "y"
|
||||||
|
|
||||||
|
|
||||||
if confirm():
|
if confirm():
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
else:
|
else:
|
||||||
|
|
61
src/help.py
61
src/help.py
|
@ -5,25 +5,27 @@ import argparse
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
##- '$(ansi_py)' -##
|
##- '$(ansi_py)' -##
|
||||||
|
|
||||||
|
ansi: Any
|
||||||
|
|
||||||
MaxLens = namedtuple("MaxLens", "goal msg")
|
MaxLens = namedtuple("MaxLens", "goal msg")
|
||||||
|
|
||||||
###- double dollar signs to prevent make escaping them -###
|
# double dollar signs to prevent make escaping them
|
||||||
pattern = re.compile(
|
pattern = re.compile(
|
||||||
r"^## (?P<goal>.*?) \| (?P<msg>.*?)(?:\s?\| args: (?P<msgargs>.*?))?$$|^### (?P<rawmsg>.*?)?(?:\s?\| args: (?P<rawargs>.*?))?$$"
|
r"^## (?P<goal>.*) \| (?P<msg>.*)|^### (?P<rawmsg>.*?)?(?:\s?\| args: (?P<args>.*?))?$$"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def parseargs(argstring):
|
def rawargs(argstring):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("--align")
|
parser.add_argument("--align")
|
||||||
parser.add_argument("-d", "--divider", action="store_true")
|
parser.add_argument("-d", "--divider", action="store_true")
|
||||||
parser.add_argument("-ws", "--whitespace", action="store_true")
|
parser.add_argument("-ws", "--whitespace", action="store_true")
|
||||||
parser.add_argument("-ms", "--msg-style", type=str)
|
parser.add_argument("-ms", "--msg-style", type=str)
|
||||||
parser.add_argument("-gs", "--goal-style", type=str)
|
parser.add_argument("--hidden",action="store_true")
|
||||||
parser.add_argument("--hidden", action="store_true")
|
|
||||||
return parser.parse_args(argstring.split())
|
return parser.parse_args(argstring.split())
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,63 +49,54 @@ 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 fmt_goal(goal, msg, max_goal_len, argstr):
|
def print_goal(goal, msg, max_goal_len):
|
||||||
args = parseargs(argstr)
|
print(
|
||||||
goal_style = args.goal_style.strip() if args.goal_style else "$(GOAL_STYLE)"
|
ansi.style(f" {goal:>{max_goal_len}}", "$(GOAL_COLOR)")
|
||||||
msg_style = args.msg_style.strip() if args.msg_style else "$(MSG_STYLE)"
|
|
||||||
return (
|
|
||||||
ansi.style(f" {goal:>{max_goal_len}}", goal_style)
|
|
||||||
+ " $(HELP_SEP) "
|
+ " $(HELP_SEP) "
|
||||||
+ ansi.style(msg, msg_style)
|
+ ansi.style(msg, "$(MSG_COLOR)")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def fmt_rawmsg(msg, argstr, maxlens):
|
def print_rawmsg(msg, argstr, maxlens):
|
||||||
args = parseargs(argstr)
|
args = rawargs(argstr)
|
||||||
lines = []
|
msg_style = args.msg_style if args.msg_style else "$(MSG_COLOR)"
|
||||||
msg_style = args.msg_style.strip() 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:
|
||||||
if args.align == "sep":
|
if args.align == "sep":
|
||||||
lines.append(
|
print(
|
||||||
f"{' '*(maxlens.goal+len('$(HELP_SEP)')+4)}{ansi.style(msg,msg_style)}"
|
f"{' '*(maxlens.goal+len('$(HELP_SEP)')+4)}{ansi.style(msg,msg_style)}"
|
||||||
)
|
)
|
||||||
elif args.align == "center":
|
elif args.align == "center":
|
||||||
lines.append(f" {ansi.style(msg.center(sum(maxlens)),msg_style)}")
|
print(f" {ansi.style(msg.center(sum(maxlens)),msg_style)}")
|
||||||
else:
|
else:
|
||||||
lines.append(f" {ansi.style(msg,msg_style)}")
|
print(f" {ansi.style(msg,msg_style)}")
|
||||||
if args.divider:
|
if args.divider:
|
||||||
lines.append(
|
print(
|
||||||
ansi.style(
|
ansi.style(
|
||||||
f" {'$(DIVIDER)'*(len('$(HELP_SEP)')+sum(maxlens)+2)}",
|
f" {'$(DIVIDER)'*(len('$(HELP_SEP)')+sum(maxlens)+2)}",
|
||||||
"$(DIVIDER_STYLE)",
|
"$(DIVIDER_COLOR)",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if args.whitespace:
|
if args.whitespace:
|
||||||
lines.append("\n")
|
print()
|
||||||
|
|
||||||
return lines
|
|
||||||
|
|
||||||
|
|
||||||
def print_help():
|
def print_help():
|
||||||
lines = [f"""$(USAGE)"""]
|
print(f"""$(USAGE)""")
|
||||||
|
|
||||||
items = list(parse_make(gen_makefile()))
|
items = list(parse_make(gen_makefile()))
|
||||||
maxlens = MaxLens(
|
maxlens = MaxLens(
|
||||||
*(max((len(item[x]) for item in items if x in item)) for x in ["goal", "msg"])
|
*(max((len(item[x]) for item in items if x in item)) for x in ["goal", "msg"])
|
||||||
)
|
)
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
if "goal" in item:
|
if "goal" in item:
|
||||||
lines.append(
|
print_goal(item["goal"], item["msg"], maxlens.goal)
|
||||||
fmt_goal(
|
|
||||||
item["goal"], item["msg"], maxlens.goal, item.get("msgargs", "")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if "rawmsg" in item:
|
if "rawmsg" in item:
|
||||||
lines.extend(fmt_rawmsg(item["rawmsg"], item.get("rawargs", ""), maxlens))
|
print_rawmsg(item["rawmsg"], item.get("args", ""), maxlens)
|
||||||
lines.append(f"""$(EPILOG)""")
|
|
||||||
print("\n".join(lines))
|
print(f"""$(EPILOG)""")
|
||||||
|
|
||||||
|
|
||||||
print_help()
|
print_help()
|
||||||
|
|
|
@ -5,10 +5,6 @@
|
||||||
|
|
||||||
codes_names = {getattr(ansi, attr): attr for attr in ansi.__dict__}
|
codes_names = {getattr(ansi, attr): attr for attr in ansi.__dict__}
|
||||||
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(
|
print("{:>20} $(HELP_SEP) {} $(HELP_SEP) {}".format(codes_names[code], code + "******" + ansi.end,repr(code)))
|
||||||
"{:>20} $(HELP_SEP) {} $(HELP_SEP) {}".format(
|
|
||||||
codes_names[code], code + "******" + ansi.end, repr(code)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
#% endblock %#
|
#% endblock %#
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
# ---- [python/bash script runner] ---- #
|
# ---- [python/bash script runner] ---- #
|
||||||
###-- modified from https://unix.stackexchange.com/a/223093 -###
|
|
||||||
|
# modified from https://unix.stackexchange.com/a/223093
|
||||||
define \n
|
define \n
|
||||||
|
|
||||||
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1))))
|
escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1))))
|
||||||
escape_printf = $(subst \,\\,$(subst %,%%,$1))
|
escape_printf = $(subst \,\\,$(subst %,%%,$1))
|
||||||
create_string = $(subst $(\n),\n,$(call escape_shellstring,$(call escape_printf,$1)))
|
create_string = $(subst $(\n),\n,$(call escape_shellstring,$(call escape_printf,$1)))
|
||||||
printline = printf -- "<----------------------------------->\n"
|
|
||||||
ifdef DEBUG
|
ifdef DEBUG
|
||||||
define _debug_runner
|
define _debug_runner
|
||||||
@printf "$(1) Script:\n";$(printline);
|
@printf "$(1) Script:\n"
|
||||||
@printf "$(call create_string,$(3))\n" | cat -n
|
@printf -- "<----------------------------------->\n"
|
||||||
@$(printline)
|
@printf "$(call create_string,$(3))\n"
|
||||||
|
@printf -- "<----------------------------------->\n"
|
||||||
@printf "$(call create_string,$(3))" | $(2)
|
@printf "$(call create_string,$(3))" | $(2)
|
||||||
endef
|
endef
|
||||||
py = $(call _debug_runner,Python,python3,$($(1)))
|
py = $(call _debug_runner,Python,python3,$($(1)))
|
||||||
|
@ -21,4 +24,5 @@ else
|
||||||
py = @python3 <(printf "$(call create_string,$($(1)))")
|
py = @python3 <(printf "$(call create_string,$($(1)))")
|
||||||
tbash = @bash <(printf "$(call create_string,$($(1)))")
|
tbash = @bash <(printf "$(call create_string,$($(1)))")
|
||||||
endif
|
endif
|
||||||
|
|
||||||
pysh = python3 <(printf "$(call create_string,$($(1)))")
|
pysh = python3 <(printf "$(call create_string,$($(1)))")
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
#% include 'header.mk' %#
|
#% include 'header.mk' %#
|
||||||
|
|
||||||
#% include 'config.mk' %#
|
#% include 'config.mk' %#
|
||||||
|
|
||||||
#% include 'builtins.mk' %#
|
#% include 'builtins.mk' %#
|
||||||
|
|
||||||
#% include 'runners.mk' %#
|
#% include 'runners.mk' %#
|
||||||
|
|
||||||
# ---- [python scripts] ---- #
|
# ---- [python scripts] ---- #
|
||||||
#%- for script in py_scripts %#
|
|
||||||
|
#% for script in py_scripts %#
|
||||||
##- script -##
|
##- script -##
|
||||||
#%- endfor %#
|
#% endfor %#
|
|
@ -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_STYLE)}vars:{ansi.end}\n")
|
print(f"{ansi.$(HEADER_COLOR)}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)}")
|
||||||
|
|
205
task.mk
205
task.mk
|
@ -1,66 +1,89 @@
|
||||||
# }> [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-13-gd2a239d-dev
|
# version: v22.9.14-4-gde1bc7e-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] ---- #
|
|
||||||
HEADER_STYLE ?= b_cyan
|
# ---- CONFIG ---- #
|
||||||
ACCENT_STYLE ?= b_yellow
|
HEADER_COLOR ?= b_cyan
|
||||||
PARAMS_STYLE ?= $(ACCENT_STYLE)
|
PARAMS_COLOR ?= b_magenta
|
||||||
GOAL_STYLE ?= $(ACCENT_STYLE)
|
ACCENT_COLOR ?= b_yellow
|
||||||
MSG_STYLE ?= faint
|
GOAL_COLOR ?= $(ACCENT_COLOR)
|
||||||
DIVIDER_STYLE ?= default
|
MSG_COLOR ?= faint
|
||||||
|
DIVIDER_COLOR ?= default
|
||||||
DIVIDER ?= ─
|
DIVIDER ?= ─
|
||||||
HELP_SEP ?= │
|
HELP_SEP ?= │
|
||||||
|
|
||||||
# python f-string literals
|
# python f-string literals
|
||||||
EPILOG ?=
|
EPILOG ?=
|
||||||
USAGE ?={ansi.$(HEADER_STYLE)}usage{ansi.end}:\n make <recipe>
|
define USAGE ?=
|
||||||
|
{ansi.$(HEADER_COLOR)}usage{ansi.end}:
|
||||||
|
make <recipe>
|
||||||
|
|
||||||
|
endef
|
||||||
|
|
||||||
# ---- [buitlin recipes] ---- #
|
# ---- [buitlin recipes] ---- #
|
||||||
|
|
||||||
## h, help | show this help
|
## h, help | show this help
|
||||||
.PHONY: help h
|
.PHONY: help h
|
||||||
help h:
|
help h:
|
||||||
$(call py,help_py)
|
$(call py,help_py)
|
||||||
|
|
||||||
.PHONY: _help
|
.PHONY: _help
|
||||||
_help: export SHOW_HIDDEN=true
|
_help: export SHOW_HIDDEN=true
|
||||||
_help: help
|
_help: help
|
||||||
|
|
||||||
ifdef PRINT_VARS
|
ifdef PRINT_VARS
|
||||||
|
|
||||||
$(foreach v,$(PRINT_VARS),$(eval export $(v)))
|
$(foreach v,$(PRINT_VARS),$(eval export $(v)))
|
||||||
|
|
||||||
.PHONY: vars v
|
.PHONY: vars v
|
||||||
vars v:
|
vars v:
|
||||||
$(call py,vars_py,$(PRINT_VARS))
|
$(call py,vars_py,$(PRINT_VARS))
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
### | args: -ws --hidden
|
### | args: -ws --hidden
|
||||||
### task.mk builtins: | args: -d --hidden
|
### task.mk builtins: | args: -d --hidden
|
||||||
## _print-ansi | show all possible ansi color code combinations
|
## _print-ansi | show all possible ansi color code combinations
|
||||||
.PHONY:
|
.PHONY:
|
||||||
_print-ansi:
|
_print-ansi:
|
||||||
$(call py,print_ansi_py)
|
$(call py,print_ansi_py)
|
||||||
|
|
||||||
# functions to take f-string literals and pass to python print
|
# functions to take f-string literals and pass to python print
|
||||||
tprint = $(call py,info_py,$(1))
|
tprint = $(call py,info_py,$(1))
|
||||||
tprint-sh = $(call pysh,info_py,$(1))
|
tprint-sh = $(call pysh,info_py,$(1))
|
||||||
|
|
||||||
tconfirm = $(call py,confirm_py,$(1))
|
tconfirm = $(call py,confirm_py,$(1))
|
||||||
|
|
||||||
## _update-task.mk | downloads latest development version of task.mk
|
## _update-task.mk | downloads latest development version of task.mk
|
||||||
_update-task.mk:
|
_update-task.mk:
|
||||||
$(call tprint,{a.b_cyan}Updating task.mk{a.end})
|
$(call tprint,{a.b_cyan}Updating task.mk{a.end})
|
||||||
curl https://raw.githubusercontent.com/daylinmorgan/task.mk/main/task.mk -o .task.mk
|
curl https://raw.githubusercontent.com/daylinmorgan/task.mk/main/task.mk -o .task.mk
|
||||||
|
|
||||||
export MAKEFILE_LIST
|
export MAKEFILE_LIST
|
||||||
|
|
||||||
# ---- [python/bash script runner] ---- #
|
# ---- [python/bash script runner] ---- #
|
||||||
|
|
||||||
|
# modified from https://unix.stackexchange.com/a/223093
|
||||||
define \n
|
define \n
|
||||||
|
|
||||||
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1))))
|
escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1))))
|
||||||
escape_printf = $(subst \,\\,$(subst %,%%,$1))
|
escape_printf = $(subst \,\\,$(subst %,%%,$1))
|
||||||
create_string = $(subst $(\n),\n,$(call escape_shellstring,$(call escape_printf,$1)))
|
create_string = $(subst $(\n),\n,$(call escape_shellstring,$(call escape_printf,$1)))
|
||||||
printline = printf -- "<----------------------------------->\n"
|
|
||||||
ifdef DEBUG
|
ifdef DEBUG
|
||||||
define _debug_runner
|
define _debug_runner
|
||||||
@printf "$(1) Script:\n";$(printline);
|
@printf "$(1) Script:\n"
|
||||||
@printf "$(call create_string,$(3))\n" | cat -n
|
@printf -- "<----------------------------------->\n"
|
||||||
@$(printline)
|
@printf "$(call create_string,$(3))\n"
|
||||||
|
@printf -- "<----------------------------------->\n"
|
||||||
@printf "$(call create_string,$(3))" | $(2)
|
@printf "$(call create_string,$(3))" | $(2)
|
||||||
endef
|
endef
|
||||||
py = $(call _debug_runner,Python,python3,$($(1)))
|
py = $(call _debug_runner,Python,python3,$($(1)))
|
||||||
|
@ -69,33 +92,50 @@ else
|
||||||
py = @python3 <(printf "$(call create_string,$($(1)))")
|
py = @python3 <(printf "$(call create_string,$($(1)))")
|
||||||
tbash = @bash <(printf "$(call create_string,$($(1)))")
|
tbash = @bash <(printf "$(call create_string,$($(1)))")
|
||||||
endif
|
endif
|
||||||
|
|
||||||
pysh = python3 <(printf "$(call create_string,$($(1)))")
|
pysh = python3 <(printf "$(call create_string,$($(1)))")
|
||||||
|
|
||||||
# ---- [python scripts] ---- #
|
# ---- [python scripts] ---- #
|
||||||
|
|
||||||
|
|
||||||
define help_py
|
define help_py
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
$(ansi_py)
|
$(ansi_py)
|
||||||
|
|
||||||
|
ansi: Any
|
||||||
|
|
||||||
MaxLens = namedtuple("MaxLens", "goal msg")
|
MaxLens = namedtuple("MaxLens", "goal msg")
|
||||||
|
|
||||||
|
# double dollar signs to prevent make escaping them
|
||||||
pattern = re.compile(
|
pattern = re.compile(
|
||||||
r"^## (?P<goal>.*?) \| (?P<msg>.*?)(?:\s?\| args: (?P<msgargs>.*?))?$$|^### (?P<rawmsg>.*?)?(?:\s?\| args: (?P<rawargs>.*?))?$$"
|
r"^## (?P<goal>.*) \| (?P<msg>.*)|^### (?P<rawmsg>.*?)?(?:\s?\| args: (?P<args>.*?))?$$"
|
||||||
)
|
)
|
||||||
def parseargs(argstring):
|
|
||||||
|
|
||||||
|
def rawargs(argstring):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("--align")
|
parser.add_argument("--align")
|
||||||
parser.add_argument("-d", "--divider", action="store_true")
|
parser.add_argument("-d", "--divider", action="store_true")
|
||||||
parser.add_argument("-ws", "--whitespace", action="store_true")
|
parser.add_argument("-ws", "--whitespace", action="store_true")
|
||||||
parser.add_argument("-ms", "--msg-style", type=str)
|
parser.add_argument("-ms", "--msg-style", type=str)
|
||||||
parser.add_argument("-gs", "--goal-style", type=str)
|
parser.add_argument("--hidden",action="store_true")
|
||||||
parser.add_argument("--hidden", action="store_true")
|
|
||||||
return parser.parse_args(argstring.split())
|
return parser.parse_args(argstring.split())
|
||||||
|
|
||||||
|
|
||||||
def gen_makefile():
|
def gen_makefile():
|
||||||
makefile = ""
|
makefile = ""
|
||||||
for file in os.getenv("MAKEFILE_LIST").split():
|
for file in os.getenv("MAKEFILE_LIST").split():
|
||||||
with open(file, "r") as f:
|
with open(file, "r") as f:
|
||||||
makefile += f.read() + "\n\n"
|
makefile += f.read() + "\n\n"
|
||||||
return makefile
|
return makefile
|
||||||
|
|
||||||
|
|
||||||
def parse_make(file):
|
def parse_make(file):
|
||||||
for line in file.splitlines():
|
for line in file.splitlines():
|
||||||
match = pattern.search(line)
|
match = pattern.search(line)
|
||||||
|
@ -106,62 +146,67 @@ def parse_make(file):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
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 fmt_goal(goal, msg, max_goal_len, argstr):
|
|
||||||
args = parseargs(argstr)
|
|
||||||
goal_style = args.goal_style.strip() if args.goal_style else "$(GOAL_STYLE)"
|
def print_goal(goal, msg, max_goal_len):
|
||||||
msg_style = args.msg_style.strip() if args.msg_style else "$(MSG_STYLE)"
|
print(
|
||||||
return (
|
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_style)
|
+ ansi.style(msg, "$(MSG_COLOR)")
|
||||||
)
|
)
|
||||||
def fmt_rawmsg(msg, argstr, maxlens):
|
|
||||||
args = parseargs(argstr)
|
|
||||||
lines = []
|
def print_rawmsg(msg, argstr, maxlens):
|
||||||
msg_style = args.msg_style.strip() if args.msg_style else "$(MSG_STYLE)"
|
args = rawargs(argstr)
|
||||||
|
msg_style = args.msg_style if args.msg_style else "$(MSG_COLOR)"
|
||||||
if not os.getenv("SHOW_HIDDEN") and args.hidden:
|
if not os.getenv("SHOW_HIDDEN") and args.hidden:
|
||||||
return []
|
return
|
||||||
if msg:
|
if msg:
|
||||||
if args.align == "sep":
|
if args.align == "sep":
|
||||||
lines.append(
|
print(
|
||||||
f"{' '*(maxlens.goal+len('$(HELP_SEP)')+4)}{ansi.style(msg,msg_style)}"
|
f"{' '*(maxlens.goal+len('$(HELP_SEP)')+4)}{ansi.style(msg,msg_style)}"
|
||||||
)
|
)
|
||||||
elif args.align == "center":
|
elif args.align == "center":
|
||||||
lines.append(f" {ansi.style(msg.center(sum(maxlens)),msg_style)}")
|
print(f" {ansi.style(msg.center(sum(maxlens)),msg_style)}")
|
||||||
else:
|
else:
|
||||||
lines.append(f" {ansi.style(msg,msg_style)}")
|
print(f" {ansi.style(msg,msg_style)}")
|
||||||
if args.divider:
|
if args.divider:
|
||||||
lines.append(
|
print(
|
||||||
ansi.style(
|
ansi.style(
|
||||||
f" {'$(DIVIDER)'*(len('$(HELP_SEP)')+sum(maxlens)+2)}",
|
f" {'$(DIVIDER)'*(len('$(HELP_SEP)')+sum(maxlens)+2)}",
|
||||||
"$(DIVIDER_STYLE)",
|
"$(DIVIDER_COLOR)",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if args.whitespace:
|
if args.whitespace:
|
||||||
lines.append("\n")
|
print()
|
||||||
return lines
|
|
||||||
|
|
||||||
def print_help():
|
def print_help():
|
||||||
lines = [f"""$(USAGE)"""]
|
print(f"""$(USAGE)""")
|
||||||
|
|
||||||
items = list(parse_make(gen_makefile()))
|
items = list(parse_make(gen_makefile()))
|
||||||
maxlens = MaxLens(
|
maxlens = MaxLens(
|
||||||
*(max((len(item[x]) for item in items if x in item)) for x in ["goal", "msg"])
|
*(max((len(item[x]) for item in items if x in item)) for x in ["goal", "msg"])
|
||||||
)
|
)
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
if "goal" in item:
|
if "goal" in item:
|
||||||
lines.append(
|
print_goal(item["goal"], item["msg"], maxlens.goal)
|
||||||
fmt_goal(
|
|
||||||
item["goal"], item["msg"], maxlens.goal, item.get("msgargs", "")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if "rawmsg" in item:
|
if "rawmsg" in item:
|
||||||
lines.extend(fmt_rawmsg(item["rawmsg"], item.get("rawargs", ""), maxlens))
|
print_rawmsg(item["rawmsg"], item.get("args", ""), maxlens)
|
||||||
lines.append(f"""$(EPILOG)""")
|
|
||||||
print("\n".join(lines))
|
print(f"""$(EPILOG)""")
|
||||||
|
|
||||||
|
|
||||||
print_help()
|
print_help()
|
||||||
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define ansi_py
|
define ansi_py
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
color2byte = dict(
|
color2byte = dict(
|
||||||
black=0,
|
black=0,
|
||||||
red=1,
|
red=1,
|
||||||
|
@ -172,35 +217,47 @@ color2byte = dict(
|
||||||
cyan=6,
|
cyan=6,
|
||||||
white=7,
|
white=7,
|
||||||
)
|
)
|
||||||
|
|
||||||
state2byte = dict(
|
state2byte = dict(
|
||||||
bold=1, faint=2, italic=3, underline=4, blink=5, fast_blink=6, crossed=9
|
bold=1, faint=2, italic=3, underline=4, blink=5, fast_blink=6, crossed=9
|
||||||
)
|
)
|
||||||
addfg = lambda byte: byte + 30
|
|
||||||
addbg = lambda byte: byte + 40
|
|
||||||
|
def fg(byte):
|
||||||
|
return 30 + byte
|
||||||
|
|
||||||
|
|
||||||
|
def bg(byte):
|
||||||
|
return 40 + byte
|
||||||
|
|
||||||
|
|
||||||
class Ansi:
|
class Ansi:
|
||||||
"""ANSI escape codes"""
|
"""ANSI color codes"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
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")
|
||||||
for name, byte in color2byte.items():
|
for name, byte in color2byte.items():
|
||||||
self.setcode(name, f"\033[{addfg(byte)}m")
|
self.setcode(name, f"\033[{fg(byte)}m")
|
||||||
self.setcode(f"b_{name}", f"\033[1;{addfg(byte)}m")
|
self.setcode(f"b_{name}", f"\033[1;{fg(byte)}m")
|
||||||
self.setcode(f"d_{name}", f"\033[2;{addfg(byte)}m")
|
self.setcode(f"d_{name}", f"\033[2;{fg(byte)}m")
|
||||||
for bgname, bgbyte in color2byte.items():
|
for bgname, bgbyte in color2byte.items():
|
||||||
self.setcode(
|
self.setcode(f"{name}_on_{bgname}", f"\033[{bg(bgbyte)};{fg(byte)}m")
|
||||||
f"{name}_on_{bgname}", f"\033[{addbg(bgbyte)};{addfg(byte)}m"
|
|
||||||
)
|
|
||||||
for name, byte in state2byte.items():
|
for name, byte in state2byte.items():
|
||||||
self.setcode(name, f"\033[{byte}m")
|
self.setcode(name, f"\033[{byte}m")
|
||||||
|
|
||||||
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 not sys.stdout.isatty() or os.getenv("NO_COLOR", False):
|
||||||
setattr(self, name, "")
|
setattr(self, name, "")
|
||||||
else:
|
else:
|
||||||
setattr(self, name, escape_code)
|
setattr(self, name, escape_code)
|
||||||
|
|
||||||
def custom(self, fg=None, bg=None):
|
def custom(self, fg=None, bg=None):
|
||||||
"""use custom color"""
|
"""use custom color"""
|
||||||
|
|
||||||
code, end = "\033[", "m"
|
code, end = "\033[", "m"
|
||||||
if fg:
|
if fg:
|
||||||
if isinstance(fg, int):
|
if isinstance(fg, int):
|
||||||
|
@ -212,6 +269,7 @@ class Ansi:
|
||||||
else:
|
else:
|
||||||
print("Expected one or three values for fg as a list")
|
print("Expected one or three values for fg as a list")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if bg:
|
if bg:
|
||||||
if isinstance(bg, int):
|
if isinstance(bg, int):
|
||||||
code += f"{';' if fg else ''}48;5;{bg}"
|
code += f"{';' if fg else ''}48;5;{bg}"
|
||||||
|
@ -222,42 +280,64 @@ class Ansi:
|
||||||
else:
|
else:
|
||||||
print("Expected one or three values for bg as a list")
|
print("Expected one or three values for bg as a list")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
return code + end
|
return code + end
|
||||||
|
|
||||||
def style(self, text, style):
|
def style(self, text, style):
|
||||||
if style not in self.__dict__:
|
if style not in self.__dict__:
|
||||||
print(f"unknown style: {style}")
|
print(f"unknown style {style}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
return f"{self.__dict__[style]}{text}{self.__dict__['end']}"
|
return f"{self.__dict__[style]}{text}{self.__dict__['end']}"
|
||||||
|
|
||||||
|
|
||||||
a = ansi = Ansi()
|
a = ansi = Ansi()
|
||||||
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define info_py
|
define info_py
|
||||||
|
|
||||||
$(ansi_py)
|
$(ansi_py)
|
||||||
|
|
||||||
print(f"""$(2)""")
|
print(f"""$(2)""")
|
||||||
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define print_ansi_py
|
define print_ansi_py
|
||||||
|
|
||||||
$(ansi_py)
|
$(ansi_py)
|
||||||
|
|
||||||
codes_names = {getattr(ansi, attr): attr for attr in ansi.__dict__}
|
codes_names = {getattr(ansi, attr): attr for attr in ansi.__dict__}
|
||||||
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(
|
print("{:>20} $(HELP_SEP) {} $(HELP_SEP) {}".format(codes_names[code], code + "******" + ansi.end,repr(code)))
|
||||||
"{:>20} $(HELP_SEP) {} $(HELP_SEP) {}".format(
|
|
||||||
codes_names[code], code + "******" + ansi.end, repr(code)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define vars_py
|
define vars_py
|
||||||
|
|
||||||
import os
|
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_STYLE)}vars:{ansi.end}\n")
|
|
||||||
|
print(f"{ansi.$(HEADER_COLOR)}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()
|
||||||
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define confirm_py
|
define confirm_py
|
||||||
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
$(ansi_py)
|
$(ansi_py)
|
||||||
|
|
||||||
def confirm():
|
def confirm():
|
||||||
"""
|
"""
|
||||||
Ask user to enter Y or N (case-insensitive).
|
Ask user to enter Y or N (case-insensitive).
|
||||||
|
@ -268,8 +348,11 @@ def confirm():
|
||||||
while answer not in ["y", "n"]:
|
while answer not in ["y", "n"]:
|
||||||
answer = input(f"""$(2) {a.b_red}[Y/n]{a.end} """).lower()
|
answer = input(f"""$(2) {a.b_red}[Y/n]{a.end} """).lower()
|
||||||
return answer == "y"
|
return answer == "y"
|
||||||
|
|
||||||
if confirm():
|
if confirm():
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
else:
|
else:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue