mirror of
https://github.com/daylinmorgan/task.mk.git
synced 2024-12-22 18:00:44 -06:00
Compare commits
No commits in common. "6dad870b23f144904ec67a9912afe67c792004c4" and "4e57dfe0e30d54fdbc10436c2335c339aaf3f586" have entirely different histories.
6dad870b23
...
4e57dfe0e3
7 changed files with 59 additions and 68 deletions
|
@ -6,7 +6,7 @@ import jinja2
|
||||||
|
|
||||||
py_script_names = [
|
py_script_names = [
|
||||||
"help",
|
"help",
|
||||||
"print",
|
"info",
|
||||||
"print-ansi",
|
"print-ansi",
|
||||||
"vars",
|
"vars",
|
||||||
"confirm",
|
"confirm",
|
||||||
|
|
|
@ -20,8 +20,8 @@ endif
|
||||||
_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,print_py,$(1))
|
tprint = $(call py,info_py,$(1))
|
||||||
tprint-sh = $(call pysh,print_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:
|
||||||
|
|
|
@ -13,7 +13,6 @@ from textwrap import wrap
|
||||||
###-
|
###-
|
||||||
# this is just to trick the LSP during development
|
# this is just to trick the LSP during development
|
||||||
from utils import ansi, cfg
|
from utils import ansi, cfg
|
||||||
|
|
||||||
# -###
|
# -###
|
||||||
|
|
||||||
|
|
||||||
|
|
7
src/info.py
Normal file
7
src/info.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#% extends "py-script.mk" %#
|
||||||
|
#% block name %#info#% endblock %#
|
||||||
|
#% block script %#
|
||||||
|
##- '$(utils_py)' -##
|
||||||
|
|
||||||
|
print(f"""$(2)""")
|
||||||
|
#% endblock %#
|
|
@ -1,7 +0,0 @@
|
||||||
#% extends "py-script.mk" %#
|
|
||||||
#% block name %#print#% endblock %#
|
|
||||||
#% block script %#
|
|
||||||
##- '$(utils_py)' -##
|
|
||||||
###- sys is imported with utils_py -###
|
|
||||||
sys.stderr.write(f"""$(2)\n""")
|
|
||||||
#% endblock %#
|
|
48
src/utils.py
48
src/utils.py
|
@ -65,32 +65,29 @@ class Ansi:
|
||||||
"""use custom color"""
|
"""use custom color"""
|
||||||
|
|
||||||
code, end = "\033[", "m"
|
code, end = "\033[", "m"
|
||||||
if not sys.stdout.isatty() or os.getenv("NO_COLOR", False):
|
if fg:
|
||||||
return ""
|
if isinstance(fg, int):
|
||||||
else:
|
code += f"38;5;{fg}"
|
||||||
if fg:
|
elif (isinstance(fg, list) or isinstance(fg, tuple)) and len(fg) == 1:
|
||||||
if isinstance(fg, int):
|
code += f"38;5;{fg[0]}"
|
||||||
code += f"38;5;{fg}"
|
elif (isinstance(fg, list) or isinstance(fg, tuple)) and len(fg) == 3:
|
||||||
elif (isinstance(fg, list) or isinstance(fg, tuple)) and len(fg) == 1:
|
code += f"38;2;{';'.join((str(i) for i in fg))}"
|
||||||
code += f"38;5;{fg[0]}"
|
else:
|
||||||
elif (isinstance(fg, list) or isinstance(fg, tuple)) and len(fg) == 3:
|
print("Expected one or three values for fg as a list")
|
||||||
code += f"38;2;{';'.join((str(i) for i in fg))}"
|
sys.exit(1)
|
||||||
else:
|
|
||||||
print("Expected one or three values for fg as a list")
|
|
||||||
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}"
|
||||||
elif (isinstance(bg, list) or isinstance(bg, tuple)) and len(bg) == 1:
|
elif (isinstance(bg, list) or isinstance(bg, tuple)) and len(bg) == 1:
|
||||||
code += f"{';' if fg else ''}48;5;{bg[0]}"
|
code += f"{';' if fg else ''}48;5;{bg[0]}"
|
||||||
elif (isinstance(bg, list) or isinstance(bg, tuple)) and len(bg) == 3:
|
elif (isinstance(bg, list) or isinstance(bg, tuple)) and len(bg) == 3:
|
||||||
code += f"{';' if fg else ''}48;2;{';'.join((str(i) for i in bg))}"
|
code += f"{';' if fg else ''}48;2;{';'.join((str(i) for i in bg))}"
|
||||||
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 add_cfg(self):
|
def add_cfg(self):
|
||||||
cfg_styles = {
|
cfg_styles = {
|
||||||
|
@ -115,6 +112,5 @@ class Ansi:
|
||||||
a = ansi = Ansi()
|
a = ansi = Ansi()
|
||||||
|
|
||||||
cfg = Config(
|
cfg = Config(
|
||||||
"$(DIVIDER)", "$(HELP_SEP)", f"""$(EPILOG)""", f"""$(USAGE)""", int("$(WRAP)")
|
"$(DIVIDER)", "$(HELP_SEP)", f"""$(EPILOG)""", f"""$(USAGE)""",int('$(WRAP)'))
|
||||||
)
|
|
||||||
#% endblock %#
|
#% endblock %#
|
||||||
|
|
58
task.mk
58
task.mk
|
@ -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: 22.9.28
|
||||||
#
|
#
|
||||||
# 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.
|
||||||
|
@ -42,8 +42,8 @@ endif
|
||||||
_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,print_py,$(1))
|
tprint = $(call py,info_py,$(1))
|
||||||
tprint-sh = $(call pysh,print_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:
|
||||||
|
@ -240,9 +240,9 @@ def main():
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
endef
|
endef
|
||||||
define print_py
|
define info_py
|
||||||
$(utils_py)
|
$(utils_py)
|
||||||
sys.stderr.write(f"""$(2)\n""")
|
print(f"""$(2)""")
|
||||||
endef
|
endef
|
||||||
define print_ansi_py
|
define print_ansi_py
|
||||||
$(utils_py)
|
$(utils_py)
|
||||||
|
@ -331,30 +331,27 @@ class Ansi:
|
||||||
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 not sys.stdout.isatty() or os.getenv("NO_COLOR", False):
|
if fg:
|
||||||
return ""
|
if isinstance(fg, int):
|
||||||
else:
|
code += f"38;5;{fg}"
|
||||||
if fg:
|
elif (isinstance(fg, list) or isinstance(fg, tuple)) and len(fg) == 1:
|
||||||
if isinstance(fg, int):
|
code += f"38;5;{fg[0]}"
|
||||||
code += f"38;5;{fg}"
|
elif (isinstance(fg, list) or isinstance(fg, tuple)) and len(fg) == 3:
|
||||||
elif (isinstance(fg, list) or isinstance(fg, tuple)) and len(fg) == 1:
|
code += f"38;2;{';'.join((str(i) for i in fg))}"
|
||||||
code += f"38;5;{fg[0]}"
|
else:
|
||||||
elif (isinstance(fg, list) or isinstance(fg, tuple)) and len(fg) == 3:
|
print("Expected one or three values for fg as a list")
|
||||||
code += f"38;2;{';'.join((str(i) for i in fg))}"
|
sys.exit(1)
|
||||||
else:
|
if bg:
|
||||||
print("Expected one or three values for fg as a list")
|
if isinstance(bg, int):
|
||||||
sys.exit(1)
|
code += f"{';' if fg else ''}48;5;{bg}"
|
||||||
if bg:
|
elif (isinstance(bg, list) or isinstance(bg, tuple)) and len(bg) == 1:
|
||||||
if isinstance(bg, int):
|
code += f"{';' if fg else ''}48;5;{bg[0]}"
|
||||||
code += f"{';' if fg else ''}48;5;{bg}"
|
elif (isinstance(bg, list) or isinstance(bg, tuple)) and len(bg) == 3:
|
||||||
elif (isinstance(bg, list) or isinstance(bg, tuple)) and len(bg) == 1:
|
code += f"{';' if fg else ''}48;2;{';'.join((str(i) for i in bg))}"
|
||||||
code += f"{';' if fg else ''}48;5;{bg[0]}"
|
else:
|
||||||
elif (isinstance(bg, list) or isinstance(bg, tuple)) and len(bg) == 3:
|
print("Expected one or three values for bg as a list")
|
||||||
code += f"{';' if fg else ''}48;2;{';'.join((str(i) for i in bg))}"
|
sys.exit(1)
|
||||||
else:
|
return code + end
|
||||||
print("Expected one or three values for bg as a list")
|
|
||||||
sys.exit(1)
|
|
||||||
return code + end
|
|
||||||
def add_cfg(self):
|
def add_cfg(self):
|
||||||
cfg_styles = {
|
cfg_styles = {
|
||||||
"header": "$(HEADER_STYLE)",
|
"header": "$(HEADER_STYLE)",
|
||||||
|
@ -374,6 +371,5 @@ class Ansi:
|
||||||
return f"{self.__dict__[style]}{text}{self.__dict__['end']}"
|
return f"{self.__dict__[style]}{text}{self.__dict__['end']}"
|
||||||
a = ansi = Ansi()
|
a = ansi = Ansi()
|
||||||
cfg = Config(
|
cfg = Config(
|
||||||
"$(DIVIDER)", "$(HELP_SEP)", f"""$(EPILOG)""", f"""$(USAGE)""", int("$(WRAP)")
|
"$(DIVIDER)", "$(HELP_SEP)", f"""$(EPILOG)""", f"""$(USAGE)""",int('$(WRAP)'))
|
||||||
)
|
|
||||||
endef
|
endef
|
||||||
|
|
Loading…
Reference in a new issue