Skip to content

Commit 42c5245

Browse files
committed
Add Option to Disable 'f' after Outputs
1 parent 369d9fd commit 42c5245

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

colorconvert.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from sys import argv, stderr
44

55

6-
def convert(code) -> int:
6+
def convert(code, floating=False) -> int:
77
if len(code) != 6:
88
print("Proper hex color code expected.", file=stderr)
99
return 1
@@ -14,9 +14,9 @@ def convert(code) -> int:
1414
try:
1515
values.append(round(int(individual, base=16) / 0xFF, 5))
1616
except ValueError:
17-
print(f"Invalid hex code:\n{' '.join(codes)}\n{(' ' * (i * 4 + i))}^^^^", file=stderr)
17+
print(f"Invalid hex code:\n{' '.join(codes)}\n{(' ' * (i * 5))}^^^^", file=stderr)
1818
return 1
19-
print(f", ".join(map('{0}f'.format, values)))
19+
print(f", ".join(map(('{0}f' if floating else '{0}').format, values)))
2020
return 0
2121

2222

@@ -25,4 +25,11 @@ def convert(code) -> int:
2525
print("Hex color code expected as argument.", file=stderr)
2626
exit(1)
2727
else:
28-
exit(convert(argv[1]))
28+
floating = False
29+
if argv[1] == "-f":
30+
floating = True
31+
argv.pop(1)
32+
elif argv[1] == "-d":
33+
floating = False
34+
argv.pop(1)
35+
exit(convert(argv[1], floating))

0 commit comments

Comments
 (0)