mirror of
https://github.com/beetbox/beets.git
synced 2026-01-05 23:43:31 +01:00
readline on Unix (closes GH-28)
Silently skip loading readline when it's not available (e.g., on Windows). Readline behaves strangely when a "print prompt," is followed by "raw_input()", we're moving back to "raw_input(prompt)". This has caused problems with ANSI colors in the past, so these might recur now.
This commit is contained in:
parent
7b7658fc43
commit
429ebf61ce
1 changed files with 26 additions and 7 deletions
|
|
@ -32,9 +32,24 @@ from beets import library
|
|||
from beets import plugins
|
||||
from beets import util
|
||||
|
||||
|
||||
# On Windows platforms, use colorama to support "ANSI" terminal colors.
|
||||
if sys.platform == 'win32':
|
||||
import colorama
|
||||
colorama.init()
|
||||
try:
|
||||
import colorama
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
colorama.init()
|
||||
|
||||
# On Unix-like platforms, use readline to make prompts more usable.
|
||||
try:
|
||||
import readline
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
readline # Silence pyflakes "unused import" warning.
|
||||
|
||||
|
||||
# Constants.
|
||||
CONFIG_PATH_VAR = 'BEETSCONFIG'
|
||||
|
|
@ -227,9 +242,14 @@ def input_options(options, require=False, prompt=None, fallback_prompt=None,
|
|||
fallback_prompt += '%i-%i, ' % numrange
|
||||
fallback_prompt += ', '.join(display_letters) + ':'
|
||||
|
||||
# (raw_input(prompt) was causing problems with colors.)
|
||||
print prompt,
|
||||
resp = raw_input()
|
||||
# Note: In the past, this line was causing problems with colors in
|
||||
# the prompt string. However, using a separate "print prompt," line
|
||||
# breaks the readline module, which expects the length of the prompt
|
||||
# to be available to it. (Namely, entering text and then deleting it
|
||||
# caused the entire last line of the prompt to disappear.) However,
|
||||
# readline also seems to have fixed the issue with colors, so we've
|
||||
# now switched back.
|
||||
resp = raw_input(prompt + ' ')
|
||||
while True:
|
||||
resp = resp.strip().lower()
|
||||
|
||||
|
|
@ -257,8 +277,7 @@ def input_options(options, require=False, prompt=None, fallback_prompt=None,
|
|||
return resp
|
||||
|
||||
# Prompt for new input.
|
||||
print fallback_prompt,
|
||||
resp = raw_input()
|
||||
resp = raw_input(fallback_prompt + ' ')
|
||||
|
||||
def input_yn(prompt, require=False, color=False):
|
||||
"""Prompts the user for a "yes" or "no" response. The default is
|
||||
|
|
|
|||
Loading…
Reference in a new issue