Skip to content

Commit

Permalink
2 small changes,
Browse files Browse the repository at this point in the history
- hide cursor during detection
- on error, be sure to display error to stderr, not stdout
  • Loading branch information
jquast committed Jun 5, 2020
1 parent 91ad9cd commit 3ac00c7
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions ucs_detect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@


def main():
"""Program entry point."""
term = blessed.Terminal(stream=sys.__stderr__)
assert term.is_a_tty
previous_version = '4.1.0'
wide_by_version = [
('5.0.0', '龼'),
('5.1.0', '🈯'),
Expand All @@ -30,22 +30,24 @@ def main():
('12.1.0', 'ㆻ'),
]
echo = functools.partial(print, end='', flush=True, file=sys.stderr)
echo(term.black)
for version, wchar in wide_by_version:
_, start_x = term.get_location(timeout=5.0)
echo(wchar)
_, end_x = term.get_location(timeout=5.0)
echo(term.move_x(0) + term.clear_eol)
if -1 in (start_x, end_x):
echo(term.normal)
print('ucs-detect: Unicode Version could not be determined!')
return 1
if end_x - start_x != 2:
break
previous_version = version
echo(term.normal)
print('UNICODE_VERSION={0}; export UNICODE_VERSION'
.format(previous_version))
with term.hidden_cursor():
echo(term.black)
previous_version = '4.1.0'
for version, wchar in wide_by_version:
_, start_x = term.get_location(timeout=3.0)
echo(wchar)
_, end_x = term.get_location(timeout=3.0)
echo(term.move_x(0) + term.clear_eol)
if -1 in (start_x, end_x):
echo(term.normal)
echo('ucs-detect: Unicode Version could not be determined!\n')
return 1
if end_x - start_x != 2:
break
previous_version = version
echo(term.normal)
print('UNICODE_VERSION={0}; export UNICODE_VERSION'
.format(previous_version))
return 0


Expand Down

0 comments on commit 3ac00c7

Please sign in to comment.