Skip to content

Commit 78a925a

Browse files
committed
Initial commit
0 parents  commit 78a925a

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

__init__.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env python3
2+
import shutil
3+
import sys
4+
import os
5+
import math
6+
7+
def main():
8+
columns = shutil.get_terminal_size((80, 20)).columns
9+
10+
if len(sys.argv) != 2:
11+
print("invalid number of arguments")
12+
exit(1)
13+
14+
if not os.path.isfile('./'+sys.argv[1]):
15+
print(sys.argv[1]+" does not exist")
16+
exit(1)
17+
18+
def print_ruler(f, l=columns, first=False):
19+
line1 = "----+----+"
20+
line2 = " | |"
21+
line4 = "---------+"
22+
23+
print(("+" if first else "")+''.join([line1[(f-1+x)%10] for x in range(min(columns - (1 if first else 0),(10-((f-1)%10))+(math.ceil((l-(10-((f-1)%10)))/10)*10)))]))
24+
print(("|" if first else "")+''.join([line2[(f-1+x)%10] for x in range(min(columns - (1 if first else 0),(10-((f-1)%10))+(math.ceil((l-(10-((f-1)%10)))/10)*10)))]))
25+
line = ""
26+
for x in range(math.floor(min(columns-1, l)/10)):
27+
line+="{:>9}|".format(10*(math.floor(f/10)+x+1))
28+
if first:
29+
print("|"+line)#[:math.floor(((f-1)+(columns-1))/10)*10])
30+
else:
31+
print(("{:>9}".format(10*math.ceil(f/10)) if len(str(10*math.floor(f/10)))<=10-f%10 else " "*9)[(f)%10-1:]+"|"+line)#[:math.floor(((f-1)+(columns-1))/10)*10])
32+
print(("+" if first else "")+''.join([line4[(f-1+x)%10] for x in range(min(columns - (1 if first else 0),(10-((f-1)%10))+(math.ceil((l-(10-((f-1)%10)))/10)*10)))]))
33+
34+
return f+min(columns - (1 if first else 0), l)
35+
36+
37+
value = 1
38+
first = True
39+
with open(sys.argv[1]) as f:
40+
print("Total byte count: "+str(os.path.getsize(sys.argv[1])))
41+
line = " "
42+
while True:
43+
c = f.read(1)
44+
if not c:
45+
print(line)
46+
value = print_ruler(value, len(line), first)
47+
first = False
48+
break
49+
if c == '\n':
50+
c = ' '
51+
52+
line += c
53+
if len(line) == columns:
54+
print(line)
55+
value = print_ruler(value, len(line), first)
56+
first = False
57+
line = ""
58+
59+
if __name__ == "main":
60+
main()

setup.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from setuptools import setup
2+
setup(
3+
name='ascii-ruler',
4+
version='0.0.1',
5+
author="Blake Nedved",
6+
author_email="blakeanedved@gmail.com",
7+
description="A terminal based ruler for displaying the length of a file, primarily used for codegolfing",
8+
url="",
9+
entry_points={
10+
'console_scripts': [
11+
'ascii-ruler=__init__:main'
12+
]
13+
}
14+
)

0 commit comments

Comments
 (0)