diff options
author | Mattias Andrée <maandree@operamail.com> | 2012-08-22 03:23:11 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2012-08-22 03:23:11 +0200 |
commit | 860919ddd4f367c9be70b6e746b02695dfa3767a (patch) | |
tree | d7572fd5698707766caeb12059e944147e2ed90a | |
parent | a9c0dedfbc908be9bef30101737f9e0a1a5112d1 (diff) | |
download | ponysay-860919ddd4f367c9be70b6e746b02695dfa3767a.tar.gz ponysay-860919ddd4f367c9be70b6e746b02695dfa3767a.tar.bz2 ponysay-860919ddd4f367c9be70b6e746b02695dfa3767a.zip |
sorting -L
-rwxr-xr-x | ponysay | 27 |
1 files changed, 14 insertions, 13 deletions
@@ -154,6 +154,8 @@ class Ponysay(): for pony in ponies: if pony in map: ponies.append(map[pony]) + if links is not None: + links[map[pony]] = pony + '.pony' else: for j in range(0, len(ponies)): if ponies[j] in map: @@ -282,7 +284,7 @@ class Ponysay(): print() x = 0 - print('\n'); + print('' if x == 0 else '\n'); ''' @@ -300,14 +302,13 @@ class Ponysay(): for pony in _ponies: if (len(pony) > 5) and (pony[-5:] == '.pony'): ponies.append(pony[:-5]) - pseudolinkmap = [] + pseudolinkmap = {} self.__ucsise(ponies, pseudolinkmap) ##TODO - ponies.sort() - pairs = [(pony, os.path.realpath(ponydir + pony + '.pony') if os.path.islink(ponydir + pony + '.pony') else '') for pony in ponies] + pairs = [(pony, os.path.realpath(ponydir + pony + '.pony') if os.path.islink(ponydir + pony + '.pony') else None) for pony in ponies] ponymap = {} for pair in pairs: - if pair[1] == '': + if (pair[1] is None) or (pair[1] == ''): if pair[0] not in ponymap: ponymap[pair[0]] = [] else: @@ -320,8 +321,7 @@ class Ponysay(): ponymap[target] = [pair[0]] width = 0 - ponies = [] - widths = [] + ponies = {} for pony in ponymap: w = UCS.dispLen(pony) item = '\033[1m' + pony + '\033[21m' if (pony in quoters) else pony @@ -338,24 +338,25 @@ class Ponysay(): first = False item += '\033[1m' + sym + '\033[21m' if (sym in quoters) else sym item += ')' - ponies.append(item) - widths.append(w) + ponies[item] = w if width < w: width = w width += 2; x = 0 index = 0 - for pony in ponies: - spacing = ' ' * (width - widths[index]) + ponylist = list(ponies) + ponylist.sort(key = lambda pony : pony.split(' ')[0].replace('\033[1m', '').replace('\033[21m', '')) + for pony in ponylist: + spacing = ' ' * (width - ponies[pony]) index += 1 print(pony + spacing, end='') # Print pony file name 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() x = 0 - print('\n'); + print('' if x == 0 else '\n'); ''' |