File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change 3
3
from sys import argv , stderr
4
4
5
5
6
- def convert (code ) -> int :
6
+ def convert (code , floating = False ) -> int :
7
7
if len (code ) != 6 :
8
8
print ("Proper hex color code expected." , file = stderr )
9
9
return 1
@@ -14,9 +14,9 @@ def convert(code) -> int:
14
14
try :
15
15
values .append (round (int (individual , base = 16 ) / 0xFF , 5 ))
16
16
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 )
18
18
return 1
19
- print (f", " .join (map ('{0}f' .format , values )))
19
+ print (f", " .join (map (( '{0}f' if floating else '{0}' ) .format , values )))
20
20
return 0
21
21
22
22
@@ -25,4 +25,11 @@ def convert(code) -> int:
25
25
print ("Hex color code expected as argument." , file = stderr )
26
26
exit (1 )
27
27
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 ))
You can’t perform that action at this time.
0 commit comments