Skip to content

Commit b8c9acf

Browse files
committed
Improve user_input's input/raw_input compatibility.
This PR add the changes from #723 with the necessary rebase. Quoting the PR comment: I didn't like having to add a prompt message when using python's input and running it with PymodeRun * Allow default prompt ('' empty string) * Fix quoting (input('"') would crash because it wasn't escaped) * Strip whitespace to avoid duplicate spaces Caveats: strips all leading and trailing whitespace from prefix and msg still doesn't write the prompt to stdout like input/raw_input does (to fix that one would need a separate function for replacing input/raw_input) Close 723
1 parent 1ce5ce3 commit b8c9acf

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

pymode/environment.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,31 @@ def message(msg, history=False):
8484

8585
return vim.command('call pymode#wide_message("%s")' % str(msg))
8686

87-
def user_input(self, msg, default=''):
87+
def user_input(self, msg='', default=''):
8888
"""Return user input or default.
8989
9090
:return str:
9191
9292
"""
93-
msg = '%s %s ' % (self.prefix, msg)
93+
prompt = []
94+
prompt.append(str(self.prefix.strip()))
95+
prompt.append(str(msg).strip())
9496

9597
if default != '':
96-
msg += '[%s] ' % default
98+
prompt.append('[%s]' % default)
99+
100+
prompt.append('> ')
101+
prompt = ' '.join([s for s in prompt if s])
102+
103+
vim.command('echohl Debug')
97104

98105
try:
99-
vim.command('echohl Debug')
100-
input_str = vim.eval('input("%s> ")' % msg)
101-
vim.command('echohl none')
106+
input_str = vim.eval('input(%r)' % (prompt,))
102107
except KeyboardInterrupt:
103108
input_str = ''
104109

110+
vim.command('echohl none')
111+
105112
return input_str or default
106113

107114
def user_confirm(self, msg, yes=False):

0 commit comments

Comments
 (0)