Fixed a few edit/delete edge cases, consolidated error handling.

This commit is contained in:
Michael Lazar
2015-04-11 21:52:21 -07:00
parent 3e6b7c98d5
commit 4461782c67
4 changed files with 130 additions and 103 deletions

View File

@@ -10,7 +10,8 @@ from .helpers import strip_textpad
from .exceptions import EscapeInterrupt
__all__ = ['ESCAPE', 'UARROW', 'DARROW', 'BULLET', 'show_notification',
'show_help', 'LoadScreen', 'Color', 'text_input', 'curses_session']
'show_help', 'LoadScreen', 'Color', 'text_input', 'curses_session',
'prompt_input']
ESCAPE = 27
@@ -235,6 +236,31 @@ def text_input(window, allow_resize=True):
return strip_textpad(out)
def prompt_input(window, prompt, hide=False):
"""
Display a prompt where the user can enter text at the bottom of the screen
Set hide to True to make the input text invisible.
"""
attr = curses.A_BOLD | Color.CYAN
n_rows, n_cols = window.getmaxyx()
if hide:
prompt += ' ' * (n_cols - len(prompt) - 1)
window.addstr(n_rows-1, 0, prompt, attr)
out = window.getstr(n_rows-1, 1)
else:
window.addstr(n_rows - 1, 0, prompt, attr)
window.refresh()
subwin = window.derwin(1, n_cols - len(prompt),
n_rows - 1, len(prompt))
subwin.attrset(attr)
out = text_input(subwin)
return out
@contextmanager
def curses_session():
"""