Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combining browser #5

Merged
merged 2 commits into from
Nov 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions bin/wcwidth-browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,17 +389,16 @@ def text_entry(self, ucs, name):
return fmt.format(name_len=style.name_len,
delimiter=delimiter,
name=name, ucs=ucs,
value=ord(ucs))
value=ord(ucs if len(ucs) == 1 else ucs[1]))


def main():
def main(character_factory):
term = Terminal()
style = Style(heading=term.magenta,
hint=term.bright_cyan,
delimiter=u'|',
) if term.number_of_colors else Style()
screen = Screen(term, style)
character_factory = WcWideCharacterGenerator
pager = Pager(term, screen, character_factory)
if term.is_a_tty:
signal.signal(signal.SIGWINCH, pager.on_resize)
Expand All @@ -410,4 +409,4 @@ def main():
pager.run(writer=echo, reader=term.inkey)

if __name__ == '__main__':
main()
main(WcWideCharacterGenerator)
32 changes: 32 additions & 0 deletions bin/wcwidth-combining-browser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
browser = __import__('wcwidth-browser')
import string
import unicodedata
from wcwidth import wcwidth, table_comb


class WcCombinedCharacterGenerator(object):
def __init__(self, width=1):
self.characters = []
for boundaries in table_comb.NONZERO_COMBINING:
for i in range(boundaries[0], boundaries[1]+1):
self.characters.append(u'o' + browser.unichr(i))
self.characters.reverse()

def __next__(self):
while True:
if not self.characters:
raise StopIteration
ucs = self.characters.pop()
try:
name = string.capwords(unicodedata.name(ucs[1]))
except ValueError:
continue
return (ucs, name)

# python 2.6 - 3.3 compatibility
next = __next__


if __name__ == '__main__':
browser.main(WcCombinedCharacterGenerator)

3 changes: 3 additions & 0 deletions wcwidth/wcwidth.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ def wcswidth(pwcs, n=None):
for char in pwcs[idx]:
wcw = wcwidth(char)
if wcw < 0:
ucs = ord(char)
if _bisearch(ucs, NONZERO_COMBINING):
continue
return -1
else:
width += wcw
Expand Down