Fixed prompt sometimes not clearing.
This commit is contained in:
@@ -412,11 +412,18 @@ class Terminal(object):
|
||||
n_rows, n_cols = self.stdscr.getmaxyx()
|
||||
attr = curses.A_BOLD | Color.CYAN
|
||||
prompt = self.clean(prompt, n_cols-1)
|
||||
window = self.stdscr.derwin(
|
||||
1, n_cols - len(prompt), n_rows - 1, len(prompt))
|
||||
window.attrset(attr)
|
||||
self.add_line(self.stdscr, prompt, n_rows-1, 0, attr)
|
||||
self.stdscr.refresh()
|
||||
|
||||
# Create a new window to draw the text at the bottom of the screen,
|
||||
# so we can erase it when we're done.
|
||||
prompt_win = curses.newwin(1, len(prompt)+1, n_rows-1, 0)
|
||||
self.add_line(prompt_win, prompt, attr=attr)
|
||||
prompt_win.refresh()
|
||||
|
||||
# Create a separate window for text input
|
||||
input_win = curses.newwin(1, n_cols-len(prompt), n_rows-1, len(prompt))
|
||||
input_win.attrset(attr)
|
||||
input_win.refresh()
|
||||
|
||||
if key:
|
||||
curses.curs_set(1)
|
||||
ch = self.getch()
|
||||
@@ -426,7 +433,15 @@ class Terminal(object):
|
||||
text = ch if ch != self.ESCAPE else None
|
||||
curses.curs_set(0)
|
||||
else:
|
||||
text = self.text_input(window)
|
||||
text = self.text_input(input_win)
|
||||
|
||||
prompt_win.clear()
|
||||
input_win.clear()
|
||||
del prompt_win
|
||||
del input_win
|
||||
self.stdscr.touchwin()
|
||||
self.stdscr.refresh()
|
||||
|
||||
return text
|
||||
|
||||
def prompt_y_or_n(self, prompt):
|
||||
|
||||
@@ -218,7 +218,7 @@ def test_prompt_input(terminal, stdscr, ascii):
|
||||
assert isinstance(terminal.prompt_input('hi'), six.text_type)
|
||||
|
||||
attr = Color.CYAN | curses.A_BOLD
|
||||
stdscr.addstr.assert_called_with(39, 0, 'hi'.encode('ascii'), attr)
|
||||
stdscr.subwin.addstr.assert_called_with(0, 0, 'hi'.encode('ascii'), attr)
|
||||
assert window.nlines == 1
|
||||
assert window.ncols == 78
|
||||
|
||||
@@ -236,25 +236,26 @@ def test_prompt_y_or_n(terminal, stdscr):
|
||||
|
||||
stdscr.getch.side_effect = [ord('y'), ord('N'), terminal.ESCAPE, ord('a')]
|
||||
attr = Color.CYAN | curses.A_BOLD
|
||||
text = 'hi'.encode('ascii')
|
||||
|
||||
# Press 'y'
|
||||
assert terminal.prompt_y_or_n('hi')
|
||||
stdscr.addstr.assert_called_with(39, 0, 'hi'.encode('ascii'), attr)
|
||||
stdscr.subwin.addstr.assert_called_with(0, 0, text, attr)
|
||||
assert not curses.flash.called
|
||||
|
||||
# Press 'N'
|
||||
assert not terminal.prompt_y_or_n('hi')
|
||||
stdscr.addstr.assert_called_with(39, 0, 'hi'.encode('ascii'), attr)
|
||||
stdscr.subwin.addstr.assert_called_with(0, 0, text, attr)
|
||||
assert not curses.flash.called
|
||||
|
||||
# Press Esc
|
||||
assert not terminal.prompt_y_or_n('hi')
|
||||
stdscr.addstr.assert_called_with(39, 0, 'hi'.encode('ascii'), attr)
|
||||
stdscr.subwin.addstr.assert_called_with(0, 0, text, attr)
|
||||
assert not curses.flash.called
|
||||
|
||||
# Press an invalid key
|
||||
assert not terminal.prompt_y_or_n('hi')
|
||||
stdscr.addstr.assert_called_with(39, 0, 'hi'.encode('ascii'), attr)
|
||||
stdscr.subwin.addstr.assert_called_with(0, 0, text, attr)
|
||||
assert curses.flash.called
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user