Skip to content

Instantly share code, notes, and snippets.

@Philogy
Created May 26, 2023 18:26
Show Gist options
  • Save Philogy/366fd86c6cdf4c3a3929a09ed98b7055 to your computer and use it in GitHub Desktop.
Save Philogy/366fd86c6cdf4c3a3929a09ed98b7055 to your computer and use it in GitHub Desktop.
Extended Header Tool
#!/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