Compare commits

..

No commits in common. "bf0394c5e18f7d72b236462930248876bc8a5336" and "6dad870b23f144904ec67a9912afe67c792004c4" have entirely different histories.

6 changed files with 17 additions and 74 deletions

View file

@ -4,11 +4,6 @@
import sys import sys
###-
# this is just to trick the LSP during development
from utils import a
# -###
##- '$(utils_py)' -## ##- '$(utils_py)' -##
@ -20,8 +15,7 @@ def confirm():
""" """
answer = "" answer = ""
while answer not in ["y", "n"]: while answer not in ["y", "n"]:
sys.stderr.write(f"""$(2) {a.b_red}[Y/n]{a.end} \n""") answer = input(f"""$(2) {a.b_red}[Y/n]{a.end} """).lower()
answer = input().lower()
return answer == "y" return answer == "y"

View file

@ -9,14 +9,14 @@ import subprocess
import sys import sys
from textwrap import wrap from textwrap import wrap
##- '$(utils_py)' -##
###- ###-
# 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
# -### # -###
##- '$(utils_py)' -##
a = ansi = Ansi(target="stdout")
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 -###

View file

@ -2,26 +2,9 @@
#% block name %#print_ansi#% endblock %# #% block name %#print_ansi#% endblock %#
#% block script %# #% block script %#
##- '$(utils_py)' -## ##- '$(utils_py)' -##
import sys sep = f"$(HELP_SEP)"
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)):
sys.stderr.write( print(f"{codes_names[code]:>20} {sep} {code+'*****'+ansi.end} {sep} {repr(code)}")
f"{codes_names[code]:>20} {cfg.sep} {code+'*****'+ansi.end} {cfg.sep} {repr(code)}\n"
)
#% endblock %# #% endblock %#

View file

@ -37,8 +37,7 @@ addbg = lambda byte: byte + 40
class Ansi: class Ansi:
"""ANSI escape codes""" """ANSI escape codes"""
def __init__(self, target="stdout"): def __init__(self):
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")
@ -57,11 +56,7 @@ class Ansi:
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 os.getenv("NO_COLOR", False): if not sys.stdout.isatty() or 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)
@ -118,6 +113,7 @@ 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)")
) )

View file

@ -3,15 +3,8 @@
#% block script %# #% block script %#
import os import os
###-
# this is just to trick the LSP during development
from utils import Ansi
# -###
##- '$(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))

37
task.mk
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-3-g76e9ece-dev # version: v22.9.28-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.
@ -88,7 +88,6 @@ 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>.*?) \| (?P<msg>.*?)(?:\s?\| args: (?P<msgargs>.*?))?$$|^### (?P<rawmsg>.*?)?(?:\s?\| args: (?P<rawargs>.*?))?$$"
@ -247,30 +246,14 @@ sys.stderr.write(f"""$(2)\n""")
endef endef
define print_ansi_py define print_ansi_py
$(utils_py) $(utils_py)
import sys sep = f"$(HELP_SEP)"
codes_names = { codes_names = {getattr(ansi, attr): attr for attr in ansi.__dict__}
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)):
sys.stderr.write( print(f"{codes_names[code]:>20} {sep} {code+'*****'+ansi.end} {sep} {repr(code)}")
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")
@ -289,8 +272,7 @@ def confirm():
""" """
answer = "" answer = ""
while answer not in ["y", "n"]: while answer not in ["y", "n"]:
sys.stderr.write(f"""$(2) {a.b_red}[Y/n]{a.end} \n""") answer = input(f"""$(2) {a.b_red}[Y/n]{a.end} """).lower()
answer = input().lower()
return answer == "y" return answer == "y"
if confirm(): if confirm():
sys.exit() sys.exit()
@ -325,8 +307,7 @@ 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, target="stdout"): def __init__(self):
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")
@ -343,11 +324,7 @@ 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 os.getenv("NO_COLOR", False): if not sys.stdout.isatty() or 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)