Created
May 26, 2023 18:26
-
-
Save Philogy/366fd86c6cdf4c3a3929a09ed98b7055 to your computer and use it in GitHub Desktop.
Extended Header Tool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
import pyperclip | |
import argparse | |
def check_width(args, base_width): | |
min_width = len(args.text) + base_width | |
if args.width < min_width: | |
raise ValueError( | |
f'Width of {args.width} cannot fit "{args.text}" (len: {len(args.text)} + {base_width})' | |
) | |
def big_header(args): | |
check_width(args, 4) | |
fill_size = args.width - len(args.text) - 4 | |
word_padding_size = fill_size // 2 | |
word_lpad = ' ' * word_padding_size | |
word_rpad = ' ' * (word_padding_size + fill_size % 2) | |
horizontal_bar = '/' * (args.width - 2) | |
return f'//{horizontal_bar}\n//{word_lpad}{args.text.upper()}{word_rpad}//\n{horizontal_bar}//' | |
def small_header(args): | |
check_width(args, 7) | |
fill_size = args.width - len(args.text) - 5 | |
line_size = fill_size // 2 | |
lline = '=' * line_size | |
rline = '=' * (line_size + fill_size % 2) | |
return f'// {lline} {args.text} {rline}' | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('text', type=str) | |
parser.add_argument('--small', '-s', action='store_true') | |
parser.add_argument('--indent', '-i', default=4, type=int) | |
parser.add_argument('--width', '-w', default=64, type=int) | |
args = parser.parse_args() | |
header = small_header(args) if args.small else big_header(args) | |
print(header) | |
pyperclip.copy(header) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment