feat: add support for styling entire raw string

This commit is contained in:
Daylin Morgan 2022-09-14 09:26:02 -05:00
parent 1bed53d3fd
commit 93287afb8e
3 changed files with 13 additions and 9 deletions

View file

@ -5,7 +5,7 @@ TEMPLATES := $(shell find src/ -type f)
msgfmt = {a.style('==>','bold')} {a.style('$(1)','b_magenta')} {a.style('<==','bold')}
msg = $(call tprint,$(call msgfmt ,$(1)))
### task.mk development | args: --divider --align center
### task.mk development | args: -d --align center -ms d_green
## bootstrap | generate local dev environment
.PHONY: bootstrap
bootstrap:
@ -42,7 +42,7 @@ c clean:
@rm -f task.mk .task.mk
### | args: --divider --whitespace
### examples of task.mk features | args: --divider --align center
### examples of task.mk features | args: --divider --align center --msg-style d_red
define list_files_py
from pathlib import Path
print("files in $(2)")

View file

@ -24,6 +24,7 @@ def rawargs(argstring):
parser.add_argument("--align")
parser.add_argument("-d", "--divider", action="store_true")
parser.add_argument("-ws", "--whitespace", action="store_true")
parser.add_argument("-ms", "--msg-style", type=str)
return parser.parse_args(argstring.split())
@ -57,15 +58,16 @@ def print_goal(goal, msg, max_goal_len):
def print_rawmsg(msg, argstr, maxlens):
args = rawargs(argstr)
msg_style = args.msg_style if args.msg_style else "$(MSG_COLOR)"
if msg:
if args.align == "sep":
print(
f"{' '*(maxlens.goal+len('$(HELP_SEP)')+4)}{ansi.style(msg,'$(MSG_COLOR)')}"
f"{' '*(maxlens.goal+len('$(HELP_SEP)')+4)}{ansi.style(msg,msg_style)}"
)
elif args.align == "center":
print(f" {ansi.style(msg.center(sum(maxlens)),'$(MSG_COLOR)')}")
print(f" {ansi.style(msg.center(sum(maxlens)),msg_style)}")
else:
print(f" {ansi.style(msg,'$(MSG_COLOR)')}")
print(f" {ansi.style(msg,msg_style)}")
if args.divider:
print(
ansi.style(

10
task.mk
View file

@ -1,7 +1,7 @@
# }> [github.com/daylinmorgan/task.mk] <{ #
# Copyright (c) 2022 Daylin Morgan
# MIT License
# version: v22.9.12-8-gea398af-dev
# version: v22.9.12-9-g1bed53d-dev
#
# task.mk should be included at the bottom of your Makefile.
# See below for the standard configuration options that should be set prior to including this file.
@ -119,6 +119,7 @@ def rawargs(argstring):
parser.add_argument("--align")
parser.add_argument("-d", "--divider", action="store_true")
parser.add_argument("-ws", "--whitespace", action="store_true")
parser.add_argument("-ms", "--msg-style", type=str)
return parser.parse_args(argstring.split())
@ -152,15 +153,16 @@ def print_goal(goal, msg, max_goal_len):
def print_rawmsg(msg, argstr, maxlens):
args = rawargs(argstr)
msg_style = args.msg_style if args.msg_style else "$(MSG_COLOR)"
if msg:
if args.align == "sep":
print(
f"{' '*(maxlens.goal+len('$(HELP_SEP)')+4)}{ansi.style(msg,'$(MSG_COLOR)')}"
f"{' '*(maxlens.goal+len('$(HELP_SEP)')+4)}{ansi.style(msg,msg_style)}"
)
elif args.align == "center":
print(f" {ansi.style(msg.center(sum(maxlens)),'$(MSG_COLOR)')}")
print(f" {ansi.style(msg.center(sum(maxlens)),msg_style)}")
else:
print(f" {ansi.style(msg,'$(MSG_COLOR)')}")
print(f" {ansi.style(msg,msg_style)}")
if args.divider:
print(
ansi.style(