Skip to content

Commit

Permalink
Merge pull request #6 from ZeroOne010101/dev
Browse files Browse the repository at this point in the history
Add comments to resolve #2
  • Loading branch information
ZeroOne010101 authored Oct 1, 2022
2 parents f109a43 + 67762ff commit d0ef226
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions ascii-framer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
from stat import S_ISFIFO

# Global Variables
char = '║'
hchar = '═'
whitespacefiller=' '
Expand All @@ -12,9 +13,12 @@
stdincontent = []

def argparse():
"""Parse piped arguments"""
global char
# Exit if there is no arguments
if len(sys.argv) == 1:
return
# set the horizonal char with the -c switch
if len(sys.argv) == 3:
if sys.argv[1] == '-c':
char = sys.argv[2]
Expand All @@ -26,20 +30,23 @@ def argparse():
print('ARGUMENT ERROR, shit is happening!')

def get_stdin():
#check if programm is being piped
"""Populate stdinconent list"""
# Check if programm is being piped
if S_ISFIFO(os.fstat(0).st_mode):
for line in sys.stdin:
line = line.replace('\n', '')
line = line.replace(' ', '')
stdincontent.append(line)

def maxlinelencalc():
# Calculate longest string
global maxlinelen
for line in stdincontent:
if len(line) > maxlinelen:
maxlinelen = len(line)

def horizontal_line(position):
# Helper function to draw the top and bottom lines of the frame
edgechar_l = None
edgechar_r = None
if position == 'top':
Expand All @@ -51,18 +58,18 @@ def horizontal_line(position):
print(f'{edgechar_l}{hchar*(maxlinelen)}{edgechar_r}')

def framer():
# Frame string using the horizontal_line helper function
horizontal_line('top')
for line in stdincontent:
print(f'{char}{line}{whitespacefiller*(maxlinelen-len(line))}{char}')
horizontal_line('bottom')



def main():
argparse()
get_stdin()
maxlinelencalc()
framer()

# Only execute if run as main
if __name__ == "__main__":
main()

0 comments on commit d0ef226

Please sign in to comment.