diff options
author | Mike Crute <mike@crute.us> | 2017-09-30 18:44:45 +0000 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2017-09-30 23:09:18 +0000 |
commit | fdfb18a78e0014d362a2e0654eabf706094e4f09 (patch) | |
tree | 40069ec26e0095a1238777119cea2e4c00359cc4 | |
parent | c09e16c4f375a9d9b29b7c34e9d62f9cab1e8c69 (diff) | |
download | pydora-fdfb18a78e0014d362a2e0654eabf706094e4f09.tar.bz2 pydora-fdfb18a78e0014d362a2e0654eabf706094e4f09.tar.xz pydora-fdfb18a78e0014d362a2e0654eabf706094e4f09.zip |
Check if termios is present or ignore
termios is POSIX specific which doesn't work for Windows users using the
CLI. Check for the presence of termios and disable the set_echo function
if it's not present.
The only reason echo is disabled during polling is to prevent control
characters entered by a user from displaying in the playlist so
it's more cosmetic than anything.
-rw-r--r-- | pydora/utils.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/pydora/utils.py b/pydora/utils.py index 47422d6..3c48117 100644 --- a/pydora/utils.py +++ b/pydora/utils.py | |||
@@ -2,10 +2,15 @@ from __future__ import print_function | |||
2 | 2 | ||
3 | import os | 3 | import os |
4 | import sys | 4 | import sys |
5 | import termios | ||
6 | import getpass | 5 | import getpass |
7 | import subprocess | 6 | import subprocess |
8 | 7 | ||
8 | try: | ||
9 | import termios | ||
10 | except ImportError: | ||
11 | # Windows does not have a termios module | ||
12 | termios = None | ||
13 | |||
9 | 14 | ||
10 | def input(prompt): | 15 | def input(prompt): |
11 | try: | 16 | try: |
@@ -39,6 +44,9 @@ class Screen(object): | |||
39 | 44 | ||
40 | @staticmethod | 45 | @staticmethod |
41 | def set_echo(enabled): | 46 | def set_echo(enabled): |
47 | if not termios: | ||
48 | return | ||
49 | |||
42 | handle = sys.stdin.fileno() | 50 | handle = sys.stdin.fileno() |
43 | if not os.isatty(handle): | 51 | if not os.isatty(handle): |
44 | return | 52 | return |