-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfmt.py
30 lines (21 loc) · 760 Bytes
/
fmt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3
def parse ( line ) :
return tuple(map(lambda x: int(x, base=16), (line[:2], line[2:4], line[4:6])))
def stringify ( colour ) :
return ('{:0<2x}'*3).format(*colour)
def dump ( colour , strfmt='{}', **kwargs ) :
line = strfmt.format(stringify(colour))
print(line, **kwargs)
def dumpXournal ( colour , file=None ) :
dump(colour, strfmt='COLOR(0x{})', file=file, end=',')
def read ( lines ) :
for line in lines:
yield parse(line)
def write ( colours, dump=dump, columns=1 ) :
table = [ [ ] for i in range(columns) ]
for i, colour in enumerate(colours):
table[i%columns].append(colour)
for col in range(columns):
if col != 0: print()
for colour in table[col]:
dump(colour)