sorting -L

This commit is contained in:
Mattias Andrée 2012-08-22 03:23:11 +02:00
parent a9c0dedfbc
commit 860919ddd4

27
ponysay
View file

@ -154,6 +154,8 @@ class Ponysay():
for pony in ponies: for pony in ponies:
if pony in map: if pony in map:
ponies.append(map[pony]) ponies.append(map[pony])
if links is not None:
links[map[pony]] = pony + '.pony'
else: else:
for j in range(0, len(ponies)): for j in range(0, len(ponies)):
if ponies[j] in map: if ponies[j] in map:
@ -282,7 +284,7 @@ class Ponysay():
print() print()
x = 0 x = 0
print('\n'); print('' if x == 0 else '\n');
''' '''
@ -300,14 +302,13 @@ class Ponysay():
for pony in _ponies: for pony in _ponies:
if (len(pony) > 5) and (pony[-5:] == '.pony'): if (len(pony) > 5) and (pony[-5:] == '.pony'):
ponies.append(pony[:-5]) ponies.append(pony[:-5])
pseudolinkmap = [] pseudolinkmap = {}
self.__ucsise(ponies, pseudolinkmap) ##TODO self.__ucsise(ponies, pseudolinkmap) ##TODO
ponies.sort() pairs = [(pony, os.path.realpath(ponydir + pony + '.pony') if os.path.islink(ponydir + pony + '.pony') else None) for pony in ponies]
pairs = [(pony, os.path.realpath(ponydir + pony + '.pony') if os.path.islink(ponydir + pony + '.pony') else '') for pony in ponies]
ponymap = {} ponymap = {}
for pair in pairs: for pair in pairs:
if pair[1] == '': if (pair[1] is None) or (pair[1] == ''):
if pair[0] not in ponymap: if pair[0] not in ponymap:
ponymap[pair[0]] = [] ponymap[pair[0]] = []
else: else:
@ -320,8 +321,7 @@ class Ponysay():
ponymap[target] = [pair[0]] ponymap[target] = [pair[0]]
width = 0 width = 0
ponies = [] ponies = {}
widths = []
for pony in ponymap: for pony in ponymap:
w = UCS.dispLen(pony) w = UCS.dispLen(pony)
item = '\033[1m' + pony + '\033[21m' if (pony in quoters) else pony item = '\033[1m' + pony + '\033[21m' if (pony in quoters) else pony
@ -338,24 +338,25 @@ class Ponysay():
first = False first = False
item += '\033[1m' + sym + '\033[21m' if (sym in quoters) else sym item += '\033[1m' + sym + '\033[21m' if (sym in quoters) else sym
item += ')' item += ')'
ponies.append(item) ponies[item] = w
widths.append(w)
if width < w: if width < w:
width = w width = w
width += 2; width += 2;
x = 0 x = 0
index = 0 index = 0
for pony in ponies: ponylist = list(ponies)
spacing = ' ' * (width - widths[index]) ponylist.sort(key = lambda pony : pony.split(' ')[0].replace('\033[1m', '').replace('\033[21m', ''))
for pony in ponylist:
spacing = ' ' * (width - ponies[pony])
index += 1 index += 1
print(pony + spacing, end='') # Print pony file name print(pony + spacing, end='') # Print pony file name
x += width x += width
if x > (termsize[1] - width): # If too wide, make new line if x > termsize[1] - width: # If too wide, make new line
print() print()
x = 0 x = 0
print('\n'); print('' if x == 0 else '\n');
''' '''